From 0ec9c2e5a1ae0b6ca01b0704e95a94cc89c043e5 Mon Sep 17 00:00:00 2001 From: David Date: Mon, 18 Nov 2024 18:17:34 +0100 Subject: [PATCH] [FIX] base_multi_company: search with in operator When searching the company with a domain like [("company_id", "in", [1, False]) to include records which are shared between companies we won't get those with no companies at all. That will lead to logical errors in several workflows. TT51779 [FIX] base_multi_company: Applying the correct parameters in the search_read() method --- .../models/multi_company_abstract.py | 18 +++++++++++++++--- .../tests/test_multi_company_abstract.py | 7 +++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/base_multi_company/models/multi_company_abstract.py b/base_multi_company/models/multi_company_abstract.py index 8ebb84aefd8..58adc8904de 100644 --- a/base_multi_company/models/multi_company_abstract.py +++ b/base_multi_company/models/multi_company_abstract.py @@ -86,7 +86,10 @@ def _patch_company_domain(self, args): if args is None: args = [] for arg in args: - if isinstance(arg, list) and arg[:2] == ["company_id", "in"]: + if (isinstance(arg, list) or isinstance(arg, tuple)) and list(arg[:2]) == [ + "company_id", + "in", + ]: fix = [] for _i in range(len(arg[2]) - 1): fix.append("|") @@ -109,6 +112,15 @@ def _name_search(self, name, domain=None, operator="ilike", limit=None, order=No ) @api.model - def search_read(self, domain=None, fields=None, offset=0, limit=None, order=None): + def search_read( + self, domain=None, fields=None, offset=0, limit=None, order=None, **read_kwargs + ): new_domain = self._patch_company_domain(domain) - return super().search_read(new_domain, fields, offset, limit, order) + return super().search_read( + new_domain, fields, offset, limit, order, **read_kwargs + ) + + @api.model + def search(self, domain, offset=0, limit=None, order=None): + domain = self._patch_company_domain(domain) + return super().search(domain, offset=offset, limit=limit, order=order) diff --git a/base_multi_company/tests/test_multi_company_abstract.py b/base_multi_company/tests/test_multi_company_abstract.py index 410b02a7137..83a55eb5339 100644 --- a/base_multi_company/tests/test_multi_company_abstract.py +++ b/base_multi_company/tests/test_multi_company_abstract.py @@ -111,6 +111,13 @@ def test_search_company_id(self): ) self.assertEqual([{"id": self.record_1.id, "name": self.record_1.name}], result) + def test_search_in_false_company(self): + """Records with no company are shared across companies but we need to convert + those queries with an or operator""" + self.record_1.company_ids = False + result = self.test_model.search([("company_id", "in", [1, False])]) + self.assertEqual(result, self.record_1) + def test_patch_company_domain(self): new_domain = self.test_model._patch_company_domain( [["company_id", "in", [False, self.company_2.id]]]