[IMP]sale: Improve code for cancel_order.yml
[odoo/odoo.git] / addons / sale / test / process / cancel_order.yml
1 -
2   In order to test the cancel sale order.
3 -
4   I try to cancel sale order and It's order policy is Manual.
5 -
6   !python {model: sale.order}: |
7     try:
8       self.action_cancel(cr, uid, [ref("order4")])
9     except Exception,e:
10       pass
11 -
12   To cancel the sale order from Invoice Exception, I have to cancel the invoice of sale order.
13 -
14   !python {model: sale.order}: |
15     import netsvc
16     wf_service = netsvc.LocalService("workflow")
17     wf_service.trg_validate(uid, 'sale.order', ref('order3'), 'order_confirm', cr)
18
19     invoice_ids = [x.id for x in self.browse(cr, uid, ref("order3")).invoice_ids]
20     for invoice in invoice_ids:
21       wf_service.trg_validate(uid, 'account.invoice', invoice, 'invoice_cancel', cr)
22
23 #code introduced by revid: mtr@tinyerp.com-20110915060653-cbedeckll1ijre66 
24 #form 'lp:~openerp-dev/openobject-addons/trunk-sale_coverage-mtr' branch
25
26 -
27   I check order status in "Invoice Exception" and related invoice is in cancel state.
28 -
29   !python {model: sale.order}: |
30     order = self.browse(cr, uid, ref("order3"))
31     assert order.invoice_ids[0].state == "cancel","order's related invoice should be cancelled"
32     assert order.state == "invoice_except", "Order should be in Invoice Exception state after cancel Invoice"
33 -
34   Then I click on the Ignore Exception button.
35 -
36   !workflow {model: sale.order, action: invoice_corrected, ref: order3}
37 -
38   And then again I set the invoice to draft state.
39 -
40   !python {model: account.invoice}: |
41     sale_order_obj = self.pool.get('sale.order')
42     so = sale_order_obj.browse(cr, uid, ref("order3"))
43     invoice_id = self.search(cr, uid, [('origin','=',so.name),('state','=','cancel')])
44     self.action_cancel_draft(cr, uid, invoice_id, ({'active_model': 'ir.ui.menu','active_ids': [ref("sale.menu_sale_order")], 'type': 'out_invoice', 'active_id': ref("sale.menu_sale_order")},))
45 -
46   Now I creating a partial picking.
47 -
48   !python {model: sale.order}: |
49     import netsvc
50     order = self.browse(cr, uid, ref("order4"))
51     assert order.picking_ids, "Picking is not created for this sale order"
52     partial_pick = self.pool.get('stock.partial.picking')
53     stock = self.pool.get('stock.picking')
54     pick_ids = [x.id for x in self.browse(cr, uid, ref("order4")).picking_ids]
55     data = stock.force_assign(cr, uid, pick_ids)
56     if data == True:
57       context={'active_model': 'stock.picking','active_ids': pick_ids}      
58       partial_id = partial_pick.create(cr, uid, {},context)
59       partial = partial_pick.browse(cr,uid,partial_id)
60       line_id = partial.move_ids[0].id
61       partial_pick.write(cr, uid, partial_id, {'move_ids': [(1,line_id,{'update_cost': 0, 'product_id': ref('product.product_product_pc1'), 'product_uom': ref('product.product_uom_unit'), 'currency': False, 'prodlot_id': False, 'cost': False, 'location_dest_id': ref('stock.stock_location_customers'), 'location_id': ref('stock.stock_location_stock'), 'quantity': 5})]})
62       partial_pick.do_partial(cr, uid, [partial_id], context)
63 -
64   Now I cancel a partial picking.
65 -
66   !python {model: sale.order}: |
67     import netsvc
68     order = self.browse(cr, uid, ref("order4"))
69     assert len(order.picking_ids) >= 2,'After partial picking there must be two or more picking'
70     assert order.picking_ids[0].state == 'assigned',"Partial Picking should be in 'Ready to progress' state"
71     assert order.picking_ids[0].move_lines[0].product_qty == 10.0,"Partial Picking product quantity must be 10.0"
72     pick_ids = order.picking_ids
73     wf_service = netsvc.LocalService("workflow")
74     wf_service.trg_validate(uid, 'stock.picking', order.picking_ids[0].id, 'button_cancel', cr)
75 -
76   The scheduler runs.
77 -
78   !function {model: procurement.order, name: run_scheduler}:
79     - model: procurement.order
80       search: "[]"
81 -
82   Now I cancel a partial picking.
83 -
84   !python {model: sale.order}: |
85     import netsvc
86     order = self.browse(cr, uid, ref("order4"))
87     print order.state
88
89 #code introduced by revid: mtr@tinyerp.com-20110921101038-xf1l3whyblmjbdx9
90 #form 'lp:~openerp-dev/openobject-addons/trunk-sale_coverage-mtr' branch
91 -
92   Then I click on the "Recreate Packing" button on sale order
93 -
94   !workflow {model: sale.order, action: ship_recreate, ref: order4}
95 -
96   I verfiy that sale order state is now 'In Progress'.
97 -
98   !assert {model: sale.order, id: order4}:
99     - state == 'progress'
100 -
101   I verify that picking is generated for sale order.
102 -
103   !python {model: stock.picking}: |
104     order = self.browse(cr, uid, ref("order4"))
105     picking_id = self.search(cr, uid, [('sale_id','=',ref("order4"))])
106     assert picking_id,"Picking has not been generated"
107 -
108   Now I need to cancel the rekated picking of sale order.
109 -
110   !python {model: sale.order}: |
111     import netsvc
112     order = self.browse(cr, uid, ref("order4"))
113     picking_ids = [x.id for x in self.browse(cr, uid, ref("order4")).picking_ids]
114     wf_service = netsvc.LocalService("workflow")
115     for picking in picking_ids:
116       wf_service.trg_validate(uid, 'stock.picking', picking, 'button_cancel', cr)
117 -
118   Now I am able to cancel this sale order.
119 -
120   !python {model: sale.order}: |
121     self.action_cancel(cr, uid, [ref("order4")])
122 -
123   I check that sale order is cancelled.
124 -
125   !assert {model: sale.order, id: order4}:
126     - state == 'cancel'
127 -
128   Again set cancelled order to draft.
129 -
130   !python {model: sale.order}: |
131     self.action_cancel_draft(cr, uid, [ref("order4")])
132