diff --git a/addons/product/pricelist.py b/addons/product/pricelist.py index d1b01f15de0..28160e6b92c 100644 --- a/addons/product/pricelist.py +++ b/addons/product/pricelist.py @@ -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 diff --git a/addons/product/product.py b/addons/product/product.py index 0bc1ec3de85..3440b03ee41 100644 --- a/addons/product/product.py +++ b/addons/product/product.py @@ -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