diff --git a/base_location/models/res_partner.py b/base_location/models/res_partner.py index 4a6eb3e7e..3a3b989c1 100644 --- a/base_location/models/res_partner.py +++ b/base_location/models/res_partner.py @@ -90,28 +90,30 @@ class ResPartner(models.Model): if state and record.state_id != state: record.state_id = record.zip_id.city_id.state_id - @api.constrains("zip_id", "country_id", "city_id", "state_id") + @api.constrains("zip_id", "country_id", "city_id", "state_id", "zip") def _check_zip(self): if self.env.context.get("skip_check_zip"): return for rec in self: if not rec.zip_id: continue - if rec.zip_id.city_id.state_id != rec.state_id: + if rec.zip_id.city_id.country_id != rec.country_id: raise ValidationError( - _("The state of the partner %s differs from that in " "location %s") + _("The country of the partner %s differs from that in location %s") % (rec.name, rec.zip_id.name) ) - if rec.zip_id.city_id.country_id != rec.country_id: + if rec.zip_id.city_id.state_id != rec.state_id: raise ValidationError( - _( - "The country of the partner %s differs from that in " - "location %s" - ) + _("The state of the partner %s differs from that in location %s") % (rec.name, rec.zip_id.name) ) if rec.zip_id.city_id != rec.city_id: raise ValidationError( - _("The city of partner %s differs from that in " "location %s") + _("The city of partner %s differs from that in location %s") + % (rec.name, rec.zip_id.name) + ) + if rec.zip_id.name != rec.zip: + raise ValidationError( + _("The zip of the partner %s differs from that in location %s") % (rec.name, rec.zip_id.name) ) diff --git a/base_location/tests/test_base_location.py b/base_location/tests/test_base_location.py index 42f03764f..0f4cbad13 100644 --- a/base_location/tests/test_base_location.py +++ b/base_location/tests/test_base_location.py @@ -122,6 +122,10 @@ class TestBaseLocation(common.SavepointCase): self.partner_obj.create( {"name": "P1", "zip_id": self.barcelona.id, "city_id": False} ) + with self.assertRaises(ValidationError): + self.partner_obj.create( + {"name": "P1", "zip_id": self.barcelona.id, "zip": False} + ) def test_writing_company(self): self.company.zip_id = self.barcelona