diff options
| author | Nicolas Lempereur <nle@odoo.com> | 2018-07-12 17:41:05 +0200 |
|---|---|---|
| committer | Nicolas Lempereur <nle@odoo.com> | 2018-07-13 10:52:33 +0200 |
| commit | 05a00fa9d4f001cef6d31a5b8d20a847de4f455b (patch) | |
| tree | 1e0bf5bd8e4b3c168de54241f9804453699b8cb8 /addons | |
| parent | 6e6e3d4c964ac8c54149104b340345523ecb7365 (diff) | |
[FIX] product: variant num w/o prefetch pollution
When getting:
- product_variant_count,
- sales_count,
of a product.product, we would pollute the records to be prefetched by
all the variants when counting the number of variants.
Thus if this happened before sales_count, we would possibly compute the
sales_count for up to 1000 records when it could have been needed for
just one.
By using `.with_prefetch()`, a recordset will have its own records to be
prefetched list and will not pollute the original one.
opw-1865111
fixes #25649
closes #23112 (PR with similar fix)
closes #25741
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/product/models/product_template.py | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/addons/product/models/product_template.py b/addons/product/models/product_template.py index f8a4ffea081..9056d40972b 100644 --- a/addons/product/models/product_template.py +++ b/addons/product/models/product_template.py @@ -250,7 +250,8 @@ class ProductTemplate(models.Model): @api.one @api.depends('product_variant_ids.product_tmpl_id') def _compute_product_variant_count(self): - self.product_variant_count = len(self.product_variant_ids) + # do not pollute variants to be prefetched when counting variants + self.product_variant_count = len(self.with_prefetch().product_variant_ids) @api.depends('product_variant_ids', 'product_variant_ids.default_code') def _compute_default_code(self): |
