From d76e608da41cc5ae92f00ea2ead2be0e8ebf46a7 Mon Sep 17 00:00:00 2001 From: Atul Patel Date: Fri, 1 Dec 2023 08:33:31 +0000 Subject: [PATCH] [FIX] product: fixed wrong value for cost_currency_id will get multiple company with multiple currency record as it will try to calculate multiple template cost currency field value. we need to do iteration for template record then it will resolve the error. Error has been introduced during upgrade. ``` File "/home/odoo/src/odoo/saas-16.4/addons/product/models/product_template.py", line 189, in _compute_cost_currency_id self.cost_currency_id = self.company_id.currency_id or self.env.company.currency_id.id File "/home/odoo/src/odoo/saas-16.4/odoo/fields.py", line 1306, in __set__ self.write(protected_records, value) File "/home/odoo/src/odoo/saas-16.4/odoo/fields.py", line 3087, in write cache_value = self.convert_to_cache(value, records) File "/home/odoo/src/odoo/saas-16.4/odoo/fields.py", line 3010, in convert_to_cache raise ValueError("Wrong value for %s: %r" % (self, value)) ValueError: Wrong value for product.template.cost_currency_id: res.currency(2, 139) ``` closes odoo/odoo#144523 X-original-commit: a8d884b8fb47ad0ac3960ffc5f84f5c6316d20a6 Signed-off-by: Victor Feyens (vfe) Signed-off-by: Atul Patel (atp) --- addons/product/models/product_template.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/addons/product/models/product_template.py b/addons/product/models/product_template.py index 5fc5354b946..7017e17f177 100644 --- a/addons/product/models/product_template.py +++ b/addons/product/models/product_template.py @@ -208,7 +208,9 @@ class ProductTemplate(models.Model): @api.depends('company_id') @api.depends_context('company') def _compute_cost_currency_id(self): - self.cost_currency_id = self.company_id.currency_id or self.env.company.currency_id.id + env_currency_id = self.env.company.currency_id.id + for template in self: + template.cost_currency_id = template.company_id.currency_id.id or env_currency_id def _compute_template_field_from_variant_field(self, fname, default=False): """Sets the value of the given field based on the template variant values