4
!record {model: sale.order, id: so_J}:
5
company_id: base.main_company
6
date_order: '2011-04-13'
7
invoice_quantity: procurement
10
partner_invoice_id: address_A
11
partner_order_id: address_A
12
partner_shipping_id: address_A
13
picking_policy: direct
14
pricelist_id: product.list0
19
Create a Sale Order Line
21
!record {model: sale.order.line, id: sol_J1}:
22
product_uom: product.product_uom_unit
27
date_planned: '2011-04-13'
30
!record {model: sale.order.line, id: sol_J2}:
31
product_uom: product.product_uom_unit
36
date_planned: '2011-04-13'
39
I validate the sale order
41
!python {model: sale.order}: |
43
wf_service = netsvc.LocalService("workflow")
44
wf_service.trg_validate(uid, 'sale.order', ref("so_J"), 'order_confirm', cr)
48
!python {model: procurement.order}: |
49
self.run_scheduler(cr, uid)
51
Validate the purchase order
53
!python {model: purchase.order}: |
54
proc_obj = self.pool.get('procurement.order')
55
sol_obj = self.pool.get('sale.order.line')
56
# get the corresponding procurement order
57
data = sol_obj.read(cr, uid, [ref("sol_J1")], ['procurement_id'], context=context)[0]
58
proc_id = data['procurement_id'][0]
59
data = proc_obj.read(cr, uid, [proc_id], ['purchase_id', 'state', 'note'], context=context)[0]
60
po_id = data['purchase_id'][0]
61
# change Invoicing control to From Picking
62
self.write(cr, uid, [po_id], {'invoice_method':'picking'}, context=context)
64
wf_service = netsvc.LocalService("workflow")
65
wf_service.trg_validate(uid, 'purchase.order', po_id, 'purchase_confirm', cr)
66
wf_service.trg_validate(uid, 'purchase.order', po_id, 'purchase_approve', cr)
68
Process the incoming shipment - reduce both qty - a back order is created
70
!python {model: stock.picking}: |
71
proc_obj = self.pool.get('procurement.order')
72
sol_obj = self.pool.get('sale.order.line')
73
po_obj = self.pool.get('purchase.order')
74
# get the corresponding procurement order
75
data = sol_obj.read(cr, uid, [ref("sol_J1")], ['procurement_id'], context=context)[0]
76
proc_id = data['procurement_id'][0]
77
data = proc_obj.read(cr, uid, [proc_id], ['purchase_id', 'state', 'note'], context=context)[0]
78
po_id = data['purchase_id'][0]
80
in_ids = self.search(cr, uid, [('purchase_id', '=', po_id)], context=context)
81
# cancel the incoming shipment with out update - then check the out
82
dic = self.enter_reason(cr, uid, in_ids, context=dict(context, cancel_type='update_out'))
83
wiz_model = dic['res_model']
84
wiz_id = dic['res_id']
85
wiz_c = dic['context']
87
wiz_obj = self.pool.get(wiz_model)
88
for obj in wiz_obj.browse(cr, uid, [wiz_id], context=wiz_c):
89
wiz_obj.write(cr, uid, [obj.id], {'change_reason': 'test yml'}, context=context)
91
wiz_obj.do_cancel(cr, uid, [dic['res_id']], context=dic['context'])
92
data = self.read(cr, uid, in_ids, ['state', 'purchase_id'], context=context)[0]
93
assert data['state'] == 'cancel', 'the incoming shipment is not Canceled - cancel - %s'%data['state']
94
# check the corresponding purchase state - the state has been automaticly manually corrected because the cancelation of incoming is definitive (out updated)
95
# as the invoice control is From Picking, we do not wait for the invoice, the po state is therefore Done
96
data = po_obj.read(cr, uid, [data['purchase_id'][0]], ['state'], context=context)[0]
97
assert data['state'] == 'done', 'the corresponding po is not in Done state - done - %s'%data['state']
98
# check the moves in OUT - back order contained 10 A and 5 B, should have been decreased in OUT
101
out_ids = self.search(cr, uid, [('sale_id', '=', ref("so_J"))], context=context)
102
# only one OUT for the sale order
103
assert len(out_ids) == 1, 'number of out objects is wrong - 1 - %s'%len(out_ids)
104
for obj in self.browse(cr, uid, out_ids, context=context):
105
for move in obj.move_lines:
106
if move.product_id.id == ref("product_A"):
107
a_qty.remove(move.product_qty)
108
# the move should be canceled
109
assert move.state == 'cancel', 'the out move product A should be canceled - cancel - %s'%move.state
110
if move.product_id.id == ref("product_B"):
111
b_qty.remove(move.product_qty)
112
# the move should be canceled
113
assert move.state == 'cancel', 'the out move product B should be canceled - cancel - %s'%move.state
114
# check the sale order, it should be manually corrected
115
assert obj.sale_id.state == 'done', 'corresponding sale order state is wrong - done - %s'%obj.sale_id.state
116
# all qty must be empty
117
assert not a_qty, 'Quantity for product A is not empty - %s'%a_qty
118
assert not b_qty, 'Quantity for product B is not empty - %s'%b_qty