-
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.
Merge pull request #20 from openimis/develop
MERGING develop into release/24.04
- Loading branch information
Showing
16 changed files
with
495 additions
and
269 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
123 changes: 123 additions & 0 deletions
123
payment_cycle/migrations/0004_add_start_and_end_date.py
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,123 @@ | ||
from django.db import migrations, models | ||
import string | ||
import random | ||
import core.fields | ||
from django.utils.translation import gettext_lazy as _ | ||
from datetime import date | ||
from calendar import monthrange, month_name | ||
|
||
|
||
def generate_random_code(): | ||
characters = string.ascii_letters + string.digits | ||
return ''.join(random.choice(characters) for _ in range(8)) | ||
|
||
|
||
def get_default_date(): | ||
return date(1999, 6, 28) | ||
|
||
|
||
def get_date(year, month): | ||
first_day = 1 | ||
_, last_day = monthrange(year, month) | ||
return date(year, month, first_day), date(year, month, last_day) | ||
|
||
|
||
def create_code_from_date(apps, schema_editor): | ||
PaymentCycle = apps.get_model('payment_cycle', 'PaymentCycle') | ||
for payment_cycle in PaymentCycle.objects.all(): | ||
month_name_string = month_name[payment_cycle.run_month] | ||
year_month_code = f"{payment_cycle.run_year}-{month_name_string}" | ||
|
||
new_code = year_month_code | ||
while PaymentCycle.objects.filter(code=new_code).exists(): | ||
new_code = f"{year_month_code}-{generate_random_code()}" | ||
|
||
payment_cycle.code = new_code | ||
payment_cycle.save() | ||
|
||
|
||
def set_default_start_end_date_and_status(apps, schema_editor): | ||
PaymentCycle = apps.get_model('payment_cycle', 'PaymentCycle') | ||
|
||
for payment_cycle in PaymentCycle.objects.all(): | ||
start_date, end_date = get_date(payment_cycle.run_year, payment_cycle.run_month) | ||
payment_cycle.start_date = start_date | ||
payment_cycle.end_date = end_date | ||
payment_cycle.save() | ||
|
||
|
||
def create_unique_code_historical(apps, schema_editor): | ||
PaymentCycle = apps.get_model('payment_cycle', 'PaymentCycle') | ||
HistoricalPaymentCycle = apps.get_model('payment_cycle', 'HistoricalPaymentCycle') | ||
|
||
for payment_cycle in PaymentCycle.objects.all(): | ||
historical_payment_cycles = HistoricalPaymentCycle.objects.filter(id=payment_cycle.id) | ||
for historical in historical_payment_cycles: | ||
historical.code = payment_cycle.code | ||
historical.save() | ||
|
||
|
||
def set_default_start_end_date_and_status_historical(apps, schema_editor): | ||
HistoricalPaymentCycle = apps.get_model('payment_cycle', 'HistoricalPaymentCycle') | ||
|
||
for payment_cycle in HistoricalPaymentCycle.objects.all(): | ||
start_date, end_date = get_date(payment_cycle.run_year, payment_cycle.run_month) | ||
payment_cycle.start_date = start_date | ||
payment_cycle.end_date = end_date | ||
payment_cycle.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
('payment_cycle', '0003_alter_historicalpaymentcycle_date_created_and_more'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='paymentcycle', | ||
name='code', | ||
field=models.CharField(max_length=255, default=generate_random_code()), | ||
), | ||
migrations.AddField( | ||
model_name='paymentcycle', | ||
name='start_date', | ||
field=core.fields.DateField(default=get_default_date()), | ||
), | ||
migrations.AddField( | ||
model_name='paymentcycle', | ||
name='end_date', | ||
field=core.fields.DateField(default=get_default_date()), | ||
), | ||
migrations.AddField( | ||
model_name='paymentcycle', | ||
name='status', | ||
field=models.CharField(max_length=255, choices=[('PENDING', _('PENDING')), ('ACTIVE', _('ACTIVE')), | ||
('SUSPENDED', _('SUSPENDED'))], default='PENDING'), | ||
), | ||
migrations.RunPython(set_default_start_end_date_and_status), | ||
migrations.RunPython(create_code_from_date), | ||
# historical | ||
migrations.AddField( | ||
model_name='historicalpaymentcycle', | ||
name='code', | ||
field=models.CharField(max_length=255, default=generate_random_code()), | ||
), | ||
migrations.AddField( | ||
model_name='historicalpaymentcycle', | ||
name='start_date', | ||
field=core.fields.DateField(default=get_default_date()), | ||
), | ||
migrations.AddField( | ||
model_name='historicalpaymentcycle', | ||
name='end_date', | ||
field=core.fields.DateField(default=get_default_date()), | ||
), | ||
migrations.AddField( | ||
model_name='historicalpaymentcycle', | ||
name='status', | ||
field=models.CharField(max_length=255, choices=[('PENDING', _('PENDING')), ('ACTIVE', _('ACTIVE')), | ||
('SUSPENDED', _('SUSPENDED'))], default='PENDING'), | ||
), | ||
migrations.RunPython(set_default_start_end_date_and_status_historical), | ||
migrations.RunPython(create_unique_code_historical), | ||
] |
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,29 @@ | ||
# Generated by Django 3.2.24 on 2024-03-11 13:53 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('payment_cycle', '0004_add_start_and_end_date'), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name='historicalpaymentcycle', | ||
name='run_year', | ||
), | ||
migrations.RemoveField( | ||
model_name='historicalpaymentcycle', | ||
name='run_month', | ||
), | ||
migrations.RemoveField( | ||
model_name='paymentcycle', | ||
name='run_year', | ||
), | ||
migrations.RemoveField( | ||
model_name='paymentcycle', | ||
name='run_month', | ||
), | ||
] |
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,44 @@ | ||
# Generated by Django 3.2.24 on 2024-03-15 09:43 | ||
|
||
import core.fields | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('payment_cycle', '0005_remove_run_month'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='historicalpaymentcycle', | ||
name='code', | ||
field=models.CharField(max_length=255), | ||
), | ||
migrations.AlterField( | ||
model_name='historicalpaymentcycle', | ||
name='end_date', | ||
field=core.fields.DateField(), | ||
), | ||
migrations.AlterField( | ||
model_name='historicalpaymentcycle', | ||
name='start_date', | ||
field=core.fields.DateField(), | ||
), | ||
migrations.AlterField( | ||
model_name='paymentcycle', | ||
name='code', | ||
field=models.CharField(max_length=255), | ||
), | ||
migrations.AlterField( | ||
model_name='paymentcycle', | ||
name='end_date', | ||
field=core.fields.DateField(), | ||
), | ||
migrations.AlterField( | ||
model_name='paymentcycle', | ||
name='start_date', | ||
field=core.fields.DateField(), | ||
), | ||
] |
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,29 @@ | ||
# Generated by Django 3.2.24 on 2024-03-20 12:33 | ||
|
||
import core.models | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import uuid | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('core', '0027_alter_interactiveuser_last_login_and_more'), | ||
('payment_cycle', '0006_auto_20240315_0943'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='PaymentCycleMutation', | ||
fields=[ | ||
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), | ||
('mutation', models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, related_name='payment_cycle', to='core.mutationlog')), | ||
('payment_cycle', models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, related_name='mutations', to='payment_cycle.paymentcycle')), | ||
], | ||
options={ | ||
'abstract': False, | ||
}, | ||
bases=(models.Model, core.models.ObjectMutation), | ||
), | ||
] |
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 |
---|---|---|
@@ -1,10 +1,26 @@ | ||
from django.contrib.contenttypes.models import ContentType | ||
from django.db import models | ||
|
||
from core.models import HistoryModel | ||
from gettext import gettext as _ | ||
|
||
from core.models import HistoryModel, ObjectMutation, UUIDModel, MutationLog | ||
from core.fields import DateField | ||
|
||
|
||
class PaymentCycle(HistoryModel): | ||
run_year = models.IntegerField() | ||
run_month = models.SmallIntegerField() | ||
type = models.ForeignKey(ContentType, on_delete=models.DO_NOTHING, blank=True, null=True, unique=False) | ||
class PaymentCycleStatus(models.TextChoices): | ||
PENDING = 'PENDING', _('PENDING') | ||
ACTIVE = 'ACTIVE', _('ACTIVE') | ||
SUSPENDED = 'SUSPENDED', _('SUSPENDED') | ||
|
||
code = models.CharField(max_length=255, blank=False, null=False) | ||
start_date = DateField(blank=False, null=False) | ||
end_date = DateField(blank=False, null=False) | ||
status = models.CharField(max_length=255, choices=PaymentCycleStatus.choices, default=PaymentCycleStatus.PENDING) | ||
type = models.ForeignKey(ContentType, on_delete=models.DO_NOTHING, blank=True, null=True, unique=False) | ||
|
||
|
||
class PaymentCycleMutation(UUIDModel, ObjectMutation): | ||
payment_cycle = models.ForeignKey(PaymentCycle, models.DO_NOTHING, related_name='mutations') | ||
mutation = models.ForeignKey( | ||
MutationLog, models.DO_NOTHING, related_name='payment_cycle') |
Oops, something went wrong.