Skip to content

Commit

Permalink
Merge pull request #335 from Paul424/fix-334-plan-not-set-correct-plu…
Browse files Browse the repository at this point in the history
…s-store-tax-and-receipt-number

Fix issue where Plan not set correctly on InvoiceItem + store the cal…
  • Loading branch information
paltman committed May 10, 2017
2 parents 5535156 + 13c2292 commit afe0eb6
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pinax/stripe/actions/invoices.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import decimal
import stripe

from . import charges
Expand Down Expand Up @@ -101,11 +102,14 @@ def sync_invoice_from_stripe_data(stripe_invoice, send_receipt=settings.PINAX_ST
period_end=period_end,
period_start=period_start,
subtotal=utils.convert_amount_for_db(stripe_invoice["subtotal"], stripe_invoice["currency"]),
tax=utils.convert_amount_for_db(stripe_invoice["tax"], stripe_invoice["currency"]) if stripe_invoice["tax"] is not None else None,
tax_percent=decimal.Decimal(stripe_invoice["tax_percent"]) if stripe_invoice["tax_percent"] is not None else None,
total=utils.convert_amount_for_db(stripe_invoice["total"], stripe_invoice["currency"]),
currency=stripe_invoice["currency"],
date=date,
charge=charge,
subscription=subscription
subscription=subscription,
receipt_number=stripe_invoice["receipt_number"] or "",
)
invoice, created = models.Invoice.objects.get_or_create(
stripe_id=stripe_invoice["id"],
Expand Down Expand Up @@ -168,7 +172,8 @@ def sync_invoice_items(invoice, items):
invoice.customer,
stripe_subscription
) if stripe_subscription else None
plan = item_subscription.plan if item_subscription is not None and plan is None else None
if plan is None and item_subscription is not None and item_subscription.plan is not None:
plan = item_subscription.plan
else:
item_subscription = None

Expand Down
25 changes: 25 additions & 0 deletions pinax/stripe/migrations/0008_auto_20170509_1736.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10 on 2017-05-09 17:36
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('pinax_stripe', '0007_auto_20170108_1202'),
]

operations = [
migrations.AddField(
model_name='invoice',
name='tax',
field=models.DecimalField(decimal_places=2, max_digits=9, null=True),
),
migrations.AddField(
model_name='invoice',
name='tax_percent',
field=models.DecimalField(decimal_places=2, max_digits=9, null=True),
),
]
2 changes: 2 additions & 0 deletions pinax/stripe/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ class Invoice(StripeObject):
period_end = models.DateTimeField()
period_start = models.DateTimeField()
subtotal = models.DecimalField(decimal_places=2, max_digits=9)
tax = models.DecimalField(decimal_places=2, max_digits=9, null=True)
tax_percent = models.DecimalField(decimal_places=2, max_digits=9, null=True)
total = models.DecimalField(decimal_places=2, max_digits=9)
date = models.DateTimeField()
webhooks_delivered_at = models.DateTimeField(null=True)
Expand Down

0 comments on commit afe0eb6

Please sign in to comment.