Add history to CourseEntitlement

DE-1510
This commit is contained in:
Troy Sankey
2019-05-30 16:42:31 -04:00
committed by bmedx
parent f1f7e7e2ec
commit df8f581d36
2 changed files with 54 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.20 on 2019-05-30 21:13
from __future__ import unicode_literals
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
import model_utils.fields
import simple_history.models
import uuid
class Migration(migrations.Migration):
dependencies = [
('student', '0021_historicalcourseenrollment'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('entitlements', '0010_backfill_refund_lock'),
]
operations = [
migrations.CreateModel(
name='HistoricalCourseEntitlement',
fields=[
('id', models.IntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')),
('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)),
('course_uuid', models.UUIDField(help_text=b'UUID for the Course, not the Course Run')),
('expired_at', models.DateTimeField(blank=True, help_text=b'The date that an entitlement expired, if NULL the entitlement has not expired.', null=True)),
('mode', models.CharField(help_text=b'The mode of the Course that will be applied on enroll.', max_length=100)),
('order_number', models.CharField(max_length=128, null=True)),
('refund_locked', models.BooleanField(default=False)),
('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)),
('_policy', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='entitlements.CourseEntitlementPolicy')),
('enrollment_course_run', models.ForeignKey(blank=True, db_constraint=False, help_text=b'The current Course enrollment for this entitlement. If NULL the Learner has not enrolled.', null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='student.CourseEnrollment')),
('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
('user', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to=settings.AUTH_USER_MODEL)),
],
options={
'ordering': ('-history_date', '-history_id'),
'get_latest_by': 'history_date',
'verbose_name': 'historical course entitlement',
},
bases=(simple_history.models.HistoricalChanges, models.Model),
),
]

View File

@@ -12,6 +12,7 @@ from django.db import IntegrityError, models, transaction
from django.utils.timezone import now
from model_utils import Choices
from model_utils.models import TimeStampedModel
from simple_history.models import HistoricalRecords
from course_modes.models import CourseMode
from entitlements.utils import is_course_run_entitlement_fulfillable
@@ -173,6 +174,8 @@ class CourseEntitlement(TimeStampedModel):
refund_locked = models.BooleanField(default=False)
_policy = models.ForeignKey(CourseEntitlementPolicy, null=True, blank=True, on_delete=models.CASCADE)
history = HistoricalRecords()
@property
def expired_at_datetime(self):
"""