Skip to content

Commit

Permalink
Merge PR #719 into 17.0
Browse files Browse the repository at this point in the history
Signed-off-by pedrobaeza
  • Loading branch information
OCA-git-bot committed Nov 20, 2024
2 parents 2f53ac9 + 0ec9c2e commit 497e902
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
18 changes: 15 additions & 3 deletions base_multi_company/models/multi_company_abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("|")
Expand All @@ -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)
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 497e902

Please sign in to comment.