2
In order to test the grouped by supplier and requestor feature,
3
we will create 3 customers, 2 suppliers and 5 products (with stock or not
4
and mini stock rules or not)
8
Create the first customer
10
!record {model: res.partner, id: gr_cust1}:
18
Create an address for this first customer
20
!record {model: res.partner.address, id: gr_ad_cust1}:
24
Create a second customer
26
!record {model: res.partner, id: gr_cust2}:
34
Create an address for this second customer
36
!record {model: res.partner.address, id: gr_ad_cust2}:
40
Create a second customer
42
!record {model: res.partner, id: gr_cust3}:
50
Create an address for this third customer
52
!record {model: res.partner.address, id: gr_ad_cust3}:
58
Create the first supplier
60
!record {model: res.partner, id: gr_supplier1}:
67
po_by_project: project
69
Create an address for this first supplier
71
!record {model: res.partner.address, id: gr_ad_supplier1}:
73
partner_id: gr_supplier1
75
Create the second supplier
77
!record {model: res.partner, id: gr_supplier2}:
86
Create an address for this second supplier
88
!record {model: res.partner.address, id: gr_ad_supplier2}:
90
partner_id: gr_supplier2
96
!record {model: product.template, id: gr_template1}:
97
categ_id: product.cat0
101
procure_method: make_to_order
102
standard_price: 160.0
105
uom_id: product.product_uom_unit
106
uom_po_id: product.product_uom_unit
108
Creating a product.product record
110
!record {model: product.product, id: gr_product1}:
113
valuation: manual_periodic
118
product_tmpl_id: gr_template1
119
international_status: itc
121
Creating a product.supplierinfo record
123
!record {model: product.supplierinfo, id: gr_si_product1}:
127
product_id: gr_template1
129
Creation of Product 2
131
!record {model: product.template, id: gr_template2}:
132
categ_id: product.cat0
133
cost_method: standard
136
procure_method: make_to_order
137
standard_price: 160.0
140
uom_id: product.product_uom_unit
141
uom_po_id: product.product_uom_unit
143
Creating a product.product record
145
!record {model: product.product, id: gr_product2}:
148
valuation: manual_periodic
153
product_tmpl_id: gr_template2
154
international_status: itc
156
Creating a product.supplierinfo record
158
!record {model: product.supplierinfo, id: gr_si_product2}:
162
product_id: gr_template2
164
Creation of Product 3
166
!record {model: product.template, id: gr_template3}:
167
categ_id: product.cat0
168
cost_method: standard
171
procure_method: make_to_order
172
standard_price: 160.0
175
uom_id: product.product_uom_unit
176
uom_po_id: product.product_uom_unit
178
Creating a product.product record
180
!record {model: product.product, id: gr_product3}:
183
valuation: manual_periodic
188
product_tmpl_id: gr_template3
189
international_status: itc
191
Creating a product.supplierinfo record
193
!record {model: product.supplierinfo, id: gr_si_product3}:
197
product_id: gr_template3
199
Creation of Product 4
201
!record {model: product.template, id: gr_template4}:
202
categ_id: product.cat0
203
cost_method: standard
206
procure_method: make_to_stock
207
standard_price: 160.0
210
uom_id: product.product_uom_unit
211
uom_po_id: product.product_uom_unit
213
Creating a product.product record
215
!record {model: product.product, id: gr_product4}:
218
valuation: manual_periodic
223
product_tmpl_id: gr_template4
224
international_status: itc
226
Creating a product.supplierinfo record
228
!record {model: product.supplierinfo, id: gr_si_product4}:
232
product_id: gr_template4
234
Creation of Product 5
236
!record {model: product.template, id: gr_template5}:
237
categ_id: product.cat0
238
cost_method: standard
241
procure_method: make_to_stock
242
standard_price: 160.0
245
uom_id: product.product_uom_unit
246
uom_po_id: product.product_uom_unit
248
Creating a product.product record
250
!record {model: product.product, id: gr_product5}:
253
valuation: manual_periodic
258
product_tmpl_id: gr_template5
259
international_status: itc
261
Creating a product.supplierinfo record
263
!record {model: product.supplierinfo, id: gr_si_product5}:
267
product_id: gr_template5
269
Creation of an inventory for 100 P5 and 5 P4
271
!record {model: stock.inventory, id: gr_inventory1}:
273
date: !eval time.strftime('%Y-%m-%d')
275
- location_id: stock.stock_location_stock
276
product_uom: product.product_uom_unit
277
product_id: gr_product5
279
- location_id: stock.stock_location_stock
280
product_uom: product.product_uom_unit
281
product_id: gr_product4
284
Validate the inventory
286
!python {model: stock.inventory}: |
287
self.action_confirm(cr, uid, [ref('gr_inventory1')], context=context)
288
self.action_done(cr, uid, [ref('gr_inventory1')], context=context)
290
Creation of a mini stock rules for P4
292
!record {model: stock.warehouse.orderpoint, id: gr_orderpoint_4}:
294
warehouse_id: stock.warehouse0
295
product_id: gr_product4
296
product_uom: product.product_uom_unit
297
location_id: stock.stock_location_stock
303
Creation of sales orders
305
Create the first sale order
307
!record {model: sale.order, id: gr_so1}:
308
company_id: base.main_company
309
date_order: !eval time.strftime('%Y-%m-%d')
310
invoice_quantity: order
313
partner_invoice_id: gr_ad_cust1
314
partner_order_id: gr_ad_cust1
315
partner_shipping_id: gr_ad_cust1
316
picking_policy: direct
317
pricelist_id: product.list0
322
Create a Sale Order Line
324
!record {model: sale.order.line, id: gr_so1_l1}:
325
product_uom: product.product_uom_unit
326
product_id: gr_product1
330
date_planned: !eval time.strftime('%Y-%m-%d')
333
Create a Sale Order Line
335
!record {model: sale.order.line, id: gr_so1_l2}:
336
product_uom: product.product_uom_unit
337
product_id: gr_product2
341
date_planned: !eval time.strftime('%Y-%m-%d')
344
Create a Sale Order Line
346
!record {model: sale.order.line, id: gr_so1_l3}:
347
product_uom: product.product_uom_unit
348
product_id: gr_product3
352
date_planned: !eval time.strftime('%Y-%m-%d')
355
Create the second sale order
357
!record {model: sale.order, id: gr_so2}:
358
company_id: base.main_company
359
date_order: !eval time.strftime('%Y-%m-%d')
360
invoice_quantity: order
363
partner_invoice_id: gr_ad_cust2
364
partner_order_id: gr_ad_cust2
365
partner_shipping_id: gr_ad_cust2
366
picking_policy: direct
367
pricelist_id: product.list0
372
Create a Sale Order Line
374
!record {model: sale.order.line, id: gr_so2_l1}:
375
product_uom: product.product_uom_unit
376
product_id: gr_product1
380
date_planned: !eval time.strftime('%Y-%m-%d')
383
Create a Sale Order Line
385
!record {model: sale.order.line, id: gr_so2_l2}:
386
product_uom: product.product_uom_unit
387
product_id: gr_product2
391
date_planned: !eval time.strftime('%Y-%m-%d')
394
Create a Sale Order Line
396
!record {model: sale.order.line, id: gr_so2_l3}:
397
product_uom: product.product_uom_unit
398
product_id: gr_product3
402
date_planned: !eval time.strftime('%Y-%m-%d')
405
Create a Sale Order Line
407
!record {model: sale.order.line, id: gr_so2_l4}:
408
product_uom: product.product_uom_unit
409
product_id: gr_product4
413
date_planned: !eval time.strftime('%Y-%m-%d')
416
Create a Sale Order Line
418
!record {model: sale.order.line, id: gr_so2_l5}:
419
product_uom: product.product_uom_unit
420
product_id: gr_product5
424
date_planned: !eval time.strftime('%Y-%m-%d')
427
Create the third sale order
429
!record {model: sale.order, id: gr_so3}:
430
company_id: base.main_company
431
date_order: !eval time.strftime('%Y-%m-%d')
432
invoice_quantity: order
435
partner_invoice_id: gr_ad_cust3
436
partner_order_id: gr_ad_cust3
437
partner_shipping_id: gr_ad_cust3
438
picking_policy: direct
439
pricelist_id: product.list0
444
Create a Sale Order Line
446
!record {model: sale.order.line, id: gr_so3_l1}:
447
product_uom: product.product_uom_unit
448
product_id: gr_product1
452
date_planned: !eval time.strftime('%Y-%m-%d')
455
Create a Sale Order Line
457
!record {model: sale.order.line, id: gr_so3_l2}:
458
product_uom: product.product_uom_unit
459
product_id: gr_product2
463
date_planned: !eval time.strftime('%Y-%m-%d')
466
Create a Sale Order Line
468
!record {model: sale.order.line, id: gr_so3_l3}:
469
product_uom: product.product_uom_unit
470
product_id: gr_product3
474
date_planned: !eval time.strftime('%Y-%m-%d')
477
Create a Sale Order Line
479
!record {model: sale.order.line, id: gr_so3_l4}:
480
product_uom: product.product_uom_unit
481
product_id: gr_product4
485
date_planned: !eval time.strftime('%Y-%m-%d')
488
Create a Purchase Order for gr_supplier1
490
!record {model: purchase.order, id: po_gr_sp1}:
491
partner_id: gr_supplier1
493
company_id: base.main_company
494
date_order: !eval time.strftime('%Y-%m-%d')
495
invoice_method: order
496
location_id: stock.stock_location_stock
497
partner_address_id: gr_ad_supplier1
498
pricelist_id: purchase.list0
499
customer_id: gr_cust1
501
Update the delivery requested date of the PO
503
!python {model: purchase.order}: |
505
from dateutil.relativedelta import relativedelta
506
req_date = (datetime.datetime.today() + relativedelta(days=1)).strftime('%Y-%m-%d 00:00:00')
507
self.write(cr, uid, [ref('po_gr_sp1')], {'delivery_requested_date': req_date})
509
I validate the sale order
511
!python {model: sale.order}: |
513
wf_service = netsvc.LocalService("workflow")
514
wf_service.trg_validate(uid, 'sale.order', ref("gr_so1"), 'order_validated', cr)
515
wf_service.trg_validate(uid, 'sale.order', ref("gr_so2"), 'order_validated', cr)
516
wf_service.trg_validate(uid, 'sale.order', ref("gr_so3"), 'order_validated', cr)
517
wf_service.trg_validate(uid, 'sale.order', ref("gr_so1"), 'order_confirm', cr)
518
wf_service.trg_validate(uid, 'sale.order', ref("gr_so2"), 'order_confirm', cr)
519
wf_service.trg_validate(uid, 'sale.order', ref("gr_so3"), 'order_confirm', cr)
523
!python {model: procurement.order}: |
524
self.run_scheduler(cr, uid , context={'update_mode':'init'})
526
!python {model: purchase.order}: |
527
s1_po_ids = self.search(cr, uid, [('partner_id', '=', ref('gr_supplier1'))])
528
s2_po_ids = self.search(cr, uid, [('partner_id', '=', ref('gr_supplier2'))])
529
assert len(s1_po_ids) == 3, "Number of PO for Supplier 1 is not correct (expected : 3 :: result : %s)" % len(s1_po_ids)
530
assert len(s2_po_ids) == 1, "Number of PO for Supplier 2 is not correct (expected : 1 :: result : %s)" % len(s2_po_ids)