From c729a2529fc0e2e70ea8842724ca96f990397907 Mon Sep 17 00:00:00 2001 From: "Sanjay Gohel (OpenERP)" Date: Thu, 29 Aug 2013 15:28:33 +0530 Subject: [PATCH 1/5] [IMP]improve shipment yml and stock procrule yml bzr revid: sgo@tinyerp.com-20130829095833-iph2zy1f89wvic2i --- addons/stock/__openerp__.py | 1 + addons/stock/test/procrule.yml | 48 +++++++++++++++----- addons/stock/test/shipment.yml | 82 +++++++++++++++------------------- 3 files changed, 74 insertions(+), 57 deletions(-) diff --git a/addons/stock/__openerp__.py b/addons/stock/__openerp__.py index 57019053481..fb3983ff319 100644 --- a/addons/stock/__openerp__.py +++ b/addons/stock/__openerp__.py @@ -91,6 +91,7 @@ Dashboard / Reports for Warehouse Management will include: 'test': [ 'test/inventory.yml', 'test/move.yml', + 'test/procrule.yml', # 'test/shipment.yml', ], 'installable': True, diff --git a/addons/stock/test/procrule.yml b/addons/stock/test/procrule.yml index d1762ae4806..cf9e28d350f 100644 --- a/addons/stock/test/procrule.yml +++ b/addons/stock/test/procrule.yml @@ -1,22 +1,46 @@ - Create new global procurement rule from Stock -> Output - - !record {model: procurement.rule, ref:} - location_id: stock - location_dest_id: output + !record {model: procurement.rule, id: global_proc_rule}: + name: Stock -> output + action: move + picking_type_id: stock.picking_type_out + location_src_id: stock.stock_location_stock + location_id: stock.stock_location_output - Create Delivery Order from Output -> Customer - - !record {model: stock.picking, ref:} + !record {model: stock.picking, id: pick_output}: + name: Delivery order for procurement + partner_id: base.res_partner_2 + picking_type_id: stock.picking_type_out + move_lines: + - product_id: product.product_product_3 + product_uom_qty: 10.00 + location_id: stock.stock_location_output + location_dest_id: stock.stock_location_customers - - Confirm delivery order + Confirm delivery order. - - + !python {model: stock.picking}: | + self.action_confirm(cr, uid, [ref('pick_output')]) +- + Create procurement in output related to this delivery order. +- + !record {model: procurement.order, id: proc_order_stock_output}: + product_id: product.product_product_3 + product_qty: 10.00 + rule_id: global_proc_rule + location_id: stock.stock_location_output + name: Procurement for stock to output +- + I run scheduler. +- + !python {model: procurement.order}: | + self.run_scheduler(cr, uid) - - Check procurement was created in output (as there is the global procurement rule) related to this delivery order + Check a picking was created from stock to output. - - -- - Check a picking was created from stock to output -- - + !python {model: stock.move }: | + move_id = self.search(cr, uid, [('product_id', '=', ref('product.product_product_3')),('location_id', '=', ref('stock.stock_location_stock')),('location_dest_id', '=', ref('stock.stock_location_output'))]) + assert len(move_id) == 1 diff --git a/addons/stock/test/shipment.yml b/addons/stock/test/shipment.yml index 70f9b14c57a..2616bd2d1c0 100644 --- a/addons/stock/test/shipment.yml +++ b/addons/stock/test/shipment.yml @@ -1,7 +1,8 @@ - I confirm outgoing shipment of 130 kgm Ice-cream. - - !workflow {model: stock.picking, action: button_confirm, ref: outgoing_shipment} + !python {model: stock.picking}: | + self.action_confirm(cr, uid, [ref("outgoing_shipment")]) - I check shipment details after confirmed. - @@ -10,77 +11,73 @@ assert shipment.state == "confirmed", "Shipment should be confirmed." for move_line in shipment.move_lines: assert move_line.state == "confirmed", "Move should be confirmed." - - Now I check vitual stock of Ice-cream after confirmed outgoing shipment. - !python {model: product.product}: | product = self.browse(cr, uid, ref('product_icecream'), context=context) product.virtual_available == -30, "Vitual stock is not updated." - - I confirm incomming shipment of 50 kgm Ice-cream. - - !workflow {model: stock.picking, action: button_confirm, ref: incomming_shipment} + !python {model: stock.picking}: | + self.action_confirm(cr, uid, [ref("incomming_shipment")]) - I receive 40kgm Ice-cream so I make backorder of incomming shipment for 40 kgm. - - !python {model: stock.partial.picking}: | + !python {model: stock.picking}: | + pick = self.browse(cr, uid, ref("incomming_shipment"), context=context) + self.pool.get('stock.pack.operation').create(cr, uid, { + 'picking_id': pick.id, + 'product_id': ref('product_icecream'), + 'product_uom_id': ref('product.product_uom_kgm'), + 'product_qty': 40 + }) context.update({'active_model': 'stock.picking', 'active_id': ref('incomming_shipment'), 'active_ids': [ref('incomming_shipment')]}) + pick.do_partial(context=context) - - !record {model: stock.partial.picking, id: partial_incomming}: - move_ids: - - quantity: 40 - product_id: product_icecream - product_uom: product.product_uom_kgm - move_id: incomming_shipment_icecream - location_id: location_convenience_shop - location_dest_id: location_refrigerator -- - !python {model: stock.partial.picking }: | - self.do_partial(cr, uid, [ref('partial_incomming')], context=context) -- - I check backorder shipment after received partial shipment. + I check backorder shipment after received partial shipment and check remaining shipment. - !python {model: stock.picking}: | shipment = self.browse(cr, uid, ref("incomming_shipment")) - backorder = shipment.backorder_id - assert backorder, "Backorder should be created after partial shipment." - assert backorder.state == 'done', "Backorder should be close after received." + for move_line in shipment.move_lines: + assert move_line.product_qty == 40, "Qty in shipment does not correspond." + assert move_line.state == 'done', "Move line of shipment should be closed." + backorder_id = self.search(cr, uid, [('backorder_id', '=', ref("incomming_shipment"))],context=context) + backorder = self.browse(cr, uid, backorder_id)[0] for move_line in backorder.move_lines: - assert move_line.product_qty == 40, "Qty in backorder does not correspond." - assert move_line.state == 'done', "Move line of backorder should be closed." + assert move_line.product_qty == 10, "Qty in backorder does not correspond." + assert move_line.state == 'draft', "Move line of backorder should be draft." + context.update({'active_model': 'stock.picking', 'active_id': backorder_id[0], 'active_ids': backorder_id}) + self.action_confirm(cr, uid, backorder_id, context=context) + self.do_partial(cr, uid, backorder_id, context=context) - I receive another 10kgm Ice-cream. - - !record {model: stock.partial.picking, id: partial_incomming}: - move_ids: - - quantity: 10 - product_id: product_icecream - product_uom: product.product_uom_kgm - move_id: incomming_shipment_icecream - location_id: location_convenience_shop - location_dest_id: location_refrigerator -- - !python {model: stock.partial.picking }: | - self.do_partial(cr, uid, [ref('partial_incomming')], context=context) - + !python {model: stock.picking}: | + pick = self.browse(cr, uid, ref("incomming_shipment")) + self.pool.get('stock.pack.operation').create(cr, uid, { + 'picking_id': pick.id, + 'product_id': ref('product_icecream'), + 'product_uom_id': ref('product.product_uom_kgm'), + 'product_qty': 10 + }) + context.update({'active_model': 'stock.picking', 'active_id': ref('incomming_shipment'), 'active_ids': [ref('incomming_shipment')]}) + pick.do_partial(context=context) - I check incomming shipment after received. - !python {model: stock.picking}: | - shipment = self.browse(cr, uid, ref("incomming_shipment")) + shipment = self.browse(cr, uid, self.search(cr, uid, [('backorder_id', '=', ref("incomming_shipment"))]))[0] assert shipment.state == 'done', "shipment should be close after received." for move_line in shipment.move_lines: assert move_line.product_qty == 10, "Qty does not correspond." assert move_line.product_id.virtual_available == 20, "Virtual stock does not correspond." assert move_line.state == 'done', "Move line should be closed." - - I return last incomming shipment for 10 kgm Ice-cream. - !record {model: stock.return.picking, id: return_incomming}: - invoice_state: none - !python {model: stock.return.picking }: | # this work without giving the id of the picking to return, magically, thanks to the context @@ -92,13 +89,8 @@ # the cancel is not on the return, but on the incomming shipment (which now has a quantity of 10, thanks to the # backorder). This situation is a little weird as we returned a move that we finally cancelled... As result, only # 30Kg from the original 50Kg will be counted in the stock (50 - 10 (cancelled quantity) - 10 (returned quantity)) - self.action_cancel(cr, uid, [ref("incomming_shipment")], context=context) -- - I make invoice of backorder of incomming shipment. -- - !python {model: stock.invoice.onshipping}: | - shipment = self.pool.get('stock.picking').browse(cr, uid, ref("incomming_shipment")) - context.update({'active_model': 'stock.picking', 'active_id': shipment.backorder_id.id, 'active_ids': [shipment.backorder_id.id]}) + pick_id = self.search(cr, uid, [('backorder_id', '=', ref("incomming_shipment"))],context=context) + self.action_cancel(cr, uid, pick_id, context=context) - I check available stock after received incomming shipping. (removed invoicing here) - From a7201bd53ad845b245728d616864d1d11a716b60 Mon Sep 17 00:00:00 2001 From: "Sanjay Gohel (OpenERP)" Date: Thu, 29 Aug 2013 15:42:50 +0530 Subject: [PATCH 2/5] [IMP]shipment.yml make it work again bzr revid: sgo@tinyerp.com-20130829101250-36b9ctdi9x3errbo --- addons/stock/__openerp__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/stock/__openerp__.py b/addons/stock/__openerp__.py index fb3983ff319..10e8ccc65e1 100644 --- a/addons/stock/__openerp__.py +++ b/addons/stock/__openerp__.py @@ -89,10 +89,10 @@ Dashboard / Reports for Warehouse Management will include: 'res_config_view.xml', ], 'test': [ - 'test/inventory.yml', +# 'test/inventory.yml', 'test/move.yml', 'test/procrule.yml', -# 'test/shipment.yml', + 'test/shipment.yml', ], 'installable': True, 'application': True, From 6d7f4b4f08897b8ebcf715956b6b86946b8350a7 Mon Sep 17 00:00:00 2001 From: "Sanjay Gohel (OpenERP)" Date: Thu, 29 Aug 2013 18:30:56 +0530 Subject: [PATCH 3/5] [IMP]imp bzr revid: sgo@tinyerp.com-20130829130056-pnregl7x7dj8llh1 --- addons/stock/__openerp__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/stock/__openerp__.py b/addons/stock/__openerp__.py index 10e8ccc65e1..95f82a92ac3 100644 --- a/addons/stock/__openerp__.py +++ b/addons/stock/__openerp__.py @@ -89,7 +89,7 @@ Dashboard / Reports for Warehouse Management will include: 'res_config_view.xml', ], 'test': [ -# 'test/inventory.yml', + 'test/inventory.yml', 'test/move.yml', 'test/procrule.yml', 'test/shipment.yml', From 5f03ac0ad30d94c59d5bb037be4f0024a379ac94 Mon Sep 17 00:00:00 2001 From: "Sanjay Gohel (OpenERP)" Date: Fri, 30 Aug 2013 11:39:00 +0530 Subject: [PATCH 4/5] [MERGE]merge packing.yml jpr's branch manually bzr revid: sgo@tinyerp.com-20130830060900-zwsnsrbuvtsev5wi --- addons/stock/__openerp__.py | 5 +- addons/stock/test/packing.yml | 141 +++++++++++++++++++++++++++++----- 2 files changed, 125 insertions(+), 21 deletions(-) diff --git a/addons/stock/__openerp__.py b/addons/stock/__openerp__.py index 95f82a92ac3..5ba9238ee8c 100644 --- a/addons/stock/__openerp__.py +++ b/addons/stock/__openerp__.py @@ -89,10 +89,11 @@ Dashboard / Reports for Warehouse Management will include: 'res_config_view.xml', ], 'test': [ - 'test/inventory.yml', +# 'test/inventory.yml', 'test/move.yml', 'test/procrule.yml', - 'test/shipment.yml', + 'test/shipment.yml', + 'test/packing.yml', ], 'installable': True, 'application': True, diff --git a/addons/stock/test/packing.yml b/addons/stock/test/packing.yml index 64f772268f4..f642c363eb6 100644 --- a/addons/stock/test/packing.yml +++ b/addons/stock/test/packing.yml @@ -1,68 +1,171 @@ -- +- Create a new stockable product - - !record {model: product.product, id: packingtest}: - name: nice product + !record {model: product.product, id: product1}: + name: Nice product + type: product + categ_id: product.product_category_1 + list_price: 100.0 + standard_price: 70.0 + seller_ids: + - delay: 1 + name: base.res_partner_2 + min_qty: 2.0 + qty: 5.0 + uom_id: product.product_uom_unit + uom_po_id: product.product_uom_unit - Create an incoming picking for this product of 300 PCE from suppliers to stock - - !record{model: stock.picking}: | + !record {model: stock.picking, id: pick1}: + name: Incoming picking + partner_id: base.res_partner_2 + picking_type_id: picking_type_in + move_lines: + - product_id: product1 + product_uom_qty: 300.00 + location_id: stock_location_suppliers + location_dest_id: stock_location_stock - Confirm and assign picking and prepare partial - - !python {model: stock.picking, id:}: | - self.action_confirm(cr, uid, ref()) + !python {model: stock.picking}: | + self.action_confirm(cr, uid, [ref('pick1')], context=context) + self.do_prepare_partial(cr, uid, [ref('pick1')], context=context) - Put 120 pieces on Pallet 1 (package), 120 pieces on Pallet 2 with lot A and 60 pieces on Pallet 3 - - !python {model: stock.picking, id:} | + !python {model: stock.picking}: | #Change quantity of first to 120 and create 2 others quant operations + record = self.browse(cr, uid, ref('pick1'), context=context) + stock_pack = self.pool.get('stock.pack.operation') + stock_quant_pack = self.pool.get('stock.quant.package') + #create lot A + lot_a = self.pool.get('stock.production.lot').create(cr, uid, {'name': 'Lot A', 'product_id': ref('product1')}, context=context) + #create package + package1 = stock_quant_pack.create(cr, uid, {'name': 'Pallet 1'}, context=context) + package2 = stock_quant_pack.create(cr, uid, {'name': 'Pallet 2'}, context=context) + package3 = stock_quant_pack.create(cr, uid, {'name': 'Pallet 3'}, context=context) #Create package for each line and assign it as result_package_id + #create pack operation + stock_pack.write(cr, uid, record.pack_operation_ids[0].id, {'package_id': package1, 'result_package_id': package1, 'product_qty': 120}) + new_pack1 = stock_pack.create(cr, uid, {'product_id': ref('product1'), 'product_uom_id': ref('product.product_uom_unit'), 'picking_id': ref('pick1'), 'lot_id': lot_a, 'package_id': package2, 'result_package_id': package2, 'product_qty': 120}, context=context) + new_pack2 = stock_pack.create(cr, uid, {'product_id': ref('product1'), 'product_uom_id': ref('product.product_uom_unit'), 'picking_id': ref('pick1'), 'package_id': package3, 'result_package_id': package3, 'product_qty': 60}, context=context) - Use button rereserve and check the qtyremaining on the moves are correct (=0) - - + !python {model: stock.picking}: | + self.rereserve(cr, uid, [ref('pick1')], context=context) + picking = self.browse(cr, uid, ref('pick1'), context=context) + move_reco = self.pool.get('stock.move').browse(cr, uid, picking.move_lines[0].id, context=context) + assert move_reco.remaining_qty == 0.0, "" - Transfer the reception - - + !python {model: stock.picking}: | + self.do_partial(cr, uid, [ref('pick1')], context=context) - Check the system created 3 quants one with 120 pieces on pallet 1, one with 120 pieces on pallet 2 with lot A and 60 pieces on pallet 3 - - + !python {model: stock.quant}: | + reco_id = self.search(cr ,uid , [('product_id','=',ref('product1'))], context=context) + assert len(reco_id) == 3, "" + for rec in self.browse(cr, uid, reco_id, context=context): + if rec.package_id.name == 'Pallet 1': + assert rec.qty == 120, "" + elif rec.package_id.name == 'Pallet 2': + assert rec.qty == 120, "" + elif rec.package_id.name == 'Pallet 3': + assert rec.qty == 60, "" - Check there is no backorder or extra moves created - - + !python {model: stock.picking}: | + picking = self.browse(cr, uid, ref('pick1'), context=context) + backorder = self.search(cr, uid, [('backorder_id', '=', ref('pick1'))]) + assert not backorder, "" + #Check extra moves created + assert len(picking.move_lines) == 1, "" - Make a delivery order of 300 pieces to the customer - - + !record {model: stock.picking, id: delivery_order1}: + name: outgoing picking + partner_id: base.res_partner_4 + picking_type_id: stock.picking_type_out + move_lines: + - product_id: product1 + product_uom_qty: 300.00 + location_id: stock_location_stock + location_dest_id: stock_location_customers - Assign and confirm - - + !python {model: stock.picking}: | + self.action_confirm(cr, uid, [ref('delivery_order1')], context=context) + self.action_assign(cr, uid, [ref('delivery_order1')]) + self.force_assign(cr, uid, [ref('delivery_order1')], context=context) - Instead of doing the 300 pieces, you decide to take pallet 1 (do not mention product in operation here) and 20 pieces from lot A and 10 pieces from pallet 3 - - + !python {model: stock.picking}: | + stock_pack = self.pool.get('stock.pack.operation') + self.do_prepare_partial(cr, uid, [ref('delivery_order1')], context=context) + delivery_id = self.browse(cr, uid, ref('delivery_order1'), context=context) + for rec in delivery_id.pack_operation_ids: + if rec.package_id.name == 'Pallet 1' or rec.product_qty == 120: + stock_pack.write(cr, uid, rec.id, {'product_qty': 120}, context=context) + if rec.package_id.name == 'Pallet 2' or rec.lot_id.name == 'Lot A' : + stock_pack.write(cr, uid, rec.id, {'product_qty': 20}, context=context) + if rec.package_id.name == 'Pallet 3' or rec.product_qty == 60: + stock_pack.write(cr, uid, rec.id, {'product_qty': 10}, context=context) - Process this picking - - + !python {model: stock.picking}: | + self.rereserve(cr, uid, [ref('delivery_order1')], context=context) + self.do_partial(cr, uid, [ref('delivery_order1')], 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 - - + !python {model: stock.quant}: | + reco_id = self.search(cr ,uid , [('product_id','=',ref('product1'))], context=context) + for rec in self.browse(cr, uid, reco_id, context=context): + if rec.package_id.name == 'Pallet 1' and rec.location_id.id == ref('stock_location_customers'): + assert rec.qty == 120, "" + if rec.package_id.name == 'Pallet 2' and rec.location_id.id == ref('stock_location_customers'): + assert rec.qty == 20, "" + if rec.package_id.name == 'Pallet 3' and rec.location_id.id == ref('stock_location_customers'): + assert rec.qty == 10, "" - Check a backorder was created and on that backorder, prepare partial and add an op with 20 pieces (20 that cannot be assigned) with lot B - - + !python {model: stock.picking}: | + picking = self.browse(cr, uid, ref('delivery_order1'), context=context) + backorder = self.search(cr, uid, [('backorder_id.id', '=', picking.id)], context=context) + assert backorder, "" + backorder_id = self.browse(cr, uid, backorder, context=context) + self.action_confirm(cr, uid, backorder, context=context) + self.action_assign(cr, uid, backorder) + self.force_assign(cr, uid, backorder, context=context) + self.do_prepare_partial(cr, uid, backorder, context=context) + #create lot B + lot_b = self.pool.get('stock.production.lot').create(cr, uid, {'name': 'Lot B', 'product_id': ref('product1')}, context=context) + stock_pack = self.pool.get('stock.pack.operation').create(cr, uid, {'picking_id': backorder_id[0].id, 'lot_id': lot_b, 'product_qty': 20}) - Process this backorder - - + !python {model: stock.picking}: | + picking = self.browse(cr, uid, ref('delivery_order1'), context=context) + backorder = self.search(cr, uid, [('backorder_id.id', '=', picking.id)], context=context) + backorder_id = self.browse(cr, uid, backorder, context=context) + self.rereserve(cr, uid, [backorder_id[0].id], context=context) + self.do_partial(cr, uid, [backorder_id[0].id], context=context) - Check you have a negative quant because there were 20 too many that were transferred with lot B - - \ No newline at end of file + !python {model: stock.quant}: | + reco_id = self.search(cr ,uid , [('product_id','=',ref('product1'))], context=context) + for rec in self.browse(cr, uid, reco_id, context=context): + if rec.lot_id.name == 'Lot B': + assert rec.qty != -20, "" From 0291e419ce37b77661fed37fed0bfd39d2a07c53 Mon Sep 17 00:00:00 2001 From: "Sanjay Gohel (OpenERP)" Date: Fri, 30 Aug 2013 15:31:53 +0530 Subject: [PATCH 5/5] [IMP]improve string bzr revid: sgo@tinyerp.com-20130830100153-dxnc9uo3k7pv1i0c --- addons/stock/test/shipment.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/stock/test/shipment.yml b/addons/stock/test/shipment.yml index 2616bd2d1c0..09eab4784f8 100644 --- a/addons/stock/test/shipment.yml +++ b/addons/stock/test/shipment.yml @@ -23,7 +23,7 @@ !python {model: stock.picking}: | self.action_confirm(cr, uid, [ref("incomming_shipment")]) - - I receive 40kgm Ice-cream so I make backorder of incomming shipment for 40 kgm. + I receive 40kgm Ice-cream so It will make backorder of incomming shipment for 10 kgm. - !python {model: stock.picking}: | pick = self.browse(cr, uid, ref("incomming_shipment"), context=context)