Browse Source

[12.0][IMP] - filter city zip by country in partner form

12.0
sbejaoui 5 years ago
parent
commit
003c692e91
  1. 1
      base_location/models/res_city_zip.py
  2. 15
      base_location/models/res_partner.py

1
base_location/models/res_city_zip.py

@ -18,6 +18,7 @@ class ResCityZip(models.Model):
'res.city',
'City',
required=True,
auto_join=True
)
display_name = fields.Char(compute='_compute_new_display_name',
store=True, index=True)

15
base_location/models/res_partner.py

@ -27,6 +27,12 @@ class ResPartner(models.Model):
'zip_id': [('city_id', '=', self.city_id.id)]
},
}
if self.country_id:
return {
'domain': {
'zip_id': [('city_id.country_id', '=', self.country_id.id)]
}
}
return {'domain': {'zip_id': []}}
@api.onchange('country_id')
@ -34,6 +40,15 @@ class ResPartner(models.Model):
res = super()._onchange_country_id()
if self.zip_id and self.zip_id.city_id.country_id != self.country_id:
self.zip_id = False
if self.country_id:
city_zip_domain = {
"zip_id": [("city_id.country_id", "=", self.country_id.id)]
}
if isinstance(res, dict):
res.setdefault("domain", {})
res["domain"].update(city_zip_domain)
else:
res = {"domain": city_zip_domain}
return res
@api.onchange('zip_id')

Loading…
Cancel
Save