odoo/addons/sale_mrp/test/cancellation_propagated.yml

97 lines
3.8 KiB
YAML

-
I first create a warehouse with pick-pack-ship and reception in 2 steps
-
!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 for this product
-
!record {model: mrp.bom, id: mrp_bom_test1}:
company_id: base.main_company
product_tmpl_id: product_manu_product_template
product_id: product_manu
product_uom_id: product.product_uom_unit
product_qty: 1.0
type: normal
bom_line_ids:
- product_id: product.consu_delivery_01
product_uom_id: product.product_uom_unit
product_qty: 1.0
-
And set routes on product to be MTO and manufacture
-
!python {model: product.product, id: product_manu}: |
route_warehouse0_manufacture_id = self.env['stock.warehouse'].browse(ref('stock.warehouse0')).manufacture_pull_id.route_id.id
route_warehouse0_mto_id = self.env['stock.warehouse'].browse(ref('stock.warehouse0')).mto_pull_id.route_id.id
self.write({'route_ids': [(6, 0, [route_warehouse0_mto_id, route_warehouse0_manufacture_id])]})
-
I create a sales order
-
!record {model: sale.order, id: sale_order_product_manu}:
partner_id: base.res_partner_3
note: Create Sales order
warehouse_id: wh_pps
pricelist_id: product.list0
order_line:
- product_id: product_manu
name: "product_manu"
product_uom_qty: 5.00
product_uom: product.product_uom_unit
-
Confirm sales order
-
!python {model: sale.order, id: sale_order_product_manu}: |
self.action_confirm()
-
I run scheduler.
-
!python {model: procurement.order, id: False}: |
self.run_scheduler()
-
Check the propagation when we cancel the main procurement
* Retrieve related procurements and check that there are all running
* Check that the purchase order has been well created
* Cancel the main procurement
* Check that all procurements related and the purchase order has been well cancelled
-
!python {model: procurement.order, id: False}: |
# Retrieve related procu
so = self.env['sale.order'].browse(ref('sale_order_product_manu'))
procus = self.search([('group_id.name', '=', so.name)])
assert len(procus.ids)>0, 'No procurements are found for sale order "%s" (with id : %d)' %(so.name, so.id)
# Check that all procurements are running
for procu in procus:
assert procu.state == u'running', 'Procurement with id %d should be "running" but is with a state : %s!' %(procu.id, procu.state)
# Check that one production order exist
prodor_ids = [proc.production_id for proc in procus if proc.production_id]
assert len(prodor_ids) > 0, 'No production order found !'
# Cancel the main procurement
main_procu = self.search([('origin', '=', so.name)])
assert len(main_procu.ids) == 1, 'Main procurement not identified !'
main_procu.cancel()
assert main_procu[0].state == u'cancel', 'Main procurement should be cancelled !'
# Check that all procurements related are cancelled
for procu in procus:
assert procu.state == u'cancel', 'Procurement with id %d should be with the state "cancel" but is with a state : %s!' %(procu.id, procu.state)
# Check that the production order is cancelled
for prodor in self.env['mrp.production'].browse([prodor.id for prodor in prodor_ids]):
assert prodor.state == u'cancel', 'Production order %d should be cancelled but is in state : %s!' %(prodor.id, prodor.state)