@@ -1102,7 +1102,13 @@ class LivelihoodActivity(common_models.Model):
11021102 # but there are exceptions, such as MilkProduction, where there is also an amount used for ButterProduction
11031103 quantity_consumed = models .PositiveIntegerField (blank = True , null = True , verbose_name = _ ("Quantity Consumed" ))
11041104
1105- price = models .FloatField (blank = True , null = True , verbose_name = _ ("Price" ), help_text = _ ("Price per unit" ))
1105+ price = models .FloatField (
1106+ blank = True ,
1107+ null = True ,
1108+ validators = [common_models .validate_positive ],
1109+ verbose_name = _ ("Price" ),
1110+ help_text = _ ("Price per unit" ),
1111+ )
11061112 # Can be calculated / validated as `quantity_sold * price` for livelihood strategies that involve the sale of
11071113 # a proportion of the household's own production.
11081114 income = models .FloatField (blank = True , null = True , help_text = _ ("Income" ))
@@ -1584,8 +1590,12 @@ class PaymentInKind(LivelihoodActivity):
15841590 """
15851591
15861592 # Production calculation/validation is `people_per_household * times_per_month * months_per_year`
1587- payment_per_time = models .PositiveSmallIntegerField (
1588- verbose_name = _ ("Payment per time" ), help_text = _ ("Amount of item received each time the labor is performed" )
1593+ payment_per_time = models .FloatField (
1594+ blank = True ,
1595+ null = True , # Not required if people_per_household or times_per_month is null
1596+ validators = [common_models .validate_positive ],
1597+ verbose_name = _ ("Payment per time" ),
1598+ help_text = _ ("Amount of item received each time the labor is performed" ),
15891599 )
15901600 people_per_household = models .PositiveSmallIntegerField (
15911601 verbose_name = _ ("People per household" ), help_text = _ ("Number of household members who perform the labor" )
@@ -1601,6 +1611,14 @@ class PaymentInKind(LivelihoodActivity):
16011611 help_text = _ ("Number of times in a year that the labor is performed" ),
16021612 )
16031613
1614+ def clean (self ):
1615+ # payment_per_time is only required if people_per_household and times_per_month are provided
1616+ if self .people_per_household and self .times_per_month and not self .payment_per_time :
1617+ raise ValidationError (
1618+ _ ("Payment per time is required if people per household and times per month are provided" )
1619+ )
1620+ super ().clean ()
1621+
16041622 def validate_quantity_produced (self ):
16051623 if (
16061624 self .quantity_produced
@@ -1711,8 +1729,12 @@ class OtherCashIncome(LivelihoodActivity):
17111729 # However, some other income (e.g. Remittances) just has a number of times per year and is not calculated from
17121730 # people_per_household, etc. Therefore those fields must be nullable, and we must store the total number of times
17131731 # per year as a separate field
1714- payment_per_time = models .PositiveSmallIntegerField (
1715- verbose_name = _ ("Payment per time" ), help_text = _ ("Amount of money received each time the labor is performed" )
1732+ payment_per_time = models .FloatField (
1733+ blank = True ,
1734+ null = True , # Not required if people_per_household or times_per_month is null
1735+ validators = [common_models .validate_positive ],
1736+ verbose_name = _ ("Payment per time" ),
1737+ help_text = _ ("Amount of money received each time the labor is performed" ),
17161738 )
17171739 people_per_household = models .PositiveSmallIntegerField (
17181740 verbose_name = _ ("People per household" ),
@@ -1734,6 +1756,14 @@ class OtherCashIncome(LivelihoodActivity):
17341756 help_text = _ ("Number of times in a year that the income is received" ),
17351757 )
17361758
1759+ def clean (self ):
1760+ # payment_per_time is only required if people_per_household and times_per_month are provided
1761+ if self .people_per_household and self .times_per_month and not self .payment_per_time :
1762+ raise ValidationError (
1763+ _ ("Payment per time is required if people per household and times per month are provided" )
1764+ )
1765+ super ().clean ()
1766+
17371767 def validate_income (self ):
17381768 if (
17391769 self .people_per_household
0 commit comments