diff --git a/spp_registry/models/individual.py b/spp_registry/models/individual.py index da2101a62..87a0681e3 100644 --- a/spp_registry/models/individual.py +++ b/spp_registry/models/individual.py @@ -75,12 +75,6 @@ def _compute_calc_age(self): for line in self: line.age = self.compute_age_from_dates(line.birthdate) - @api.constrains("age") - def _check_age_is_integer(self): - for record in self: - if record.age and not record.age.isdigit(): - raise ValidationError(_("Age must be a valid integer.")) - def compute_age_from_dates(self, partner_dob): now = datetime.strptime(str(fields.Datetime.now())[:10], "%Y-%m-%d") if partner_dob: diff --git a/spp_registry/tests/test_individual_name.py b/spp_registry/tests/test_individual_name.py index 4a6f5eda5..f958b06b6 100644 --- a/spp_registry/tests/test_individual_name.py +++ b/spp_registry/tests/test_individual_name.py @@ -279,21 +279,25 @@ def test_age_populated_from_birthdate(self): @tagged("post_install", "-at_install") class TestCheckAgeIsInteger(RegistryCommon): - """``_check_age_is_integer`` — constraint on the ``age`` field. - - Note: ``age`` is a NON-stored compute, so ``@api.constrains("age")`` - only fires when ``age`` is read after a dependency change. In - practice, creating an individual with no birthdate yields - ``age = "No Birthdate!"`` (not isdigit), but the constraint does NOT - fire because Odoo's constrains hooks only trigger on stored writes. - - These tests pin the current observable behavior. If the constraint - is ever made to fire (e.g., by storing the compute), the second test - will need to flip to ``assertRaises(ValidationError)``. + """Creation behavior around the computed ``age`` field. + + ``age`` is a NON-stored compute derived from ``birthdate`` + (``str(years)`` when set, else ``"No Birthdate!"``), so it can never + carry a user-supplied non-integer. The former ``@api.constrains("age")`` + ``_check_age_is_integer`` guard therefore never fired (Odoo's constrains + hooks only trigger on stored writes) and only emitted the registry-load + warning ``@constrains parameter 'age' is not writeable`` — it was removed + as dead code. + + These tests pin the observable behavior the removal must preserve: + an individual can be created with or without a birthdate. They also + guard against a naive re-introduction (e.g. constraining on + ``birthdate`` or storing the compute), which would make the + birthdate-less case raise on ``age == "No Birthdate!"``. """ def test_individual_without_birthdate_can_be_created(self): - """Despite age=='No Birthdate!' (not isdigit), no error.""" + """age=='No Birthdate!' (not isdigit) must not block creation.""" rec = self.Partner.create({"name": "Ageless", "is_registrant": True}) self.assertTrue(rec.id)