From 950d0f1849bebc20bfd6b2d71bedfd97d675b642 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Mon, 25 Feb 2019 13:16:34 +0000 Subject: [PATCH] [FIX] product, stock_account: cost currency The cost of the product is a property field, meaning that: - its value depends on the current company; - its currency is the company currency However, several views use the monetary widget to display its currency with the default `currency_id` field. This can be incorrect, since the latter is computed based on the product's company. We introduce the new computed field `cost_currency_id` which has the appropriate value and can be used in the views. Closes #30616 opw-1934443 --- addons/product/models/product_template.py | 6 ++++++ addons/product/views/product_views.xml | 3 ++- addons/stock_account/views/product_views.xml | 2 +- addons/stock_account/views/stock_account_views.xml | 3 ++- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/addons/product/models/product_template.py b/addons/product/models/product_template.py index e40525e3933..c8a1268cb52 100644 --- a/addons/product/models/product_template.py +++ b/addons/product/models/product_template.py @@ -62,6 +62,8 @@ class ProductTemplate(models.Model): currency_id = fields.Many2one( 'res.currency', 'Currency', compute='_compute_currency_id') + cost_currency_id = fields.Many2one( + 'res.currency', 'Cost Currency', compute='_compute_cost_currency_id') # price fields price = fields.Float( @@ -163,6 +165,10 @@ class ProductTemplate(models.Model): for template in self: template.currency_id = template.company_id.sudo().currency_id.id or main_company.currency_id.id + def _compute_cost_currency_id(self): + for template in self: + template.cost_currency_id = self.env.user.company_id.currency_id.id + @api.multi def _compute_template_price(self): prices = {} diff --git a/addons/product/views/product_views.xml b/addons/product/views/product_views.xml index 7686d354722..2323224fcc9 100644 --- a/addons/product/views/product_views.xml +++ b/addons/product/views/product_views.xml @@ -51,13 +51,14 @@