Skip to content

Commit e9a70ce

Browse files
committed
Update animals_slaughtered and carcass_weight to make them nullable see HEA-957
1 parent 0382ddd commit e9a70ce

2 files changed

Lines changed: 42 additions & 6 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Generated by Django 5.2.11 on 2026-02-26 07:23
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
("baseline", "0027_alter_seasonalactivity_livelihood_zone_baseline"),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name="meatproduction",
15+
name="animals_slaughtered",
16+
field=models.PositiveSmallIntegerField(
17+
blank=True, null=True, verbose_name="Number of animals slaughtered"
18+
),
19+
),
20+
migrations.AlterField(
21+
model_name="meatproduction",
22+
name="carcass_weight",
23+
field=models.FloatField(blank=True, null=True, verbose_name="Carcass weight per animal"),
24+
),
25+
]

apps/baseline/models.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,14 +1723,25 @@ class MeatProduction(LivelihoodActivity):
17231723
"""
17241724

17251725
# Production calculation /validation is `input_quantity` * `item_yield`
1726-
animals_slaughtered = models.PositiveSmallIntegerField(verbose_name=_("Number of animals slaughtered"))
1727-
carcass_weight = models.FloatField(verbose_name=_("Carcass weight per animal"))
1726+
animals_slaughtered = models.PositiveSmallIntegerField(
1727+
verbose_name=_("Number of animals slaughtered"), null=True, blank=True
1728+
)
1729+
carcass_weight = models.FloatField(verbose_name=_("Carcass weight per animal"), null=True, blank=True)
1730+
1731+
def clean(self):
1732+
super().clean()
1733+
# If animals were slaughtered, carcass weight must be recorded
1734+
if self.animals_slaughtered and self.animals_slaughtered > 0 and self.carcass_weight is None:
1735+
raise ValidationError(_("Carcass weight is required when animals slaughtered"))
17281736

17291737
def validate_quantity_produced(self):
1730-
if self.quantity_produced and self.quantity_produced != self.animals_slaughtered * self.carcass_weight:
1731-
raise ValidationError(
1732-
_("Quantity Produced for a Meat Production must be animals slaughtered multiplied by carcass weight")
1733-
)
1738+
if self.quantity_produced is not None and self.animals_slaughtered and self.carcass_weight is not None:
1739+
if self.quantity_produced != self.animals_slaughtered * self.carcass_weight:
1740+
raise ValidationError(
1741+
_(
1742+
"Quantity Produced for a Meat Production must be animals slaughtered multiplied by carcass weight"
1743+
)
1744+
)
17341745

17351746
class Meta:
17361747
verbose_name = LivelihoodStrategyType.MEAT_PRODUCTION.label

0 commit comments

Comments
 (0)