forked from dj-stripe/dj-stripe
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added discount model (dj-stripe#1751)
* Added internal model InvoiceOrLineItem InvoiceOrLineItem model is similar to the DjstripePaymentMethod model and acts as a wrapper around the InvoiceItem and LineItem models. This was done because Discount.invoice_item model field can receive either of InvoiceItem or LineItem objects. * Added InvoiceOrLineItemForeignKey custom model field InvoiceOrLineItemForeignKey is like the PaymentMethodForeignKey to be able to deal with both InvoiceItem and LineItem models whichever is returned as the Discounts invoice_item field's value. * Added Discount Model * Exposed Discount model on the Admin * Updated _handle_crud_like_event to allow syncing of discount.* events This was done because Stripe doesn't allow direct retrieval of Discount objects. * Fixed Discount Event Fixtures * Fixed corner case in Event.customer prop It could be possible that the json key may have been expanded using expand_fields attribute and hence also handled that case. * Updated Changelog * Fix Formatting Errors
- Loading branch information
1 parent
36d1323
commit 44356fa
Showing
14 changed files
with
509 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Generated by Django 3.2.13 on 2022-07-09 08:04 | ||
|
||
import django.db.models.deletion | ||
from django.conf import settings | ||
from django.db import migrations, models | ||
|
||
import djstripe.enums | ||
import djstripe.fields | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("djstripe", "0016_alter_payout_destination"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="InvoiceOrLineItem", | ||
fields=[ | ||
( | ||
"id", | ||
models.CharField(max_length=255, primary_key=True, serialize=False), | ||
), | ||
( | ||
"type", | ||
djstripe.fields.StripeEnumField( | ||
enum=djstripe.enums.InvoiceorLineItemType, max_length=12 | ||
), | ||
), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
# Generated by Django 3.2.16 on 2023-01-28 06:04 | ||
|
||
import django.db.models.deletion | ||
from django.conf import settings | ||
from django.db import migrations, models | ||
|
||
import djstripe.fields | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("djstripe", "0017_invoiceorlineitem"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="Discount", | ||
fields=[ | ||
("djstripe_created", models.DateTimeField(auto_now_add=True)), | ||
("djstripe_updated", models.DateTimeField(auto_now=True)), | ||
( | ||
"djstripe_id", | ||
models.BigAutoField( | ||
primary_key=True, serialize=False, verbose_name="ID" | ||
), | ||
), | ||
("id", djstripe.fields.StripeIdField(max_length=255, unique=True)), | ||
( | ||
"livemode", | ||
models.BooleanField( | ||
blank=True, | ||
default=None, | ||
help_text="Null here indicates that the livemode status is unknown or was previously unrecorded. Otherwise, this field indicates whether this record comes from Stripe test mode or live mode operation.", | ||
null=True, | ||
), | ||
), | ||
("created", djstripe.fields.StripeDateTimeField(blank=True, null=True)), | ||
("metadata", djstripe.fields.JSONField(blank=True, null=True)), | ||
( | ||
"description", | ||
models.TextField( | ||
blank=True, help_text="A description of this object.", null=True | ||
), | ||
), | ||
("coupon", djstripe.fields.JSONField(blank=True, null=True)), | ||
("end", djstripe.fields.StripeDateTimeField(blank=True, null=True)), | ||
( | ||
"promotion_code", | ||
models.CharField( | ||
blank=True, | ||
help_text="The promotion code applied to create this discount.", | ||
max_length=255, | ||
), | ||
), | ||
("start", djstripe.fields.StripeDateTimeField(blank=True, null=True)), | ||
( | ||
"checkout_session", | ||
djstripe.fields.StripeForeignKey( | ||
blank=True, | ||
help_text="The Checkout session that this coupon is applied to, if it is applied to a particular session in payment mode. Will not be present for subscription mode.", | ||
null=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
to="djstripe.session", | ||
to_field=settings.DJSTRIPE_FOREIGN_KEY_TO_FIELD, | ||
), | ||
), | ||
( | ||
"customer", | ||
djstripe.fields.StripeForeignKey( | ||
blank=True, | ||
help_text="The ID of the customer associated with this discount.", | ||
null=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="customer_discounts", | ||
to="djstripe.customer", | ||
to_field=settings.DJSTRIPE_FOREIGN_KEY_TO_FIELD, | ||
), | ||
), | ||
( | ||
"djstripe_owner_account", | ||
djstripe.fields.StripeForeignKey( | ||
blank=True, | ||
help_text="The Stripe Account this object belongs to.", | ||
null=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
to="djstripe.account", | ||
to_field=settings.DJSTRIPE_FOREIGN_KEY_TO_FIELD, | ||
), | ||
), | ||
( | ||
"invoice", | ||
djstripe.fields.StripeForeignKey( | ||
blank=True, | ||
help_text="The invoice that the discount’s coupon was applied to, if it was applied directly to a particular invoice.", | ||
null=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="invoice_discounts", | ||
to="djstripe.invoice", | ||
to_field=settings.DJSTRIPE_FOREIGN_KEY_TO_FIELD, | ||
), | ||
), | ||
( | ||
"invoice_item", | ||
djstripe.fields.InvoiceOrLineItemForeignKey( | ||
blank=True, | ||
help_text="The invoice item id (or invoice line item id for invoice line items of type=‘subscription’) that the discount’s coupon was applied to, if it was applied directly to a particular invoice item or invoice line item.", | ||
null=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
to="djstripe.invoiceorlineitem", | ||
), | ||
), | ||
( | ||
"subscription", | ||
djstripe.fields.StripeForeignKey( | ||
blank=True, | ||
help_text="The subscription that this coupon is applied to, if it is applied to a particular subscription.", | ||
null=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="subscription_discounts", | ||
to="djstripe.subscription", | ||
to_field=settings.DJSTRIPE_FOREIGN_KEY_TO_FIELD, | ||
), | ||
), | ||
], | ||
options={ | ||
"get_latest_by": "created", | ||
"abstract": False, | ||
}, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.