From a6ae9fd39e99c0a62371f6c3e2bbd8079c157b85 Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Mon, 27 May 2013 18:23:17 +0200 Subject: [PATCH] [IMP] Check get stock move matchings bzr revid: jco@openerp.com-20130527162317-oc8fwx2jw0q7evfo --- addons/purchase/test/fifo_price.yml | 2 +- addons/stock/stock_fifo_lifo.py | 17 +++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/addons/purchase/test/fifo_price.yml b/addons/purchase/test/fifo_price.yml index 34a8b393e85..ae4786ac7f7 100644 --- a/addons/purchase/test/fifo_price.yml +++ b/addons/purchase/test/fifo_price.yml @@ -329,7 +329,7 @@ line = self.browse(cr, uid, partial_id, context=context).move_ids[0] self.pool.get("stock.partial.picking.line").write(cr, uid, [line.id], {'quantity':50}) self.do_partial(cr, uid, [partial_id]) - from datetime import * + from datetime import datetime.now(), timedelta picking_id = self.pool.get("stock.picking").browse(cr, uid, ref("outgoing_fifo_shipment_neg2")).backorder_id.id mov_ids = self.pool.get("stock.move").search(cr, uid, [('picking_id', '=', picking_id)]) self.pool.get("stock.move").write(cr, uid, mov_ids, {'date': (datetime.now()+timedelta(seconds=3)).strftime('%Y-%m-%d %H:%M:%S')}) diff --git a/addons/stock/stock_fifo_lifo.py b/addons/stock/stock_fifo_lifo.py index ac517c87b54..196b235ec50 100644 --- a/addons/stock/stock_fifo_lifo.py +++ b/addons/stock/stock_fifo_lifo.py @@ -90,13 +90,16 @@ class product_product (osv.osv): if not currency_id: currency_id = self.pool.get('res.company').browse(cr, uid, company_id, context=context).currency_id.id if fifo: - move_in_ids = move_obj.search(cr, uid, [('company_id','=', company_id), ('qty_remaining', '>', 0), ('state', '=', 'done'), - ('location_id.usage', '!=', 'internal'), ('location_dest_id.usage', '=', 'internal'), ('product_id', '=', product.id)], - order = 'date', context=context) + order = 'date, id' else: - move_in_ids = move_obj.search(cr, uid, [('company_id','=', company_id), ('qty_remaining', '>', 0), ('state', '=', 'done'), - ('location_id.usage', '!=', 'internal'), ('location_dest_id.usage', '=', 'internal'), ('product_id', '=', product.id)], - order = 'date desc', context=context) + order = 'date desc, id' + move_in_ids = move_obj.search(cr, uid, [('company_id','=', company_id), + ('qty_remaining', '>', 0), + ('state', '=', 'done'), + ('location_id.usage', '!=', 'internal'), + ('location_dest_id.usage', '=', 'internal'), + ('product_id', '=', product.id)], + order = order, context=context) tuples = [] qty_to_go = qty for move in move_obj.browse(cr, uid, move_in_ids, context=context): @@ -117,6 +120,8 @@ class product_product (osv.osv): else: tuples.append((move.id, qty_to_go, new_price, qty_from * qty_to_go / product_qty),) break + if tuples == [] and move_in_ids != []: + raise osv.except_osv(_('Error'), 'Not possible that there are no tuples when move ins') return tuples class stock_move(osv.osv):