4
!record {model: sale.order, id: so_C}:
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_C1}:
22
product_uom: product.product_uom_unit
27
date_planned: '2011-04-13'
30
!record {model: sale.order.line, id: sol_C2}:
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_C"), '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_C1")], ['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_C1")], ['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']
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"):
100
split_obj.write(cr, uid, split_ids, {'quantity': 7}, context=split_c)
101
if out.product_id.id == ref("product_B"):
102
split_obj.write(cr, uid, split_ids, {'quantity': 1}, context=split_c)
103
# we perform the split
104
split_obj.split(cr, uid, split_ids, context=split_c)
106
wiz_obj.copy_all(cr,uid,[dic['res_id']], context=dic['context'])
107
wiz_obj.do_incoming_shipment(cr, uid, [dic['res_id']], context=dic['context'])
108
data = self.read(cr, uid, in_ids, ['state'], context=context)[0]
109
assert data['state'] == 'done', 'the incoming shipment is not Done - done - %s'%data['state']
110
# assert no backorder has been created
111
back_ids = self.search(cr, uid, [('backorder_id', 'in', in_ids)], context=context)
112
assert not back_ids, 'backorder exists, and should not because split was performed with an equal overall quantity'
113
# check the moves in IN
116
for obj in self.browse(cr, uid, in_ids, context=context):
117
for move in obj.move_lines:
118
if move.product_id.id == ref("product_A"):
119
a_qty.remove(move.product_qty)
120
if move.product_id.id == ref("product_B"):
121
b_qty.remove(move.product_qty)
122
# all qty must be empty
123
assert not a_qty, 'Quantity for product A is not empty - %s'%a_qty
124
assert not b_qty, 'Quantity for product B is not empty - %s'%b_qty
125
# check the moves in OUT
126
a_qty = [3.0, 7.0, 0.0, 0.0]
127
b_qty = [4.0, 1.0, 0.0, 0.0]
128
out_ids = self.search(cr, uid, [('sale_id', '=', ref("so_C"))], context=context)
129
# only one OUT for the sale order
130
assert len(out_ids) == 2, 'number of out objects is wrong - 2 - %s'%len(out_ids)
131
for obj in self.browse(cr, uid, out_ids, context=context):
132
for move in obj.move_lines:
133
if move.product_id.id == ref("product_A"):
134
a_qty.remove(move.product_qty)
135
if move.product_id.id == ref("product_B"):
136
b_qty.remove(move.product_qty)
137
# all qty must be empty
138
assert not a_qty, 'Quantity for product A is not empty - %s'%a_qty
139
assert not b_qty, 'Quantity for product B is not empty - %s'%b_qty