Skip to content

Commit

Permalink
fixup! pt_multi_link: improve UX by searching templates on default_code
Browse files Browse the repository at this point in the history
  • Loading branch information
sebalix committed Jul 17, 2023
1 parent 9cba4e0 commit 81720ff
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions product_template_multi_link/models/product_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def _name_search(
expression.OR(
[
[("default_code", operator, name)],
[("product_variant_ids.default_code", operator, name)],
[(self._rec_name, operator, name)],
]
),
Expand Down
46 changes: 46 additions & 0 deletions product_template_multi_link/tests/test_product_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,49 @@ def test_product_template_name_search_with_default_code(self):
.name_search("PTL_default_code", args=[("id", "!=", 0)])
)
self.assertTrue(product)

def test_product_template_multi_variants_name_search_with_default_code(self):
# Create variants
self.product_template.write(
{
"attribute_line_ids": [
(0, 0, {
"attribute_id": self.env.ref("product.product_attribute_1").id,
"value_ids": [
(6, 0, [
self.env.ref('product.product_attribute_value_1').id,
self.env.ref('product.product_attribute_value_2').id,
])
]
})
],
}
)
variant1, variant2 = self.product_template.product_variant_ids
variant1.default_code = "PV1_default_code"
variant2.default_code = "PV2_default_code"
# Odoo std behavior: search with template default code
product = self.env["product.template"].name_search("PTL_default_code")
self.assertFalse(product)
# Odoo std behavior: search with one of the variant default code
product = self.env["product.template"].name_search("PV1_default_code")
self.assertTrue(product)
# Searching with the default_code => the template is not found
product = self.env["product.template"].name_search(
"PTL_default_code", args=[("id", "!=", 0)]
)
self.assertFalse(product)
# Same but enable the search on default_code => the template is still not found
product = (
self.env["product.template"]
.with_context(name_search_default_code=True)
.name_search("PTL_default_code", args=[("id", "!=", 0)])
)
self.assertFalse(product)
# Same but with one of the variant default_code => the template is now found
product = (
self.env["product.template"]
.with_context(name_search_default_code=True)
.name_search("PV1_default_code", args=[("id", "!=", 0)])
)
self.assertTrue(product)

0 comments on commit 81720ff

Please sign in to comment.