diff options
| author | Christophe Simonis <chs@odoo.com> | 2019-01-02 13:42:12 +0100 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2019-01-02 13:42:12 +0100 |
| commit | 7d45e43a136957afbfee2cd7bf432d78eb24ecbf (patch) | |
| tree | 767089fc867324884451a0bacbd6d7ee96da609c /addons | |
| parent | c8de59ad2b235d3c13f6c7c0b4c9421ed6856a9b (diff) | |
| parent | 6e933e42efb8e11087db63cfb5302f37f8e8b72d (diff) | |
[MERGE] forward port branch saas-15 up to 6e933e42efb
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/product/models/product.py | 25 | ||||
| -rw-r--r-- | addons/product/models/product_template.py | 2 |
2 files changed, 24 insertions, 3 deletions
diff --git a/addons/product/models/product.py b/addons/product/models/product.py index 1f4ca973217..2067878d70d 100644 --- a/addons/product/models/product.py +++ b/addons/product/models/product.py @@ -383,17 +383,36 @@ class ProductProduct(models.Model): self.check_access_rule("read") result = [] + + # Prefetch the fields used by the `name_get`, so `browse` doesn't fetch other fields + # Use `load=False` to not call `name_get` for the `product_tmpl_id` + self.sudo().read(['name', 'default_code', 'product_tmpl_id', 'attribute_value_ids'], load=False) + + product_template_ids = self.sudo().mapped('product_tmpl_id').ids + + if partner_ids: + supplier_info = self.env['product.supplierinfo'].sudo().search([ + ('product_tmpl_id', 'in', product_template_ids), + ('name', 'in', partner_ids), + ]) + # Prefetch the fields used by the `name_get`, so `browse` doesn't fetch other fields + # Use `load=False` to not call `name_get` for the `product_tmpl_id` and `product_id` + supplier_info.sudo().read(['product_tmpl_id', 'product_id', 'product_name', 'product_code'], load=False) + supplier_info_by_template = {} + for r in supplier_info: + supplier_info_by_template.setdefault(r.product_tmpl_id, []).append(r) for product in self.sudo(): # display only the attributes with multiple possible values on the template - variable_attributes = product.attribute_line_ids.filtered(lambda l: len(l.value_ids) > 1).mapped('attribute_id') + variable_attributes = product.attribute_value_ids.filtered(lambda v: len(v.attribute_id.value_ids) > 1).mapped('attribute_id') variant = product.attribute_value_ids._variant_name(variable_attributes) name = variant and "%s (%s)" % (product.name, variant) or product.name sellers = [] if partner_ids: - sellers = [x for x in product.seller_ids if (x.name.id in partner_ids) and (x.product_id == product)] + product_supplier_info = supplier_info_by_template.get(product.product_tmpl_id, []) + sellers = [x for x in product_supplier_info if x.product_id and x.product_id == product] if not sellers: - sellers = [x for x in product.seller_ids if (x.name.id in partner_ids) and not x.product_id] + sellers = [x for x in product_supplier_info if not x.product_id] if sellers: for s in sellers: seller_variant = s.product_name and ( diff --git a/addons/product/models/product_template.py b/addons/product/models/product_template.py index 602a139bba5..e40525e3933 100644 --- a/addons/product/models/product_template.py +++ b/addons/product/models/product_template.py @@ -332,6 +332,8 @@ class ProductTemplate(models.Model): @api.multi def name_get(self): + # Prefetch the fields used by the `name_get`, so `browse` doesn't fetch other fields + self.read(['name', 'default_code']) return [(template.id, '%s%s' % (template.default_code and '[%s] ' % template.default_code or '', template.name)) for template in self] |
