[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) <vfe@odoo.com>
Signed-off-by: Atul Patel (atp) <atp@odoo.com>
This commit is contained in:
Atul Patel
2023-12-01 18:14:22 +00:00
parent 94785b9889
commit d76e608da4
+3 -1
View File
@@ -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