diff --git a/core/migrations/0018_alter_attrition_cost_centre_and_more.py b/core/migrations/0018_alter_attrition_cost_centre_and_more.py new file mode 100644 index 00000000..59266439 --- /dev/null +++ b/core/migrations/0018_alter_attrition_cost_centre_and_more.py @@ -0,0 +1,51 @@ +# Generated by Django 5.1.3 on 2024-12-10 13:53 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("core", "0017_alter_attrition_cost_centre_and_more"), + ("costcentre", "0008_alter_simplehistoryarchivedcostcentre_options_and_more"), + ] + + operations = [ + migrations.AlterField( + model_name="attrition", + name="cost_centre", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.PROTECT, + to="costcentre.costcentre", + ), + ), + migrations.AlterField( + model_name="attrition", + name="financial_year", + field=models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, to="core.financialyear" + ), + ), + migrations.AlterField( + model_name="payuplift", + name="financial_year", + field=models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, to="core.financialyear" + ), + ), + migrations.AddConstraint( + model_name="attrition", + constraint=models.UniqueConstraint( + fields=("financial_year", "cost_centre"), name="unique_attrition" + ), + ), + migrations.AddConstraint( + model_name="payuplift", + constraint=models.UniqueConstraint( + fields=("financial_year",), name="unique_pay_uplift" + ), + ), + ] diff --git a/core/models.py b/core/models.py index ddb438a9..7b43fdbf 100644 --- a/core/models.py +++ b/core/models.py @@ -97,9 +97,7 @@ class Meta: def periods(self) -> list[float]: return [getattr(self, month) for month in MONTHS] - financial_year = models.ForeignKey( - FinancialYear, on_delete=models.PROTECT, unique=True - ) + financial_year = models.ForeignKey(FinancialYear, on_delete=models.PROTECT) apr = models.FloatField(default=1.0) may = models.FloatField(default=1.0) jun = models.FloatField(default=1.0) @@ -115,19 +113,36 @@ def periods(self) -> list[float]: class PayUplift(PayModifiers): - pass + class Meta: + constraints = ( + models.UniqueConstraint( + fields=[ + "financial_year", + ], + name="unique_pay_uplift", + ), + ) class Attrition(PayModifiers): class Meta: verbose_name_plural = "attrition" + constraints = ( + models.UniqueConstraint( + fields=[ + "financial_year", + "cost_centre", + ], + name="unique_attrition", + ), + ) + cost_centre = models.ForeignKey( "costcentre.CostCentre", on_delete=models.PROTECT, null=True, blank=True, - unique=True, )