From fedade8bfc05dc02e338c773901a9e753c0e7707 Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 10 Apr 2017 01:18:07 +0300 Subject: [PATCH] license: hardcoded consts in migrations because they might get changed --- .../0007_license_set_order_status.py | 22 ++++++++++-- .../0009_license_fix_order_status.py | 35 +++++++++++++------ 2 files changed, 45 insertions(+), 12 deletions(-) diff --git a/project/customer/migrations/0007_license_set_order_status.py b/project/customer/migrations/0007_license_set_order_status.py index 2bce074..423bf41 100644 --- a/project/customer/migrations/0007_license_set_order_status.py +++ b/project/customer/migrations/0007_license_set_order_status.py @@ -5,7 +5,25 @@ from south.v2 import DataMigration from django.db import models from django.db.models import F -from project.customer import consts + +ORDER_PAY_DAYS = 10 + +LICENSE_TEST_PERIOD = -1 +LICENSE_UNPAID = 0 +LICENSE_PAID = 1 +LICENSE_ACTIVE = 2 +LICENSE_EXPIRED = 3 +LICENSE_SUSPENDED = 4 + +ORDER_UNPAID = 0 +ORDER_PAID = 1 +ORDER_SUSPENDED = 4 + +PAYFORM_FREE = -1 +PAYFORM_BEZNAL = 0 +PAYFORM_CARD = 1 +PAYFORM_SBER_KVITANZ = 2 + class Migration(DataMigration): @@ -14,7 +32,7 @@ class Migration(DataMigration): # Note: Don't use "from appname.models import ModelName". # Use orm.ModelName to refer to models in this application, # and orm['appname.ModelName'] for models in other applications. - orm.License.objects.filter(status__in=[consts.LICENSE_UNPAID, consts.LICENSE_PAID, consts.LICENSE_SUSPENDED]).update(order_status=F('status')) + orm.License.objects.filter(status__in=[LICENSE_UNPAID, LICENSE_PAID, LICENSE_SUSPENDED]).update(order_status=F('status')) def backwards(self, orm): "Write your backwards methods here." diff --git a/project/customer/migrations/0009_license_fix_order_status.py b/project/customer/migrations/0009_license_fix_order_status.py index 86eeb53..cee4b7a 100644 --- a/project/customer/migrations/0009_license_fix_order_status.py +++ b/project/customer/migrations/0009_license_fix_order_status.py @@ -1,12 +1,27 @@ # -*- coding: utf-8 -*- from datetime import datetime, timedelta - from south.db import db from south.v2 import DataMigration - from django.db import models -from project.customer import consts + +ORDER_PAY_DAYS = 10 + +LICENSE_TEST_PERIOD = -1 +LICENSE_UNPAID = 0 +LICENSE_PAID = 1 +LICENSE_ACTIVE = 2 +LICENSE_EXPIRED = 3 +LICENSE_SUSPENDED = 4 + +ORDER_UNPAID = 0 +ORDER_PAID = 1 +ORDER_SUSPENDED = 4 + +PAYFORM_FREE = -1 +PAYFORM_BEZNAL = 0 +PAYFORM_CARD = 1 +PAYFORM_SBER_KVITANZ = 2 class Migration(DataMigration): @@ -18,21 +33,21 @@ class Migration(DataMigration): # and orm['appname.ModelName'] for models in other applications. # всем лицензиям "пробного периода" независимо от формы оплаты сбросить статус счёта, т.к. счёта у них быть не должно - orm.License.objects.filter(status=consts.LICENSE_TEST_PERIOD).update(order_status=None) + orm.License.objects.filter(status=LICENSE_TEST_PERIOD).update(order_status=None) # вообще всем лицензиям с формой оплаты "бесплатно" сбросить статус_счета, т.к. счёта у них быть не должно - orm.License.objects.filter(payform=consts.PAYFORM_FREE).update(order_status=None) + orm.License.objects.filter(payform=PAYFORM_FREE).update(order_status=None) # всем лицензиям с одной из "платных" форм оплаты, не пустой датой оплаты и статусом лицензии "оплачен", "активирован" или "срок истёк" - задать статус счёта "оплачен" - orm.License.objects.filter(payform__gt=consts.PAYFORM_FREE, paid_date__isnull=False, - status__in=[consts.LICENSE_PAID, consts.LICENSE_ACTIVE, consts.LICENSE_EXPIRED]).update(order_status=consts.ORDER_PAID) + orm.License.objects.filter(payform__gt=PAYFORM_FREE, paid_date__isnull=False, + status__in=[LICENSE_PAID, LICENSE_ACTIVE, LICENSE_EXPIRED]).update(order_status=ORDER_PAID) # всем лицензиям с одной из "платных" форм оплаты, пустой датой оплаты и статусом лицензии "оплачен" - задать статус счёта "не оплачен" - orm.License.objects.filter(payform__gt=consts.PAYFORM_FREE, paid_date__isnull=True, status=consts.LICENSE_PAID).update(order_status=consts.ORDER_UNPAID) + orm.License.objects.filter(payform__gt=PAYFORM_FREE, paid_date__isnull=True, status=LICENSE_PAID).update(order_status=ORDER_UNPAID) # всем неоплаченным в срок лицензиям со статусом "не оплачен" - задать статус счёта "заморожен" - orm.License.objects.filter(order_date__lte = datetime.today() - timedelta(days=consts.ORDER_PAY_DAYS), - order_status=consts.ORDER_UNPAID).update(order_status=consts.ORDER_SUSPENDED) + orm.License.objects.filter(order_date__lte = datetime.today() - timedelta(days=ORDER_PAY_DAYS), + order_status=ORDER_UNPAID).update(order_status=ORDER_SUSPENDED) def backwards(self, orm):