[FIX] product: product price assumed currency

Before this revision, with a configuration setup
like this:
 - Company A - Currency EUR
 - Company B - Currency USD
 - Public Pricelist- Currency EUR
 - Product A - Company A - Price 100 (EUR)
 - Product B - No company - Price 100

When a user set in Company B browses the `/shop`,
the pricelist applied is the public pricelist,
and, therefore, the prices are shown in EUR
(nothing wrong so far),
but the currency of the price set on the products
were assumed in USD, the user company currency, and,
therefore, the rate conversion from USD to EUR
was applied.

The product A, configured with a sale price of 100€
in the company A, was therefore displayed to 92€
(100€ * the USD-EUR rate).

The product B, without any company set, as well.

Meaning, two users from two different companies using the same
pricelist see two different prices in the same currency,
because their companies do not use the same currency.
This doesn't make any sense.

With this revision,
when setuping a sale price on a product, the currency
of this price is assumed in the currency of the company
set on the product.

If there is no company set on the product (the company
is not required), the currency assumed is then the currency
of the main company.

opw-666059
This commit is contained in:
Denis Ledoux
2016-01-27 14:10:50 +01:00
parent 4bbddc7476
commit 3622c0d12a
2 changed files with 14 additions and 10 deletions
+1 -2
View File
@@ -242,8 +242,7 @@ class product_pricelist(osv.osv):
break
# Final price conversion into pricelist currency
if suitable_rule and suitable_rule.compute_price != 'fixed' and suitable_rule.base != 'pricelist':
user_company = self.pool['res.users'].browse(cr, uid, uid, context=context).company_id
price = self.pool['res.currency'].compute(cr, uid, user_company.currency_id.id, pricelist.currency_id.id, price, context=context)
price = self.pool['res.currency'].compute(cr, uid, product.currency_id.id, pricelist.currency_id.id, price, context=context)
results[product.id] = (price, suitable_rule and suitable_rule.id or False)
return results
+13 -8
View File
@@ -421,6 +421,17 @@ class product_template(osv.osv):
return product.write({'list_price': value})
def _product_currency(self, cr, uid, ids, name, arg, context=None):
try:
main_company = self.pool['ir.model.data'].get_object(cr, uid, 'base', 'main_company')
except ValueError:
company_ids = self.pool['res.company'].search(cr, uid, [], limit=1, order="id", context=context)
main_company = self.pool['res.company'].browse(cr, uid, company_ids[0], context=context)
res = {}
for product in self.browse(cr, uid, ids, context=context):
res[product.id] = product.company_id.currency_id.id or main_company.currency_id.id
return res
def _get_product_variant_count(self, cr, uid, ids, name, arg, context=None):
res = {}
for product in self.browse(cr, uid, ids, context=context):
@@ -477,11 +488,7 @@ class product_template(osv.osv):
'rental': fields.boolean('Can be Rent'),
'categ_id': fields.many2one('product.category','Internal Category', required=True, change_default=True, domain="[('type','=','normal')]" ,help="Select category for the current product"),
'price': fields.function(_product_template_price, fnct_inv=_set_product_template_price, type='float', string='Price', digits_compute=dp.get_precision('Product Price')),
'currency_id': fields.related(
'company_id', 'currency_id',
type='many2one',
relation='res.currency',
string='Currency'),
'currency_id': fields.function(_product_currency, type='many2one', relation='res.currency', string='Currency'),
'list_price': fields.float('Sale Price', digits_compute=dp.get_precision('Product Price'), help="Base price to compute the customer price. Sometimes called the catalog price."),
'lst_price' : fields.related('list_price', type="float", string='Public Price', digits_compute=dp.get_precision('Product Price')),
'standard_price': fields.function(_compute_product_template_field, fnct_inv=_set_product_template_field, fnct_search=_search_by_standard_price, multi='_compute_product_template_field', type='float', string='Cost', digits_compute=dp.get_precision('Product Price'),
@@ -556,8 +563,6 @@ class product_template(osv.osv):
if context is None:
context = {}
if 'currency_id' in context:
currency_id = self.pool['res.users'].browse(cr, uid, uid, context=context).company_id.currency_id.id
res = {}
product_uom_obj = self.pool.get('product.uom')
for product in products:
@@ -580,7 +585,7 @@ class product_template(osv.osv):
if 'currency_id' in context:
# Take current user company currency.
# This is right cause a field cannot be in more than one currency
res[product.id] = self.pool.get('res.currency').compute(cr, uid, currency_id,
res[product.id] = self.pool.get('res.currency').compute(cr, uid, product.currency_id.id,
context['currency_id'], res[product.id], context=context)
return res