From 13e91ac467d10dcf8cafaaeeb27914372623f082 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Thu, 6 Sep 2018 14:24:01 +0200 Subject: [PATCH] [FIX] base,account,product: correct currency convertion when company is get from context Method `_convert` expect a browserecord, not an integer. --- addons/account/models/account_move.py | 6 +++++- addons/product/models/product_template.py | 5 ++++- odoo/addons/base/models/ir_qweb_fields.py | 6 +++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 539c7c9f82a..e5c3e0ef99b 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -1203,7 +1203,11 @@ class AccountMoveLine(models.Model): amount_currency = False currency_id = False date = self.env.context.get('date') or fields.Date.today() - company = self.env.context.get('company_id', self.env.user.company_id) + company_id = self.env.context.get('company_id') + if company_id: + company = self.env['res.company'].browse(company_id) + else: + company = self.env.user.company_id if src_currency and src_currency != company_currency: amount_currency = amount amount = src_currency._convert(amount, company_currency, company, date) diff --git a/addons/product/models/product_template.py b/addons/product/models/product_template.py index bcb24773cd6..60ce2ccbe54 100644 --- a/addons/product/models/product_template.py +++ b/addons/product/models/product_template.py @@ -399,7 +399,10 @@ class ProductTemplate(models.Model): # We fetch the standard price as the superuser templates = self.with_context(force_company=company and company.id or self._context.get('force_company', self.env.user.company_id.id)).sudo() if not company: - company = self._context.get('force_company', self.env.user.company_id.id) + if self._context.get('force_company'): + company = self.env['res.company'].browse(self._context['force_company']) + else: + company = self.env.user.company_id date = self.env.context.get('date') or fields.Date.today() prices = dict.fromkeys(self.ids, 0.0) diff --git a/odoo/addons/base/models/ir_qweb_fields.py b/odoo/addons/base/models/ir_qweb_fields.py index 3fb153e10ee..453629aa59a 100644 --- a/odoo/addons/base/models/ir_qweb_fields.py +++ b/odoo/addons/base/models/ir_qweb_fields.py @@ -323,7 +323,11 @@ class MonetaryConverter(models.AbstractModel): if options.get('from_currency'): date = options.get('date') or fields.Date.today() - company = options.get('company_id') or self.env.user.company_id + company_id = options.get('company_id') + if company_id: + company = self.env['res.company'].browse(company_id) + else: + company = self.env.user.company_id value = options['from_currency']._convert(value, display_currency, company, date) lang = self.user_lang()