Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[15.0][FIX] base_multi_company: search with in operator #715

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading