From 097b64075a7191d4f56b6e8a870cc9033a5748d7 Mon Sep 17 00:00:00 2001 From: Victor Feyens Date: Thu, 19 Mar 2020 09:53:48 +0000 Subject: [PATCH] [IMP] product: computes can be written in batch. When the value is the same for all records, the write can be done in batch, this can lead to a "slight" performance improvement, depending on write overrides, and how the value was computed for each line. --- addons/product/models/product.py | 3 +-- addons/product/models/product_template.py | 12 ++++-------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/addons/product/models/product.py b/addons/product/models/product.py index b868751b0d9..59858e98e64 100644 --- a/addons/product/models/product.py +++ b/addons/product/models/product.py @@ -220,8 +220,7 @@ class ProductProduct(models.Model): product.combination_indices = product.product_template_attribute_value_ids._ids2str() def _compute_is_product_variant(self): - for product in self: - product.is_product_variant = True + self.is_product_variant = True @api.depends_context('pricelist', 'partner', 'quantity', 'uom', 'date', 'no_variant_attributes_price_extra') def _compute_product_price(self): diff --git a/addons/product/models/product_template.py b/addons/product/models/product_template.py index 9f5a5458020..347dd7d55a4 100644 --- a/addons/product/models/product_template.py +++ b/addons/product/models/product_template.py @@ -173,8 +173,7 @@ class ProductTemplate(models.Model): @api.depends_context('company') def _compute_cost_currency_id(self): - for template in self: - template.cost_currency_id = self.env.company.currency_id.id + self.cost_currency_id = self.env.company.currency_id.id def _compute_template_price(self): prices = self._compute_template_price_no_inverse() @@ -259,8 +258,7 @@ class ProductTemplate(models.Model): template.weight = 0.0 def _compute_is_product_variant(self): - for template in self: - template.is_product_variant = False + self.is_product_variant = False @api.depends('product_variant_ids.barcode') def _compute_barcode(self): @@ -329,12 +327,10 @@ class ProductTemplate(models.Model): return self._get_volume_uom_id_from_ir_config_parameter().display_name def _compute_weight_uom_name(self): - for template in self: - template.weight_uom_name = self._get_weight_uom_name_from_ir_config_parameter() + self.weight_uom_name = self._get_weight_uom_name_from_ir_config_parameter() def _compute_volume_uom_name(self): - for template in self: - template.volume_uom_name = self._get_volume_uom_name_from_ir_config_parameter() + self.volume_uom_name = self._get_volume_uom_name_from_ir_config_parameter() def _set_weight(self): for template in self: