From e49b9b1945a0e24533fadacda1c0adf652bc0787 Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Wed, 25 Sep 2013 15:34:42 +0200 Subject: [PATCH] [IMP] Add reconcile negative quants tests bzr revid: jco@openerp.com-20130925133442-n09cu9nwmipg2atf --- addons/stock/stock.py | 4 ++++ addons/stock/test/packingneg.yml | 40 ++++++++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 79f18e2558f..af0f09acc4b 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -353,6 +353,10 @@ class stock_quant(osv.osv): if quant.location_id.usage != 'internal': return False solving_quant = quant + dom = [('qty', '<', 0)] + dom += [('lot_id', '=', quant.lot_id and quant.lot_id.id or False)] + dom += [('owner_id', '=', quant.owner_id and quant.owner_id.id or False)] + dom += [('package_id', '=', quant.package_id and quant.package_id.id or False)] quants = self.quants_get(cr, uid, quant.location_id, quant.product_id, quant.qty, [('qty', '<', '0')], context=context) for quant_neg, qty in quants: if not quant_neg: diff --git a/addons/stock/test/packingneg.yml b/addons/stock/test/packingneg.yml index 500e580e90e..f0948557949 100644 --- a/addons/stock/test/packingneg.yml +++ b/addons/stock/test/packingneg.yml @@ -93,7 +93,7 @@ !python {model: stock.picking}: | self.do_partial(cr, uid, [ref('delivery_order_neg')], context=context) - - Check the quants that you have 120 pieces pallet 1 in customers, 100 pieces pallet 2 in stock and 20 with customers and 50 in stock, 10 in customers from pallet 3 + Check the quants that you have 120 pieces pallet 1 in customers, -20 pieces pallet 2 in stock and 120 and 20 with customers and 20/30 in stock, 10 in customers from pallet 3 - !python {model: stock.quant}: | reco_id = self.search(cr ,uid , [('product_id','=',ref('product_neg'))], context=context) @@ -110,4 +110,40 @@ elif not rec.package_id and not rec.lot_id and rec.location_id.id == ref('stock_location_customers'): assert rec.qty == 10, "Should have 10 pieces in customer location from pallet 3" else: - assert False, "Unrecognized quant" \ No newline at end of file + assert False, "Unrecognized quant" +- + Create a picking for reconciling the negative quant +- + !record {model: stock.picking, id: delivery_reconcile}: + name: reconciling_delivery + partner_id: base.res_partner_4 + picking_type_id: stock.picking_type_in + move_lines: + - product_id: product_neg + product_uom_qty: 20.0 + location_id: stock_location_suppliers + location_dest_id: stock_location_stock +- + Receive 20 products with lot neg in stock with a new incoming shipment that should be on pallet 2 +- + !python {model: stock.picking}: | + self.action_confirm(cr, uid, [ref("delivery_reconcile")]) + self.action_confirm(cr, uid, [ref("delivery_reconcile")]) + self.do_prepare_partial(cr, uid, [ref("delivery_reconcile")]) + pick = self.browse(cr, uid, ref("delivery_reconcile")) + ops_obj = self.pool.get("stock.pack.operation") + pack_obj = self.pool.get("stock.quant.package") + lot_ids = self.pool.get("stock.production.lot").search(cr, uid, [('product_id', '=', ref('product_neg')), ('name','=','Lot neg')]) + pack_ids = pack_obj.search(cr, uid, [('name', '=', 'Palneg 2')]) + ops_obj.write(cr, uid, [pick.pack_operation_ids[0].id], {'lot_id': lot_ids[0], 'result_package_id': pack_ids[0]}) + self.do_partial(cr, uid, [ref("delivery_reconcile")]) +- + Check the negative quant was reconciled and the 20 pieces of lot neg at customers have the incoming shipments in the history_ids +- + !python {model: stock.quant}: | + neg_quants = self.search(cr, uid, [('product_id','=', ref('product_neg')), ('qty', '<', 0)]) + assert len(neg_quants) == 0, "Negative quants should have been reconciled" + pick = self.pool.get('stock.picking').browse(cr, uid, ref('delivery_reconcile')) + customer_quant = self.search(cr, uid, [('product_id', '=', ref('product_neg')), ('location_id', '=', ref('stock_location_customers')), ('lot_id.name','=', 'Lot neg'), ('qty','=', 20)]) + assert pick.move_lines[0].id in [x.id for x in self.browse(cr, uid, customer_quant[0]).history_ids] + \ No newline at end of file