Skip to content

Commit

Permalink
[FIX] base_multi_company: search with in operator
Browse files Browse the repository at this point in the history
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
  • Loading branch information
chienandalu committed Nov 19, 2024
1 parent 8ecf727 commit 7ed5468
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
9 changes: 8 additions & 1 deletion base_multi_company/models/multi_company_abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("|")
Expand Down Expand Up @@ -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
)
7 changes: 7 additions & 0 deletions base_multi_company/tests/test_multi_company_abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]]
Expand Down

0 comments on commit 7ed5468

Please sign in to comment.