Skip to content

Commit

Permalink
[IMP] product_multi_barcode: Performance
Browse files Browse the repository at this point in the history
Improve search speed when searching products by name.

Task: 4183
  • Loading branch information
GabbasovDinar committed Dec 17, 2024
1 parent 0aa0936 commit 5ddeadc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
1 change: 1 addition & 0 deletions product_multi_barcode/models/product_barcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class ProductBarcode(models.Model):
name = fields.Char(
string="Barcode",
required=True,
index="trigram",
)
sequence = fields.Integer(
default=0,
Expand Down
6 changes: 2 additions & 4 deletions product_multi_barcode/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class ProductProduct(models.Model):
comodel_name="product.barcode",
inverse_name="product_id",
string="Barcodes",
auto_join=True,
)
barcode = fields.Char(
string="Main barcode",
Expand Down Expand Up @@ -60,11 +61,8 @@ def _search(self, domain, *args, **kwargs):
def _get_barcode_domain(self, sub_domain, domain):
barcode_operator = sub_domain[1]
barcode_value = sub_domain[2]
barcodes = self.env["product.barcode"].search(
[("name", barcode_operator, barcode_value)]
)
domain = [
("barcode_ids", "in", barcodes.ids)
("barcode_ids.name", barcode_operator, barcode_value)
if x[0] == "barcode" and x[2] == barcode_value
else x
for x in domain
Expand Down

0 comments on commit 5ddeadc

Please sign in to comment.