4
!record {model: sale.order, id: so_D}:
5
company_id: base.main_company
6
date_order: '2011-04-13'
7
invoice_quantity: order
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_D1}:
22
product_uom: product.product_uom_unit
27
date_planned: '2011-04-13'
30
!record {model: sale.order.line, id: sol_D2}:
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_D"), '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_D1")], ['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
# get the corresponding procurement order
74
data = sol_obj.read(cr, uid, [ref("sol_D1")], ['procurement_id'], context=context)[0]
75
proc_id = data['procurement_id'][0]
76
data = proc_obj.read(cr, uid, [proc_id], ['purchase_id', 'state', 'note'], context=context)[0]
77
po_id = data['purchase_id'][0]
79
in_ids = self.search(cr, uid, [('purchase_id', '=', po_id)], context=context)
80
pick = self.browse(cr, uid, in_ids[0], context=context)
81
# get the weird openERP picking type
82
picking_type = self.pool.get('stock.partial.picking').get_picking_type(cr, uid, pick, context=context)
84
dic = self.action_process(cr, uid, in_ids, context=context)
85
wiz_model = dic['res_model']
86
wiz_id = dic['res_id']
87
wiz_c = dic['context']
88
# reduce qty and then split moves
89
wiz_obj = self.pool.get(wiz_model)
90
for obj in wiz_obj.browse(cr, uid, [wiz_id], context=wiz_c):
91
for out in getattr(obj, 'product_moves_%s'%picking_type): # -> because is now IN with average product cost method !!!
92
# call the split wizard
93
dic_split = out.split(context=wiz_c)
94
split_model = dic_split['res_model']
95
split_ids = [dic_split['res_id']]
96
split_c = dic_split['context']
97
split_obj = self.pool.get(split_model)
98
# depending on the product, we put different quantity in the new move
99
if out.product_id.id == ref("product_A"):
101
out.write({'quantity_ordered': 7}, context=wiz_c)
102
split_obj.write(cr, uid, split_ids, {'quantity': 5}, context=split_c)
103
if out.product_id.id == ref("product_B"):
105
out.write({'quantity_ordered': 2}, context=wiz_c)
106
split_obj.write(cr, uid, split_ids, {'quantity': 1}, context=split_c)
107
# we perform the split
108
split_obj.split(cr, uid, split_ids, context=split_c)
109
wiz_obj.copy_all(cr,uid,[dic['res_id']], context=dic['context'])
110
wiz_obj.do_incoming_shipment(cr, uid, [dic['res_id']], context=dic['context'])
111
# openERP swap IN -> backorder
112
data = self.read(cr, uid, in_ids, ['backorder_id'], context=context)[0]
114
in_ids = [data['backorder_id'][0]]
115
# assert a backorder has been created
116
assert in_ids, 'backorder does not exist'
117
data = self.read(cr, uid, in_ids, ['state'], context=context)[0]
118
assert data['state'] == 'done', 'the incoming shipment is not Done - done - %s'%data['state']
119
# assert the backorder
120
data = self.read(cr, uid, back_ids, ['state'], context=context)[0]
121
assert data['state'] == 'assigned', 'the backorder is not assigned - assigned - %s'%data['state']
122
# check the moves in backorder
125
for obj in self.browse(cr, uid, back_ids, context=context):
126
for move in obj.move_lines:
127
if move.product_id.id == ref("product_A"):
128
a_qty.remove(move.product_qty)
129
if move.product_id.id == ref("product_B"):
130
b_qty.remove(move.product_qty)
131
# all qty must be empty
132
assert not a_qty, 'Quantity for product A is not empty - %s'%a_qty
133
assert not b_qty, 'Quantity for product B is not empty - %s'%b_qty
134
# check the moves in IN
137
for obj in self.browse(cr, uid, in_ids, context=context):
138
for move in obj.move_lines:
139
if move.product_id.id == ref("product_A"):
140
a_qty.remove(move.product_qty)
141
if move.product_id.id == ref("product_B"):
142
b_qty.remove(move.product_qty)
143
# all qty must be empty
144
assert not a_qty, 'Quantity for product A is not empty - %s'%a_qty
145
assert not b_qty, 'Quantity for product B is not empty - %s'%b_qty
146
# check the moves in OUT
147
a_qty = [5.0, 2.0, 3.0] # the missing qty is put on a new stock move after assignation
148
b_qty = [3.0, 1.0, 1.0] # same behavior, the missing 3 is placed in the new move
149
out_ids = self.search(cr, uid, [('sale_id', '=', ref("so_D"))], context=context)
150
# only one OUT for the sale order
151
assert len(out_ids) == 1, 'number of out objects is wrong - 1 - %s'%len(out_ids)
152
for obj in self.browse(cr, uid, out_ids, context=context):
153
for move in obj.move_lines:
154
if move.product_id.id == ref("product_A"):
155
a_qty.remove(move.product_qty)
156
if move.product_id.id == ref("product_B"):
157
b_qty.remove(move.product_qty)
158
# all qty must be empty
159
assert not a_qty, 'Quantity for product A is not empty - %s'%a_qty
160
assert not b_qty, 'Quantity for product B is not empty - %s'%b_qty