From 9607f4e801cf4f78eb632e8f603822a891d47a31 Mon Sep 17 00:00:00 2001 From: Nans Lefebvre Date: Mon, 18 Feb 2019 12:59:38 +0000 Subject: [PATCH] [FIX] base: synchronize (non-false) company_id to child contacts Let the database be in multi-company with unshared contact catalog. Let F be a filter "('partner_id', 'not ilike', 'string')" on invoices. If there is a contact which parent belongs to another company, then this parent cannot be read. Thus the name_get on partner can create an access error. As a result applying the filter F would fail and return no results. It generally doesn't make much sense to have a contact company X, which belongs to the Odoo Company OC1, while its child contacts are in another Odoo company, since many fields are directly computed from the parent. However it is useful to have X belongs to no company, while it has child contacts X>Yi belonging to company OCi. In the first case it can create access errors interrupting the normal flow of operations, while the latter should not. To forbid the first case while allowing the second, we synchronize company_id, but add a special case to ignore it if it set to False. Note that PR#30997 should be used in case the name_get causes an error for another reason that is deemed a legitimate use-case. opw 1933862 closes odoo/odoo#31364 --- odoo/addons/base/models/res_partner.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/odoo/addons/base/models/res_partner.py b/odoo/addons/base/models/res_partner.py index aeaf5b37573..794704d376c 100644 --- a/odoo/addons/base/models/res_partner.py +++ b/odoo/addons/base/models/res_partner.py @@ -404,6 +404,8 @@ class Partner(models.Model): field = self._fields[fname] if field.type == 'many2one': values[fname] = self[fname].id + if fname == 'company_id' and not self[fname].id: + values.pop('company_id') elif field.type == 'one2many': raise AssertionError(_('One2Many fields cannot be synchronized as part of `commercial_fields` or `address fields`')) elif field.type == 'many2many': @@ -430,7 +432,7 @@ class Partner(models.Model): partners that aren't `commercial entities` themselves, and will be delegated to the parent `commercial entity`. The list is meant to be extended by inheriting classes. """ - return ['vat', 'credit_limit'] + return ['vat', 'credit_limit', 'company_id'] @api.multi def _commercial_sync_from_company(self):