From 17ad6be46aaec5fc4ed03b4f0f0df1a6755ef1b3 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 28 Oct 2019 15:04:18 +0000 Subject: [PATCH] [FIX] base: returning a domain from an onchange Turns out we've got an operator just for the pattern of "match value if there's one, otherwise match everything". Also remove an example of domain in onchange doc. closes odoo/odoo#40938 Signed-off-by: Xavier Morel (xmo) --- odoo/addons/base/models/res_company.py | 9 ++++----- odoo/api.py | 1 - 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/odoo/addons/base/models/res_company.py b/odoo/addons/base/models/res_company.py index 84e4468850d..9731779dfdc 100644 --- a/odoo/addons/base/models/res_company.py +++ b/odoo/addons/base/models/res_company.py @@ -81,7 +81,10 @@ class Company(models.Model): street2 = fields.Char(compute='_compute_address', inverse='_inverse_street2') zip = fields.Char(compute='_compute_address', inverse='_inverse_zip') city = fields.Char(compute='_compute_address', inverse='_inverse_city') - state_id = fields.Many2one('res.country.state', compute='_compute_address', inverse='_inverse_state', string="Fed. State") + state_id = fields.Many2one( + 'res.country.state', compute='_compute_address', inverse='_inverse_state', + string="Fed. State", domain="[('country_id', '=?', country_id)]" + ) bank_ids = fields.One2many('res.partner.bank', 'company_id', string='Bank Accounts', help='Bank accounts related to this company') country_id = fields.Many2one('res.country', compute='_compute_address', inverse='_inverse_country', string="Country") email = fields.Char(related='partner_id.email', store=True, readonly=False) @@ -173,13 +176,9 @@ class Company(models.Model): @api.onchange('country_id') def _onchange_country_id_wrapper(self): - res = {'domain': {'state_id': []}} - if self.country_id: - res['domain']['state_id'] = [('country_id', '=', self.country_id.id)] values = self.on_change_country(self.country_id.id)['value'] for fname, value in values.items(): setattr(self, fname, value) - return res @api.model def _name_search(self, name, args=None, operator='ilike', limit=100, name_get_uid=None): diff --git a/odoo/api.py b/odoo/api.py index ebda349fe61..68b92943640 100644 --- a/odoo/api.py +++ b/odoo/api.py @@ -148,7 +148,6 @@ def onchange(*args): .. code-block:: python return { - 'domain': {'other_id': [('partner_id', '=', partner_id)]}, 'warning': {'title': "Warning", 'message': "What is this?", 'type': 'notification'}, }