-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add Adjustment model and admin
- Loading branch information
1 parent
0f2e264
commit d550eb2
Showing
4 changed files
with
255 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# Generated by Django 3.2.19 on 2023-10-11 20:02 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import django.utils.timezone | ||
import jsonfield.fields | ||
import model_utils.fields | ||
import simple_history.models | ||
import uuid | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
('openedx_ledger', '0007_alter_externalfulfillmentprovider_name'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='HistoricalAdjustment', | ||
fields=[ | ||
('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')), | ||
('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')), | ||
('uuid', models.UUIDField(db_index=True, default=uuid.uuid4, editable=False)), | ||
('idempotency_key', models.CharField(db_index=True, help_text="An idempotency key is a unique value generated by the client of the Ledger API which the Ledger and Transaction APIs use to recognize subsequent retries of the same redemption (i.e. a Transaction that leads to the fulfillment of an enrollment or entitlement for a particular user id in a particular content key).We suggest incorporating V4 UUIDs along with sufficiently unique or random values representing the desired redemption to avoid unintended collisions.In particular, a Transaction's idempotency_key should incorporate it's corresponding ledger's idempotency_key.Utility methods are provided in the ``utils.py`` module to help clients generate appropriate idempotency keys.", max_length=255)), | ||
('quantity', models.BigIntegerField(help_text='How many units (as defined in the associated Ledger instance) this Transaction represents.')), | ||
('metadata', jsonfield.fields.JSONField(blank=True, help_text='Any additionaly metadata that a client may want to associate with this Transaction.', null=True)), | ||
('state', models.CharField(choices=[('created', 'Created'), ('pending', 'Pending'), ('committed', 'Committed'), ('failed', 'Failed')], db_index=True, default='created', help_text="The current state of the Transaction. One of: ['Created', 'Pending', 'Committed', 'Failed']", max_length=255)), | ||
('reason', models.CharField(choices=[('unauthorized_enrollment', 'Unauthorized enrollment'), ('poor_content_fit', 'Poor content fit'), ('technical_challenges', 'Technical challenges'), ('missed_refund_or_date', 'Missed refund or date'), ('good_faith', 'Good faith/Relationship building')], db_index=True, default='technical_challenges', help_text='The primary reason for the existence of this adjustment.', max_length=255)), | ||
('notes', models.TextField(blank=True, help_text='Any additional context you have for the existence of this adjustment.', null=True)), | ||
('history_id', models.AutoField(primary_key=True, serialize=False)), | ||
('history_date', models.DateTimeField()), | ||
('history_change_reason', models.CharField(max_length=100, null=True)), | ||
('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)), | ||
('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)), | ||
('ledger', models.ForeignKey(blank=True, db_constraint=False, help_text='The Ledger instance with which this Adjustment is associated.', null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='openedx_ledger.ledger')), | ||
('transaction', models.ForeignKey(blank=True, db_constraint=False, help_text='The Transaction instance which adjusts the balance of the relevant ledger.', null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='openedx_ledger.transaction')), | ||
('transaction_of_interest', models.ForeignKey(blank=True, db_constraint=False, help_text='Any transaction of interest w.r.t. the reason for being of this adjustment. For example, the transaction of interest may point to some transaction record for which the enrolling user is unsatisfied, but for which we cannot issue a reversal due to business rules.', null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='openedx_ledger.transaction')), | ||
], | ||
options={ | ||
'verbose_name': 'historical adjustment', | ||
'ordering': ('-history_date', '-history_id'), | ||
'get_latest_by': 'history_date', | ||
}, | ||
bases=(simple_history.models.HistoricalChanges, models.Model), | ||
), | ||
migrations.CreateModel( | ||
name='Adjustment', | ||
fields=[ | ||
('created', model_utils.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False, verbose_name='created')), | ||
('modified', model_utils.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False, verbose_name='modified')), | ||
('uuid', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True)), | ||
('idempotency_key', models.CharField(db_index=True, help_text="An idempotency key is a unique value generated by the client of the Ledger API which the Ledger and Transaction APIs use to recognize subsequent retries of the same redemption (i.e. a Transaction that leads to the fulfillment of an enrollment or entitlement for a particular user id in a particular content key).We suggest incorporating V4 UUIDs along with sufficiently unique or random values representing the desired redemption to avoid unintended collisions.In particular, a Transaction's idempotency_key should incorporate it's corresponding ledger's idempotency_key.Utility methods are provided in the ``utils.py`` module to help clients generate appropriate idempotency keys.", max_length=255)), | ||
('quantity', models.BigIntegerField(help_text='How many units (as defined in the associated Ledger instance) this Transaction represents.')), | ||
('metadata', jsonfield.fields.JSONField(blank=True, help_text='Any additionaly metadata that a client may want to associate with this Transaction.', null=True)), | ||
('state', models.CharField(choices=[('created', 'Created'), ('pending', 'Pending'), ('committed', 'Committed'), ('failed', 'Failed')], db_index=True, default='created', help_text="The current state of the Transaction. One of: ['Created', 'Pending', 'Committed', 'Failed']", max_length=255)), | ||
('reason', models.CharField(choices=[('unauthorized_enrollment', 'Unauthorized enrollment'), ('poor_content_fit', 'Poor content fit'), ('technical_challenges', 'Technical challenges'), ('missed_refund_or_date', 'Missed refund or date'), ('good_faith', 'Good faith/Relationship building')], db_index=True, default='technical_challenges', help_text='The primary reason for the existence of this adjustment.', max_length=255)), | ||
('notes', models.TextField(blank=True, help_text='Any additional context you have for the existence of this adjustment.', null=True)), | ||
('ledger', models.ForeignKey(help_text='The Ledger instance with which this Adjustment is associated.', on_delete=django.db.models.deletion.CASCADE, related_name='adjustments', to='openedx_ledger.ledger')), | ||
('transaction', models.OneToOneField(help_text='The Transaction instance which adjusts the balance of the relevant ledger.', on_delete=django.db.models.deletion.CASCADE, related_name='adjustment', to='openedx_ledger.transaction')), | ||
('transaction_of_interest', models.OneToOneField(help_text='Any transaction of interest w.r.t. the reason for being of this adjustment. For example, the transaction of interest may point to some transaction record for which the enrolling user is unsatisfied, but for which we cannot issue a reversal due to business rules.', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='adjustment_of_interest', to='openedx_ledger.transaction')), | ||
], | ||
options={ | ||
'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