~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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
    
- 
  Creating a res.partner record
- 
  !record {model: res.partner, id: res_partner_0}:
    credit_limit: 0.0
    debit_limit: 0.0
    name: Partner0
    supplier: true
    customer_lt: 1
    procurement_lt: 2
    transport_0_lt: 3
    transport_0: 'air'
    
- 
  Creating a res.partner.address record
- 
  !record {model: res.partner.address, id: res_partner_address_0}:
    partner_id: res_partner_0
    street: A
    
- 
  Creating a res.partner record
- 
  !record {model: res.partner, id: res_partner_1}:
    credit_limit: 0.0
    debit_limit: 0.0
    name: Partner1
    supplier: true
    
    
- 
  Creating a res.partner.address record
- 
  !record {model: res.partner.address, id: res_partner_address_1}:
    partner_id: res_partner_1
    street: B
    
-
  I create product template .
-
  !record {model: product.template, id: product_template_p0}:
    categ_id: product.cat0
    cost_method: standard
    mes_type: fixed
    name: Product0 - tender test
    procure_method: make_to_order
    standard_price: 160.0
    supply_method: buy
    type: product
    uom_id: product.product_uom_unit
    uom_po_id: product.product_uom_unit
    
- 
  Creating a product.product record
- 
  !record {model: product.product, id: product_product_p0}:
    
    standard_price: 1.0
    valuation: manual_periodic
    volume: 0.0
    warranty: 0.0
    weight: 0.0
    weight_net: 0.0
    product_tmpl_id: product_template_p0
    
    
- 
  Creating a product.supplierinfo record
- 
  !record {model: product.supplierinfo, id: product_supplierinfo_0}:
    delay: 1
    min_qty: 0.0
    name: res_partner_0
    product_id: product_template_p0
    
    
- 
  Creating a product.supplierinfo record
- 
  !record {model: product.supplierinfo, id: product_supplierinfo_1}:
    delay: 1
    min_qty: 0.0
    name: res_partner_1
    product_id: product_template_p0
    sequence: 10
    
    
- 
  Creating a sale.order record
- 
  !record {model: sale.order, id: sale_order_tender_so0}:
    amount_tax: 0.0
    amount_total: 1.0
    amount_untaxed: 1.0
    company_id: base.main_company
    date_order: '2011-04-13'
    invoice_quantity: order
    order_policy: manual
    partner_id: res_partner_0
    partner_invoice_id: res_partner_address_0
    partner_order_id: res_partner_address_0
    partner_shipping_id: res_partner_address_0
    picking_policy: direct
    pricelist_id: product.list0
    shop_id: sale.shop
    priority: normal
    categ: medical
    
    
- 
  Creating a sale.order.line record
- 
  !record {model: sale.order.line, id: sale_order_line_tender_p0}:
    company_id: base.main_company
    delay: 7.0
    order_id: sale_order_tender_so0
    order_partner_id: res_partner_0
    price_unit: 1.0
    product_id: product_product_p0
    product_uom: product.product_uom_unit
    product_uom_qty: 1.0
    salesman_id: base.user_admin
    state: draft
    th_weight: 0.0
    type: make_to_stock
    
-

  I check the sourcing line

-
  !python {model: sale.order.line}: |
    sol = self.browse(cr, uid, ref("sale_order_line_tender_p0"))
    
    count = 0
    
    for sourcing in sol.sourcing_line_ids:
      count = count + 1
      assert sourcing.sale_order_id.id == ref("sale_order_tender_so0"), 'sourcing line, sale order id is wrong (%i, %i)'%(sourcing.sale_order_id, ref("sale_order_tender_so0"))
      assert int(sourcing.sale_order_line_id) == ref("sale_order_line_tender_p0"), 'sourcing line, sale order line id is wrong (%i, %i)'%(sourcing.sale_order_line_id, ref("sale_order_line_tender_p0"))
      assert sourcing.type == 'make_to_stock', 'sourcing type wrong'
      assert sourcing.state == 'draft', 'sourcing state wrong (draft, %s)'%sourcing.state
      assert sourcing.state == sourcing.sale_order_line_state, 'states wrong'
      assert not sourcing.supplier.id, 'make_to_stock: sourcing has a supplier !'
      
      sourcing.write({'type':'make_to_order', 'supplier':ref("res_partner_1"), 'po_cft':'cft',})
      
      assert int(sol.supplier) == ref("res_partner_1"), 'sol supplier is wrong after update of sourcing line (%i, %i)'%(sol.supplier, ref("product_supplierinfo_1"))
      assert sol.type == 'make_to_order', 'sol type is wrong after update of sourcing line (%s, %s)'%(sol.type, 'make_to_order')
      assert sol.po_cft == 'cft', 'po_cft is wrong after update of sourcing line (%s, %s)'%(sol.po_cft, 'cft')
      
    assert count == 1, 'number of sourcing line wrong (%i)'%(count)
-

  I trigger the workflow

-
  !python {model: sale.order.line}: |
    import netsvc
    wf_service = netsvc.LocalService("workflow")
    wf_service.trg_validate(uid, 'sale.order', ref("sale_order_tender_so0"), 'order_confirm', cr)
    

-

  I check the new procurement order

-
  !python {model: procurement.order}: |
    ids = self.search(cr, uid, [('name', '=', 'Product0 - tender test'),], context=context)
    assert len(ids) == 1, 'wrong number of procurement. %s-%s'%(len(ids), 1)
    
-

  I run the scheduler
  
-

  !function {model: procurement.order, name: run_scheduler}:
    - model: procurement.order
      search: "[]"

-

  I check a tender has been created with one corresponding line

-

  !python {model: tender}: |
    ids = self.search(cr, uid, [('sale_order_id', '=', ref("sale_order_tender_so0")),], context=context)
    
    assert len(ids) == 1, 'number of tender is wrong. %s-%s'%(len(ids), 1)
    
    # create suppliers. table: tender_supplier_rel
    cr.execute('insert into tender_supplier_rel (tender_id,supplier_id) values (%s,%s)', (ids[0], ref("res_partner_0")))
    # generate the po
    import netsvc
    wf_service = netsvc.LocalService("workflow")
    wf_service.trg_validate(uid, 'tender', ids[0], 'button_generate', cr)

-

  check the number of po

-

  !python {model: purchase.order}: |
    # as an order point has been generated with the same partner, we must specify the origin also as beeing not 'SCHEDULER'
    ids = self.search(cr, uid, [('partner_id', '=', ref("res_partner_0")), ('origin', '!=', 'SCHEDULER'),], context=context)
    assert len(ids) == 1, 'number of rfq is wrong. %s-%s'%(len(ids), 1)
    
    # update the price_unit of purchase order line
    tender_id = False
    for po in self.browse(cr, uid, ids):
      # update valid till date
      po.write({'valid_till': '2011-10-31',})
      for pol in po.order_line:
        pol.write({'price_unit':10024})
      tender_id = po.tender_id
      # trigger the workflow
      import netsvc
      wf_service = netsvc.LocalService("workflow")
      wf_service.trg_validate(uid, 'purchase.order', po.id, 'rfq_sent', cr)
      wf_service.trg_validate(uid, 'purchase.order', po.id, 'rfq_updated', cr)
    
    # simulate the compare rfq wizard
    wiz_obj = self.pool.get('wizard.compare.rfq')
    action_dic = wiz_obj.start_compare_rfq(cr, uid, ids, context=dict(context, active_ids=ids, tender_id=tender_id))
    wiz_id = action_dic['res_id']
    wiz = wiz_obj.browse(cr, uid, wiz_id)
    wiz_line = wiz.line_ids[0]
    # choose the supplier
    choose_dic = wiz_line.choose_supplier()
    choose_id = choose_dic['res_id']
    
    # choose supplier wizard
    choose_obj = self.pool.get('wizard.choose.supplier')
    choose_line = choose_obj.browse(cr, uid, choose_id).line_ids[0]
    choose_line.choose_supplier()
    
    # back to first wizard
    wiz.update_tender()
    
-

  verify price_unit in tender line and validate the tender

-

  !python {model: tender}: |
    ids = self.search(cr, uid, [('sale_order_id', '=', ref("sale_order_tender_so0")),], context=context)
    tender = self.browse(cr, uid, ids[0])
    assert tender.tender_line_ids[0].price_unit == 10024, 'price_unit has not been updated. %s-10024'%tender.tender_line_ids[0].price_unit
    po_id = self.create_po(cr, uid, tender.id, context=context)
    
    import netsvc
    wf_service = netsvc.LocalService("workflow")
    wf_service.trg_validate(uid, 'tender', tender.id, 'button_done', cr)
    
    # all rfqs must be rfq_done
    for rfq in tender.rfq_ids:
      assert rfq.state == 'done', 'the state of the rfq is not done : done - %s'%rfq.state
       
    # the final po must have state = 'confirmed'
    po_obj = self.pool.get('purchase.order')
    so_obj = self.pool.get('sale.order')
    so = so_obj.browse(cr, uid, ref("sale_order_tender_so0"))
    so_ids = po_obj.search(cr, uid, [])
    ids = po_obj.search(cr, uid, [('origin', '=', so.name + '/' + tender.name),('id', '=', po_id)])
    assert ids, 'The origin of the generated purchase order is not correct'
    po = po_obj.browse(cr, uid, ids[0])
    assert po.state in ('approved', 'confirmed',), 'the state of purchase order is wrong. %s-approved'%po.state # state depends on the installation or not of double validation module for purchase order