~unifield-team/unifield-wm/us-826

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
-
  Create a Sale Order
-
  !record {model: sale.order, id: so_C}:
    company_id: base.main_company
    date_order: '2011-04-13'
    invoice_quantity: order
    order_policy: manual
    partner_id: partner_A
    partner_invoice_id: address_A
    partner_order_id: address_A
    partner_shipping_id: address_A
    picking_policy: direct
    pricelist_id: product.list0
    shop_id: sale.shop
    priority: normal
    categ: medical
-
  Create a Sale Order Line
-
  !record {model: sale.order.line, id: sol_C1}:
    product_uom: product.product_uom_unit
    product_id: product_A
    order_id: so_C
    price_unit: 1
    product_uom_qty: 10
    date_planned: '2011-04-13'
    type: make_to_order
-
  !record {model: sale.order.line, id: sol_C2}:
    product_uom: product.product_uom_unit
    product_id: product_B
    order_id: so_C
    price_unit: 1
    product_uom_qty: 5
    date_planned: '2011-04-13'
    type: make_to_order
-
  I validate the sale order
-
  !python {model: sale.order}: |
    import netsvc
    wf_service = netsvc.LocalService("workflow")
    wf_service.trg_validate(uid, 'sale.order', ref("so_C"), 'order_confirm', cr)
-
  Run the scheduler
-
  !python {model: procurement.order}: |
    self.run_scheduler(cr, uid)
-
  Validate the purchase order
-
  !python {model: purchase.order}: |
    proc_obj = self.pool.get('procurement.order')
    sol_obj = self.pool.get('sale.order.line')
    # get the corresponding procurement order
    data = sol_obj.read(cr, uid, [ref("sol_C1")], ['procurement_id'], context=context)[0]
    proc_id = data['procurement_id'][0]
    data = proc_obj.read(cr, uid, [proc_id], ['purchase_id', 'state', 'note'], context=context)[0]
    po_id = data['purchase_id'][0]
    # change Invoicing control to From Picking
    self.write(cr, uid, [po_id], {'invoice_method':'picking'}, context=context)
    import netsvc
    wf_service = netsvc.LocalService("workflow")
    wf_service.trg_validate(uid, 'purchase.order', po_id, 'purchase_confirm', cr)
    wf_service.trg_validate(uid, 'purchase.order', po_id, 'purchase_approve', cr)
-
  Process the incoming shipment - reduce both qty - a back order is created
-
  !python {model: stock.picking}: |
    proc_obj = self.pool.get('procurement.order')
    sol_obj = self.pool.get('sale.order.line')
    # get the corresponding procurement order
    data = sol_obj.read(cr, uid, [ref("sol_C1")], ['procurement_id'], context=context)[0]
    proc_id = data['procurement_id'][0]
    data = proc_obj.read(cr, uid, [proc_id], ['purchase_id', 'state', 'note'], context=context)[0]
    po_id = data['purchase_id'][0]
    # find the IN
    in_ids = self.search(cr, uid, [('purchase_id', '=', po_id)], context=context)
    pick = self.browse(cr, uid, in_ids[0], context=context)
    # get the weird openERP picking type
    picking_type = self.pool.get('stock.partial.picking').get_picking_type(cr, uid, pick, context=context)
    # process wizard
    dic = self.action_process(cr, uid, in_ids, context=context)
    wiz_model = dic['res_model']
    wiz_id = dic['res_id']
    wiz_c = dic['context']
    # split moves
    wiz_obj = self.pool.get(wiz_model)
    for obj in wiz_obj.browse(cr, uid, [wiz_id], context=wiz_c):
      for out in getattr(obj, 'product_moves_%s'%picking_type): # -> because is now IN with average product cost method !!!
        # call the split wizard
        dic_split = out.split(context=wiz_c)
        split_model = dic_split['res_model']
        split_ids = [dic_split['res_id']]
        split_c = dic_split['context']
        split_obj = self.pool.get(split_model)
        # depending on the product, we put different quantity in the new move
        if out.product_id.id == ref("product_A"):
          split_obj.write(cr, uid, split_ids, {'quantity': 7}, context=split_c)
        if out.product_id.id == ref("product_B"):
          split_obj.write(cr, uid, split_ids, {'quantity': 1}, context=split_c)
        # we perform the split
        split_obj.split(cr, uid, split_ids, context=split_c)

    wiz_obj.copy_all(cr,uid,[dic['res_id']], context=dic['context'])
    wiz_obj.do_incoming_shipment(cr, uid, [dic['res_id']], context=dic['context'])
    data = self.read(cr, uid, in_ids, ['state'], context=context)[0]
    assert data['state'] == 'done', 'the incoming shipment is not Done - done - %s'%data['state']
    # assert no backorder has been created
    back_ids = self.search(cr, uid, [('backorder_id', 'in', in_ids)], context=context)
    assert not back_ids, 'backorder exists, and should not because split was performed with an equal overall quantity'
    # check the moves in IN
    a_qty = [3.0, 7.0]
    b_qty = [4.0, 1.0]
    for obj in self.browse(cr, uid, in_ids, context=context):
      for move in obj.move_lines:
        if move.product_id.id == ref("product_A"):
          a_qty.remove(move.product_qty)
        if move.product_id.id == ref("product_B"):
          b_qty.remove(move.product_qty)
    # all qty must be empty
    assert not a_qty, 'Quantity for product A is not empty - %s'%a_qty
    assert not b_qty, 'Quantity for product B is not empty - %s'%b_qty
    # check the moves in OUT
    a_qty = [3.0, 7.0]
    b_qty = [4.0, 1.0]
    out_ids = self.search(cr, uid, [('sale_id', '=', ref("so_C"))], context=context)
    # only one OUT for the sale order
    assert len(out_ids) == 1, 'number of out objects is wrong - 1 - %s'%len(out_ids)
    for obj in self.browse(cr, uid, out_ids, context=context):
      for move in obj.move_lines:
        if move.product_id.id == ref("product_A"):
          a_qty.remove(move.product_qty)
        if move.product_id.id == ref("product_B"):
          b_qty.remove(move.product_qty)
    # all qty must be empty
    assert not a_qty, 'Quantity for product A is not empty - %s'%a_qty
    assert not b_qty, 'Quantity for product B is not empty - %s'%b_qty