diff --git a/base_multi_company/models/multi_company_abstract.py b/base_multi_company/models/multi_company_abstract.py index cf7fb2a6c74..63308e8d2ac 100644 --- a/base_multi_company/models/multi_company_abstract.py +++ b/base_multi_company/models/multi_company_abstract.py @@ -107,7 +107,7 @@ def _patch_company_domain(self, args): if args is None: args = [] for arg in args: - if type(arg) == list and arg[:2] == ["company_id", "in"]: + if type(arg) in {list, tuple} and list(arg[:2]) == ["company_id", "in"]: fix = [] for _i in range(len(arg[2]) - 1): fix.append("|") @@ -135,3 +135,10 @@ def _name_search( def search_read(self, domain=None, fields=None, offset=0, limit=None, order=None): new_domain = self._patch_company_domain(domain) return super().search_read(new_domain, fields, offset, limit, order) + + @api.model + def search(self, args, offset=0, limit=None, order=None, count=False): + args = self._patch_company_domain(args) + return super().search( + args, offset=offset, limit=limit, order=order, count=count + ) diff --git a/base_multi_company/tests/test_multi_company_abstract.py b/base_multi_company/tests/test_multi_company_abstract.py index dc6f54aabb8..c34936ed1ee 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]]]