[IMP] base: choice of state/country easier in banks and partners
OPW 1891131 closes #27497 When creating a new bank account/partner address, the view displays the 'state 'field before the 'country_id' field, which naturally leads users to select the state before selecting the country. But there was problem: in order to select a state, one had to first select a country, which was confusing. Done: - allow the user to select the state before the country (without restriction on country) - remove the state from the form when the country changes, if the state (name) is not in the country - automatically set the country when the state is set - always display the country code in the name_get of res.country.state, to deal with the case where different countries have a state with the same name
This commit is contained in:
@@ -26,7 +26,7 @@ class Bank(models.Model):
|
||||
street2 = fields.Char()
|
||||
zip = fields.Char()
|
||||
city = fields.Char()
|
||||
state = fields.Many2one('res.country.state', 'Fed. State', domain="[('country_id', '=', country)]")
|
||||
state = fields.Many2one('res.country.state', 'Fed. State', domain="[('country_id', '=?', country)]")
|
||||
country = fields.Many2one('res.country')
|
||||
email = fields.Char()
|
||||
phone = fields.Char()
|
||||
@@ -52,6 +52,16 @@ class Bank(models.Model):
|
||||
domain = ['&'] + domain
|
||||
bank_ids = self._search(domain + args, limit=limit, access_rights_uid=name_get_uid)
|
||||
return self.browse(bank_ids).name_get()
|
||||
|
||||
@api.onchange('country')
|
||||
def _onchange_country_id(self):
|
||||
if self.country and self.country != self.state.country_id:
|
||||
self.state = False
|
||||
|
||||
@api.onchange('state')
|
||||
def _onchange_state(self):
|
||||
if self.state.country_id:
|
||||
self.country = self.state.country_id
|
||||
|
||||
|
||||
class ResPartnerBank(models.Model):
|
||||
|
||||
@@ -128,3 +128,10 @@ class CountryState(models.Model):
|
||||
search_domain.append(('id', 'not in', first_state_ids))
|
||||
state_ids = first_state_ids + self._search(search_domain + args, limit=limit, access_rights_uid=name_get_uid)
|
||||
return [(state.id, state.display_name) for state in self.browse(state_ids)]
|
||||
|
||||
@api.multi
|
||||
def name_get(self):
|
||||
result = []
|
||||
for record in self:
|
||||
result.append((record.id, "{} ({})".format(record.name, record.country_id.code)))
|
||||
return result
|
||||
|
||||
@@ -191,7 +191,7 @@ class Partner(models.Model):
|
||||
street2 = fields.Char()
|
||||
zip = fields.Char(change_default=True)
|
||||
city = fields.Char()
|
||||
state_id = fields.Many2one("res.country.state", string='State', ondelete='restrict')
|
||||
state_id = fields.Many2one("res.country.state", string='State', ondelete='restrict', domain="[('country_id', '=?', country_id)]")
|
||||
country_id = fields.Many2one('res.country', string='Country', ondelete='restrict')
|
||||
email = fields.Char()
|
||||
email_formatted = fields.Char(
|
||||
@@ -364,10 +364,13 @@ class Partner(models.Model):
|
||||
|
||||
@api.onchange('country_id')
|
||||
def _onchange_country_id(self):
|
||||
if self.country_id:
|
||||
return {'domain': {'state_id': [('country_id', '=', self.country_id.id)]}}
|
||||
else:
|
||||
return {'domain': {'state_id': []}}
|
||||
if self.country_id and self.country_id != self.state_id.country_id:
|
||||
self.state_id = False
|
||||
|
||||
@api.onchange('state_id')
|
||||
def _onchange_state(self):
|
||||
if self.state_id.country_id:
|
||||
self.country_id = self.state_id.country_id
|
||||
|
||||
@api.onchange('email')
|
||||
def onchange_email(self):
|
||||
|
||||
Reference in New Issue
Block a user