diff --git a/addons/sale_mrp/__openerp__.py b/addons/sale_mrp/__openerp__.py index bc9b84cd471..7f9c1c2dc56 100644 --- a/addons/sale_mrp/__openerp__.py +++ b/addons/sale_mrp/__openerp__.py @@ -40,7 +40,10 @@ from sales order. It adds sales name and sales Reference on production order. 'sale_mrp_view.xml', ], 'demo': [], - 'test':['test/sale_mrp.yml'], + 'test':[ + 'test/cancellation_propagated.yml', + 'test/sale_mrp.yml', + ], 'installable': True, 'auto_install': True, } diff --git a/addons/sale_mrp/test/cancellation_propagated.yml b/addons/sale_mrp/test/cancellation_propagated.yml new file mode 100644 index 00000000000..077fb552ec1 --- /dev/null +++ b/addons/sale_mrp/test/cancellation_propagated.yml @@ -0,0 +1,92 @@ +- + I first create a warehouse with pick-pack-ship and reception in 2 step +- + !record {model: stock.warehouse, id: wh_pps}: + name: WareHouse PickPackShip + code: whpps + reception_steps: 'two_steps' + delivery_steps: 'pick_pack_ship' + manufacture_to_resupply: True +- + Next I create a new product in this warehouse +- + !record {model: product.product, id: product_manu}: + name: "My MTO Product" + type: product + uom_id: product.product_uom_unit + uom_po_id: product.product_uom_unit +- + I create a bom (service and product) for this product +- + !record {model: mrp.bom, id: mrp_bom_test1}: + company_id: base.main_company + name: BOM In test + product_id: product_manu + product_qty: 1.0 + type: normal + bom_lines: + - company_id: base.main_company + name: GrapWorks Software + product_id: product.product_product_44 + product_qty: 1.0 +- + Set routes on product to be MTO +- + !python {model: product.product}: | + route_warehouse0_manufacture = self.pool.get('stock.warehouse').browse(cr, uid, ref('stock.warehouse0')).manufacture_pull_id.route_id.id + route_warehouse0_mto = self.pool.get('stock.warehouse').browse(cr, uid, ref('stock.warehouse0')).mto_pull_id.route_id.id + self.write(cr, uid, ref('product_manu'),{ 'route_ids': [(6,0,[route_warehouse0_mto,route_warehouse0_manufacture])]}, context=context) +- + Create a sales order with route_id manufacture. +- + !record {model: sale.order, id: sale_order_product_manu}: + partner_id: base.res_partner_3 + note: Create Sales order + warehouse_id: wh_pps + order_line: + - product_id: product_manu + product_uom_qty: 5.00 +- + !python {model: sale.order.line}: | + route_warehouse0_buy = self.pool.get('stock.warehouse').browse(cr, uid, ref('stock.warehouse0')).manufacture_pull_id.route_id.id + order = self.pool.get('sale.order').browse(cr, uid, ref('sale_order_product_manu')) + line_ids = [x.id for x in order.order_line] + self.write(cr, uid, line_ids, {'route_id': route_warehouse0_buy}) +- + Confirm sales order +- + !workflow {model: sale.order, action: order_confirm, ref: sale_order_product_manu} +- + Check the propagation when we cancel the main procurement + * Retrieve related procurements and check that there are all running + * Check that Purchase order is well created + * Cancel the main procurement + * Check that all procurements related and the purchase order are well cancelled +- + !python {model: procurement.order}: | + # Retrieve related procu + so = self.pool.get('sale.order').browse(cr, uid, ref('sale_order_product_manu')) + procu_ids = self.search(cr,uid,[('group_id.name','=',so.name)]) + assert len(procu_ids)>0, 'None procu found for so %s (%d)' %(so.name,so.id) + + # Check that all procurement are running + for procu in self.browse(cr,uid,procu_ids,context=context): + assert procu.state == u'running', 'Procu %d should be running and is in state : %s!' %(procu.id,procu.state) + + # Check that one or more Production Order + procor_ids = [proc.production_id for proc in self.browse(cr, uid, procu_ids) if proc.production_id] + assert len(procor_ids) > 0, 'No production Order found !' + + # Cancel the main procurement + main_procu_id = self.search(cr,uid,[('origin','=',so.name)]) + assert len(main_procu_id) == 1, 'Main procurement not identified !' + self.cancel(cr,uid,main_procu_id,context=context) + assert self.browse(cr,uid,main_procu_id[0]).state == u'cancel', 'Main procurement is not cancelled !!!' + + # Check that all procurements related is cancelled + for procu in self.browse(cr,uid,procu_ids,context=context): + assert procu.state == u'cancel', 'Procu %d should be cancelled and is in state : %s!' %(procu.id,procu.state) + + # Check that the production order is cancelled + for po in self.pool.get('mrp.production').browse(cr,uid,[prodor.id for prodor in procor_ids],context=context): + assert po.state == u'cancel', 'Production Order %d should be cancelled and is in state : %s!' %(prodor.id, procor.state) diff --git a/addons/sale_mrp/test/sale_mrp.yml b/addons/sale_mrp/test/sale_mrp.yml index 41015c47e58..b1e1e5c8750 100644 --- a/addons/sale_mrp/test/sale_mrp.yml +++ b/addons/sale_mrp/test/sale_mrp.yml @@ -107,7 +107,10 @@ sale_order_obj = self.pool.get('sale.order') so = sale_order_obj.browse(cr, uid, ref("sale_order_so0")) proc_ids = self.search(cr, uid, [('origin','like',so.name), ('state','=','running')]) - assert len(proc_ids) == 2, 'Not both procurements are in the running state!' + # Check that all procurement are running + for procu in self.browse(cr,uid,proc_ids,context=context): + print procu.name + assert procu.state == u'running', 'Procu %d should be running and is in state : %s!' %(procu.id,procu.state) - I verify that a manufacturing order has been generated, and that its name and reference are correct - diff --git a/addons/stock_complex_routes/__openerp__.py b/addons/stock_complex_routes/__openerp__.py index a3c7e3e5a35..739650f81c4 100644 --- a/addons/stock_complex_routes/__openerp__.py +++ b/addons/stock_complex_routes/__openerp__.py @@ -36,9 +36,10 @@ This adds a route on the sales order and sales order line (mini module) 'images': [], 'depends': ['purchase', 'sale_stock'], 'init_xml': [], - 'update_xml': ['stock_complex_routes.xml'], + 'data': ['stock_complex_routes.xml'], 'demo_xml': [], 'test': [ + 'test/cancellation_propagated.yml', 'test/crossdock.yml', 'test/dropship.yml', 'test/procurementexception.yml', diff --git a/addons/stock_complex_routes/test/cancellation_propagated.yml b/addons/stock_complex_routes/test/cancellation_propagated.yml new file mode 100644 index 00000000000..d5278a149bf --- /dev/null +++ b/addons/stock_complex_routes/test/cancellation_propagated.yml @@ -0,0 +1,85 @@ +- + I first create a warehouse with pick-pack-ship and reception in 2 step +- + !record {model: stock.warehouse, id: wh_pps}: + name: WareHouse PickPackShip + code: whpps + reception_steps: 'two_steps' + delivery_steps: 'pick_pack_ship' +- + Next I create a new product in this warehouse +- + !record {model: product.product, id: product_mto}: + name: "My MTO Product" + type: product + uom_id: product.product_uom_unit + uom_po_id: product.product_uom_unit + seller_ids: ##### define a bom + - delay: 1 + name: base.res_partner_2 + min_qty: 2.0 + qty: 10.0 +- + Set routes on product to be MTO +- + !python {model: product.product}: | + route_warehouse0_buy = self.pool.get('stock.warehouse').browse(cr, uid, ref('stock.warehouse0')).buy_pull_id.route_id.id + route_warehouse0_mto = self.pool.get('stock.warehouse').browse(cr, uid, ref('stock.warehouse0')).mto_pull_id.route_id.id + self.write(cr, uid, ref('product_mto'),{ 'route_ids': [(6,0,[route_warehouse0_mto,route_warehouse0_buy])]}, context=context ) ##### manufact au lieu de buy +- + Create a sales order with a line of 5 "My MTO Product", with route_id Buy. +- + !record {model: sale.order, id: sale_order_product_mto}: + partner_id: base.res_partner_3 + note: Create Sales order + warehouse_id: wh_pps + order_line: + - product_id: product_mto + product_uom_qty: 5.00 +- + !python {model: sale.order.line}: | + route_warehouse0_buy = self.pool.get('stock.warehouse').browse(cr, uid, ref('stock.warehouse0')).buy_pull_id.route_id.id + order = self.pool.get('sale.order').browse(cr, uid, ref('sale_order_product_mto')) + line_ids = [x.id for x in order.order_line] + self.write(cr, uid, line_ids, {'route_id': route_warehouse0_buy}) +- + Confirm sales order +- + !workflow {model: sale.order, action: order_confirm, ref: sale_order_product_mto} +- + Check the propagation when we cancel the main procurement + * Retrieve related procurements and check that there are all running + * Check that Purchase order is well created + * Cancel the main procurement + * Check that all procurements related and the purchase order are well cancelled +- + !python {model: procurement.order}: | + # Retrieve related procu + so = self.pool.get('sale.order').browse(cr, uid, ref('sale_order_product_mto')) + procu_ids = self.search(cr,uid,[('group_id.name','=',so.name)]) + assert len(procu_ids)>0, 'None procu found for so %s (%d)' %(so.name,so.id) + + # Check that all procurement are running + for procu in self.browse(cr,uid,procu_ids,context=context): + assert procu.state == u'running', 'Procu %d should be running and is in state : %s!' %(procu.id,procu.state) + + # Check that one or more PO ##### a mrp.prod + purchase_ids = [proc.purchase_line_id.order_id for proc in self.browse(cr, uid, procu_ids) if proc.purchase_line_id] + assert len(purchase_ids) > 0, 'No purchase order find !' + + # Cancel the main procurement + main_procu_id = self.search(cr,uid,[('origin','=',so.name)]) + assert len(main_procu_id) == 1, 'Main procurement not identified !' + self.cancel(cr,uid,main_procu_id,context=context) + assert self.browse(cr,uid,main_procu_id[0]).state == u'cancel', 'Main procurement is not cancelled !!!' + + # Check that all procurements related is cancelled + for procu in self.browse(cr,uid,procu_ids,context=context): + assert procu.state == u'cancel', 'Procu %d should be cancelled and is in state : %s!' %(procu.id,procu.state) + + # Check that the purchase order is cancelled ##### a mrp.prod + for po in self.pool.get('purchase.order').browse(cr,uid,[po.id for po in purchase_ids],context=context): + assert po.state == u'cancel', 'Purchase %d should be cancelled and is in state : %s!' %(po.id, po.state) + + +