Skip to content

Commit

Permalink
Merge PR #544 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by pedrobaeza
  • Loading branch information
OCA-git-bot committed Dec 7, 2023
2 parents 330a34e + 7543982 commit 355232a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
18 changes: 14 additions & 4 deletions base_multi_company/models/multi_company_abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,9 @@ def write(self, vals):
return super().write(vals)

@api.model
def _name_search(
self, name, args=None, operator="ilike", limit=100, name_get_uid=None
):
def _patch_company_domain(self, args):
# In some situations the 'in' operator is used with company_id in a
# name_search. ORM does not convert to a proper WHERE clause when using
# name_search or search_read. ORM does not convert to a proper WHERE clause when using
# the 'in' operator.
# e.g: ```
# WHERE "res_partner"."id" in (SELECT "res_partner_id"
Expand Down Expand Up @@ -98,10 +96,22 @@ def _name_search(
new_args.extend(fix)
else:
new_args.append(arg)
return new_args

@api.model
def _name_search(
self, name, args=None, operator="ilike", limit=100, name_get_uid=None
):
new_args = self._patch_company_domain(args)
return super()._name_search(
name,
args=new_args,
operator=operator,
limit=limit,
name_get_uid=name_get_uid,
)

@api.model
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)
14 changes: 14 additions & 0 deletions base_multi_company/tests/test_multi_company_abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,20 @@ def test_search_company_id(self):
# Result is [(<id>, "test")]
self.assertEqual(name_result[0][0], self.record_1.id)

result = self.test_model.search_read(
[("company_id", "in", [False, self.company_2.id])], ["name"]
)
self.assertEqual([{"id": self.record_1.id, "name": self.record_1.name}], result)

def test_patch_company_domain(self):
new_domain = self.test_model._patch_company_domain(
[["company_id", "in", [False, self.company_2.id]]]
)
self.assertEqual(
["|", ["company_id", "=", False], ["company_id", "=", self.company_2.id]],
new_domain,
)

def test_compute_company_id2(self):
"""
Test the computation of company_id for a multi_company_abstract.
Expand Down

0 comments on commit 355232a

Please sign in to comment.