[FIX] product: fix performance bottleneck of populate

Since 4911a26d2c, `_check_barcode_uniqueness`
flush the default `_order` of `product.product` models (via many2one in the `_order`
of `product.packaging`). It creates a bottleneck (take > 10 minutes ) when we populate
(medium size) the `product.template` during `set_barcode_variant`.

Force the order to be trivial and simplify the domain with a 'in' instead of
multiple OR.

closes odoo/odoo#85687

Signed-off-by: William Henrotin (whe) <whe@odoo.com>
This commit is contained in:
Rémy Voet (ryv)
2022-03-03 11:04:13 +00:00
parent 08cc113be1
commit 13bddabbe0
2 changed files with 6 additions and 6 deletions
+3 -3
View File
@@ -30,10 +30,10 @@ class ProductPackaging(models.Model):
@api.constrains('barcode')
def _check_barcode_uniqueness(self):
""" With GS1 nomenclature, products and packagins use the same pattern. Therefore, we need
""" With GS1 nomenclature, products and packagings use the same pattern. Therefore, we need
to ensure the uniqueness between products' barcodes and packagings' ones"""
condition = expression.OR([[('barcode', '=', b)] for b in self.mapped('barcode') if b])
if self.env['product.product'].search(condition, limit=1):
domain = [('barcode', 'in', [b for b in self.mapped('barcode') if b])]
if self.env['product.product'].search(domain, order="id", limit=1):
raise ValidationError(_("A product already uses the barcode"))
def _check_qty(self, product_qty, uom_id, rounding_method="HALF-UP"):
+3 -3
View File
@@ -174,10 +174,10 @@ class ProductProduct(models.Model):
@api.constrains('barcode')
def _check_barcode_uniqueness(self):
""" With GS1 nomenclature, products and packagins use the same pattern. Therefore, we need
""" With GS1 nomenclature, products and packagings use the same pattern. Therefore, we need
to ensure the uniqueness between products' barcodes and packagings' ones"""
condition = expression.OR([[('barcode', '=', b)] for b in self.mapped('barcode') if b])
if self.env['product.packaging'].search(condition, limit=1):
domain = [('barcode', 'in', [b for b in self.mapped('barcode') if b])]
if self.env['product.packaging'].search(domain, order="id", limit=1):
raise ValidationError(_("A packaging already uses the barcode"))
def _get_invoice_policy(self):