From 99ba24e99380ffb6395c70a29a239fbf67eff98c Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Mon, 4 Dec 2023 12:44:02 +0100 Subject: [PATCH] [FIX] base_multi_company: _check_company multi-record aware Follow-up of #535 _check_company is not an `ensure_one` method, so we need to make sure that if it's called with several records, and they don't belong to the same company, everything is OK. --- base_multi_company/models/base.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/base_multi_company/models/base.py b/base_multi_company/models/base.py index 894b16f7061..fab997476ba 100644 --- a/base_multi_company/models/base.py +++ b/base_multi_company/models/base.py @@ -11,11 +11,15 @@ def _check_company(self, fnames=None): """Inject as context the company of the record that is going to be compared for being taking into account when computing the company of many2one's relations that links with our multi-company models. + + We have to serialize the call to super, but it doesn't matter in terms of + performance, as super also makes a for loop in the records. """ - company_source_id = False - if self._name == "res.company": - company_source_id = self.id - elif "company_id" in self._fields: - company_source_id = self.company_id.id - self = self.with_context(_check_company_source_id=company_source_id) - return super()._check_company(fnames=fnames) + for record in self: + company_source_id = False + if record._name == "res.company": + company_source_id = self.id + elif "company_id" in record._fields: + company_source_id = record.company_id.id + self = self.with_context(_check_company_source_id=company_source_id) + super()._check_company(fnames=fnames)