From 5b69ce190280be39a7ac97558a88d4852db7160b Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Mon, 6 May 2013 12:39:39 +0200 Subject: [PATCH] [IMP] Change stock move price to company currency and remove rounding bzr revid: jco@openerp.com-20130506103939-bioi6i6inyuz2kq6 --- addons/product_expiry/product_expiry_demo.xml | 3 ++- addons/stock/stock.py | 2 +- addons/stock_fifo_lifo/stock_fifo_lifo.py | 13 +++++++++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/addons/product_expiry/product_expiry_demo.xml b/addons/product_expiry/product_expiry_demo.xml index 1d52e5b5272..d22e2f26d57 100644 --- a/addons/product_expiry/product_expiry_demo.xml +++ b/addons/product_expiry/product_expiry_demo.xml @@ -5,6 +5,7 @@ buy 7.0 5.0 + standard @@ -34,7 +35,7 @@ buy 8.0 - 6.0 + diff --git a/addons/stock/stock.py b/addons/stock/stock.py index a5f8a24357f..853c37c3a18 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -1611,7 +1611,7 @@ class stock_move(osv.osv): "* Waiting Availability: This state is reached when the procurement resolution is not straight forward. It may need the scheduler to run, a component to me manufactured...\n"\ "* Available: When products are reserved, it is set to \'Available\'.\n"\ "* Done: When the shipment is processed, the state is \'Done\'."), - 'price_unit': fields.float('Unit Price', digits_compute= dp.get_precision('Account'), help="Technical field used to record the product cost set by the user during a picking confirmation (when average price costing method is used)"), + 'price_unit': fields.float('Unit Price', help="Technical field used to record the product cost set by the user during a picking confirmation (when average price costing method is used)"), 'price_currency_id': fields.many2one('res.currency', 'Currency for average price', help="Technical field used to record the currency chosen by the user during a picking confirmation (when average price costing method is used)"), 'company_id': fields.many2one('res.company', 'Company', required=True, select=True), 'backorder_id': fields.related('picking_id','backorder_id',type='many2one', relation="stock.picking", string="Back Order of", select=True), diff --git a/addons/stock_fifo_lifo/stock_fifo_lifo.py b/addons/stock_fifo_lifo/stock_fifo_lifo.py index b099167bf19..74aed0727ff 100644 --- a/addons/stock_fifo_lifo/stock_fifo_lifo.py +++ b/addons/stock_fifo_lifo/stock_fifo_lifo.py @@ -145,7 +145,7 @@ class stock_move(osv.osv): if move.picking_id.type == 'out' and cost_method in ['fifo', 'lifo']: #get_stock_matchings will convert to currency and UoM of this stock move tuples = product_obj.get_stock_matchings_fifolifo(cr, uid, [product.id], product_qty, cost_method == 'fifo', - product_uom, move.price_currency_id.id, context=context) + product_uom, move.company_id.currency_id.id, context=context) #Always move of the company price_amount = 0.0 amount = 0.0 move_currency_id = move.company_id.currency_id.id @@ -157,7 +157,6 @@ class stock_move(osv.osv): move_in = self.browse(cr, uid, match[0], context=context) #Reduce remaining quantity self.write(cr, uid, match[0], { 'qty_remaining': move_in.qty_remaining - match[3]}, context=context) - price_amount += match[1] * match[2] amount += match[1] self.write(cr, uid, move.id, {'price_unit': price_amount / amount}, context=context) @@ -180,9 +179,15 @@ class stock_move(osv.osv): # When the move is products returned to supplier or return products from customer # then the price should be the price from the original move elif cost_method in ['fifo', 'lifo']: + #The currency in the stock move should be the currency of the company + if product_currency != move.company_id.currency_id.id: + new_price = currency_obj.compute(cr, uid, product_currency, move.company_id.currency_id.id, + product_price, round=False) + else: + new_price = product_price self.write(cr, uid, [move.id], - {'price_unit': product_price, - 'price_currency_id': product_currency}) + {'price_unit': new_price, + 'price_currency_id': move.company_id.currency_id.id}) return True class stock_move_matching(osv.osv):