diff --git a/addons/account/account_analytic_line.py b/addons/account/account_analytic_line.py index 18f63733ff6..c42597e785d 100644 --- a/addons/account/account_analytic_line.py +++ b/addons/account/account_analytic_line.py @@ -147,8 +147,9 @@ class account_analytic_line(osv.osv): # Compute based on pricetype pricetype=self.pool.get('product.price.type').browse(cr,uid,company_obj.browse(cr,uid,company_id).property_valuation_price_type.id) + # Take the company currency as the reference one + context['currency_id']=company_obj.browse(cr,uid,company_id).currency_id.id amount_unit=prod.price_get(pricetype.field, context)[prod.id] - amount=amount_unit*unit_amount or 1.0 return {'value': { 'amount': - round(amount, 2), diff --git a/addons/hr_expense/hr_expense.py b/addons/hr_expense/hr_expense.py index bb6a4d38577..3c99276f7f8 100644 --- a/addons/hr_expense/hr_expense.py +++ b/addons/hr_expense/hr_expense.py @@ -220,6 +220,7 @@ class hr_expense_line(osv.osv): # Compute based on pricetype of employee company pricetype_id = self.pool.get('hr.employee').browse(cr,uid,employee_id).user_id.company_id.property_valuation_price_type.id + context['currency_id']=self.pool.get('hr.employee').browse(cr,uid,employee_id).user_id.company_id.currency_id.id pricetype=self.pool.get('product.price.type').browse(cr,uid,pricetype_id) amount_unit=product.price_get(pricetype.field, context)[product.id] diff --git a/addons/product/company.py b/addons/product/company.py index f23d010b600..0f248dba309 100644 --- a/addons/product/company.py +++ b/addons/product/company.py @@ -36,16 +36,6 @@ class res_company(osv.osv): help="The price type field in the selected price type will be used, instead of the default one, \ for valuation of product in the current company"), } - - def _check_currency(self, cr, uid, ids): - for rec in self.browse(cr, uid, ids): - if rec.currency_id.id <> rec.property_valuation_price_type.currency_id.id: - return False - return True - - _constraints = [ - (_check_currency, 'Error! You can not chooes a pricetype in a different currency than your company (Not supported now).', ['property_valuation_price_type']) - ] res_company() diff --git a/addons/product/product.py b/addons/product/product.py index 87b0622ae9e..fdc8bcbf68e 100644 --- a/addons/product/product.py +++ b/addons/product/product.py @@ -523,7 +523,6 @@ class product_product(osv.osv): def price_get(self, cr, uid, ids, ptype='list_price', context={}): res = {} product_uom_obj = self.pool.get('product.uom') - for product in self.browse(cr, uid, ids, context=context): res[product.id] = product[ptype] or 0.0 if ptype == 'list_price': @@ -533,6 +532,16 @@ class product_product(osv.osv): uom = product.uos_id or product.uom_id res[product.id] = product_uom_obj._compute_price(cr, uid, uom.id, res[product.id], context['uom']) + # Convert from price_type currency to asked one + if 'currency_id' in context: + pricetype_obj = self.pool.get('product.price.type') + # Take the price_type currency from the product field + # This is right cause a field cannot be in more than one currency + price_type_id = pricetype_obj.search(cr,ui,['field','=',ptype])[0] + price_type_currency_id = pricetype_obj.browse(cr,uid,price_type_id).currency_id.id + res[product.id] = self.pool.get('res.currency').compute(cr, uid, price_type_currency_id, + context['currency_id'], res[product.id],context=context) + return res def copy(self, cr, uid, id, default=None, context=None): diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 37a66466b6c..e5696dde1e7 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -122,8 +122,13 @@ class stock_location(osv.osv): for r in result: c = (context or {}).copy() c['location'] = id - product = self.pool.get('product.product').read(cr, uid, r['product_id'], [field_to_read, pricetype.field], context=c) - final_value += (product[field_to_read] * product[pricetype.field]) + product = self.pool.get('product.product').read(cr, uid, r['product_id'], [field_to_read], context=c) + # Compute the amount_unit in right currency + + context['currency_id']=self.pool.get('res.users').browse(cr,uid,uid).company_id.currency_id.id + amount_unit=self.pool.get('product.product').browse(cr,uid,r['product_id']).price_get(pricetype.field, context)[r['product_id']] + + final_value += (product[field_to_read] * amount_unit) return final_value def _product_value(self, cr, uid, ids, field_names, arg, context={}): @@ -223,6 +228,7 @@ class stock_location(osv.osv): # Take the user company and pricetype price_type_id=self.pool.get('res.users').browse(cr,uid,uid).company_id.property_valuation_price_type.id pricetype=self.pool.get('product.price.type').browse(cr,uid,price_type_id) + context['currency_id']=self.pool.get('res.users').browse(cr,uid,uid).company_id.currency_id.id if not product_ids: product_ids = product_obj.search(cr, uid, []) @@ -666,7 +672,9 @@ class stock_picking(osv.osv): if type in ('in_invoice', 'in_refund'): # Take the user company and pricetype price_type_id=self.pool.get('res.users').browse(cr,users,users).company_id.property_valuation_price_type.id - pricetype=self.pool.get('product.price.type').browse(cr,uid,price_type_id) + pricetype=self.pool.get('product.price.type').browse(cr,uid,price_type_id) + context['currency_id']=move_line.company_id.currency_id.id + amount_unit=move_line.product_id.price_get(pricetype.field, context)[move_line.product_id.id] return amount_unit else: @@ -1385,7 +1393,7 @@ class stock_move(osv.osv): # Base computation on valuation price type else: company_id=move.company_id.id - + context['currency_id']=move.company_id.currency_id.id pricetype=self.pool.get('product.price.type').browse(cr,uid,move.company_id.property_valuation_price_type.id) amount_unit=move.product_id.price_get(pricetype.field, context)[move.product_id.id] amount=amount_unit * q or 1.0 diff --git a/addons/stock/wizard/wizard_partial_picking.py b/addons/stock/wizard/wizard_partial_picking.py index bb0c72dff02..db3e9a48bdd 100644 --- a/addons/stock/wizard/wizard_partial_picking.py +++ b/addons/stock/wizard/wizard_partial_picking.py @@ -126,7 +126,8 @@ def _do_split(self, cr, uid, data, context): product = product_obj.browse(cr, uid, [move.product_id.id])[0] user = users_obj.browse(cr, uid, [uid])[0] - + context['currency_id']=move.company_id.currency_id.id + qty = data['form']['move%s' % move.id] uom = data['form']['uom%s' % move.id] price = data['form']['price%s' % move.id]