Skip to content

Commit

Permalink
Add unique constraints to pay uplift and attrition
Browse files Browse the repository at this point in the history
  • Loading branch information
CaitBarnard committed Dec 10, 2024
1 parent dc3adae commit ec69ac4
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 5 deletions.
51 changes: 51 additions & 0 deletions core/migrations/0018_alter_attrition_cost_centre_and_more.py
Original file line number Diff line number Diff line change
@@ -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"
),
),
]
25 changes: 20 additions & 5 deletions core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
)


Expand Down

0 comments on commit ec69ac4

Please sign in to comment.