4
!record {model: sale.order, id: so_B}:
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_B1}:
22
product_uom: product.product_uom_unit
27
date_planned: '2011-04-13'
30
!record {model: sale.order.line, id: sol_B2}:
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_B"), '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_B1")], ['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_B1")], ['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)
83
dic = self.action_process(cr, uid, in_ids, context=context)
84
# reduce quantities - in out memory moves
85
wiz_obj = self.pool.get(dic['res_model'])
86
for obj in wiz_obj.browse(cr, uid, [dic['res_id']], context=context):
87
for out in getattr(obj, 'product_moves_%s'%picking_type): # -> because is now IN with average product cost method !!!
88
if out.product_id.id == ref("product_A"):
89
out.write({'quantity_ordered': 7})
90
if out.product_id.id == ref("product_B"):
91
out.write({'quantity_ordered': 1})
93
wiz_obj.copy_all(cr,uid,[dic['res_id']], context=dic['context'])
94
wiz_obj.do_incoming_shipment(cr, uid, [dic['res_id']], context=dic['context'])
97
# openERP swap IN -> backorder
98
data = self.read(cr, uid, in_ids, ['backorder_id'], context=context)[0]
99
new_in_ids = [data['backorder_id'][0]]
100
data = self.read(cr, uid, new_in_ids, ['state'], context=context)[0]
101
assert data['state'] == 'done', 'the incoming shipment is not done - done - %s'%data['state']
102
# assert the backorder
104
data = self.read(cr, uid, back_ids, ['state'], context=context)[0]
105
assert data['state'] == 'assigned', 'the backorder is not assigned - assigned - %s'%data['state']
107
for obj in self.browse(cr, uid, back_ids, context=context):
108
for move in obj.move_lines:
109
if move.product_id.id == ref("product_A"):
110
assert move.product_qty == 3, 'back order qty is wrong - 10-7=3 - %s'%move.product_qty
111
if move.product_id.id == ref("product_B"):
112
assert move.product_qty == 4, 'back order qty is wrong - 5-1=4 - %s'%move.product_qty