2013-10-25 13:50:51 +00:00
-
2014-07-16 09:58:22 +00:00
I first create a warehouse with pick-pack-ship and receipt in 2 steps
2013-10-25 13:50:51 +00:00
-
!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}:
2013-10-29 19:27:02 +00:00
name : "My Product"
2013-10-25 13:50:51 +00:00
type : product
uom_id : product.product_uom_unit
uom_po_id : product.product_uom_unit
2014-12-05 14:11:40 +00:00
seller_ids :
2013-10-25 13:50:51 +00:00
- delay : 1
name : base.res_partner_2
min_qty : 2.0
qty : 10.0
-
2014-12-05 14:11:40 +00:00
Set routes on product to be MTO and Buy
2013-10-25 13:50:51 +00:00
-
!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
2014-12-05 14:11:40 +00:00
self.write(cr, uid, ref('product_mto'), { 'route_ids': [(6, 0, [route_warehouse0_mto,route_warehouse0_buy])]}, context=context )
2013-10-25 13:50:51 +00:00
-
2014-12-05 14:11:40 +00:00
Create a sales order with a line of 5 Units "My Product".
2013-10-25 13:50:51 +00:00
-
!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
-
2013-10-29 19:27:02 +00:00
Confirm the sale order
2013-10-25 13:50:51 +00:00
-
!workflow {model: sale.order, action: order_confirm, ref: sale_order_product_mto}
2014-12-05 14:11:40 +00:00
-
Create another sales order with 2 Dozen of the same product
-
!record {model: sale.order, id: sale_order_product_mto2}:
partner_id : base.res_partner_4
note : Create Sales order
warehouse_id : wh_pps
order_line :
- product_id : product_mto
product_uom_qty : 2.00
product_uom : product.product_uom_dozen
-
Confirm the sale order
-
!workflow {model: sale.order, action: order_confirm, ref: sale_order_product_mto2}
2014-04-24 09:53:47 +00:00
-
I run scheduler.
-
!python {model: procurement.order}: |
self.run_scheduler(cr, uid)
2013-10-25 13:50:51 +00:00
-
Check the propagation when we cancel the main procurement
* Retrieve related procurements and check that there are all running
2013-10-29 19:27:02 +00:00
* Check that a purchase order is well created
2013-10-25 13:50:51 +00:00
* Cancel the main procurement
* Check that all procurements related and the purchase order are well cancelled
-
!python {model: procurement.order}: |
2013-10-29 19:27:02 +00:00
# Retrieve related procurement
2013-10-25 13:50:51 +00:00
so = self.pool.get('sale.order').browse(cr, uid, ref('sale_order_product_mto'))
2013-10-25 14:35:51 +00:00
procu_ids = self.search(cr, uid, [('group_id.name', '=', so.name)])
2013-10-29 19:27:02 +00:00
assert len(procu_ids)>0, 'No procurement found for sale order %s (with id : %d)' %(so.name,so.id)
2013-10-25 13:50:51 +00:00
2013-10-29 19:27:02 +00:00
# Check that all procurements are running
2013-10-25 13:50:51 +00:00
for procu in self.browse(cr,uid,procu_ids,context=context) :
2013-10-29 19:27:02 +00:00
assert procu.state == u'running', 'Procurement with id: %d should be running but is with state : %s!' %(procu.id, procu.state)
2013-10-25 13:50:51 +00:00
2014-12-05 14:11:40 +00:00
# Check that one purchase order has been created
2013-10-25 13:50:51 +00:00
purchase_ids = [proc.purchase_line_id.order_id for proc in self.browse(cr, uid, procu_ids) if proc.purchase_line_id]
2014-12-05 14:11:40 +00:00
assert len(purchase_ids) == 1, 'No purchase order found !'
# Check the total quantity on the purchase order which should be in Unit(s)
purchase_line = purchase_ids[0].order_line[0]
assert purchase_line.product_qty == 29.0, 'As we ordered 2 Dozen(s) and 5 Unit(s), total should be 29 Unit(s) and not %s' % (purchase_line.product_qty,)
# Let us cancel the procurement related to the 2nd sales order first and check that the 2 Dozen(s) are subtracted correctly
so2 = self.pool.get('sale.order').browse(cr, uid, ref('sale_order_product_mto2'))
self.cancel(cr, uid, [so2.order_line[0].procurement_ids[0].id], context=context)
assert so2.order_line[0].procurement_ids[0].state == u'cancel', 'Main procurement should be cancelled !'
assert purchase_line.product_qty == 5.0, 'As we ordered 2 Dozen(s) and 5 Unit(s) and cancelled the two Dozen, total should be 5 Unit(s) and not %s' % (purchase_line.product_qty,)
# Cancel the main procurement from the sale order in units
2013-10-25 14:35:51 +00:00
main_procu_id = self.search(cr, uid, [('origin', '=', so.name)])
2013-10-25 13:50:51 +00:00
assert len(main_procu_id) == 1, 'Main procurement not identified !'
2014-04-24 09:53:47 +00:00
self.cancel(cr, uid, main_procu_id, context=context)
2013-10-29 19:27:02 +00:00
assert self.browse(cr, uid, main_procu_id[0]).state == u'cancel', 'Main procurement should be cancelled !'
2013-10-25 13:50:51 +00:00
2013-10-29 19:27:02 +00:00
# Check that all procurements related are cancelled
2013-10-25 14:35:51 +00:00
for procu in self.browse(cr, uid, procu_ids, context=context) :
2013-10-29 19:27:02 +00:00
assert procu.state == u'cancel', 'Procurement %d should be cancelled but is with a state : %s!' %(procu.id, procu.state)
2013-10-25 13:50:51 +00:00
2014-12-05 14:11:40 +00:00
# Check that the purchase order is cancelled
2013-10-25 14:35:51 +00:00
for po in self.pool.get('purchase.order').browse(cr, uid, [po.id for po in purchase_ids], context=context) :
2013-10-29 19:27:02 +00:00
assert po.state == u'cancel', 'Purchase order %d should be cancelled but is in state : %s!' %(po.id, po.state)