2
In order to test the threshold rules feature, I will create
3
a threshold rule for each product defined in data.yml, run
4
the scheduler and check if a procurement order is created or
7
I create a threshold rule for product1/2/5/8/9/11
9
!record {model: threshold.value, id: threshold1}:
11
location_id: stock.stock_location_stock
12
compute_method: computed
13
consumption_method: amc
19
- product_id: product1
20
product_uom_id: product.product_uom_unit
21
- product_id: product2
22
product_uom_id: product.product_uom_unit
23
- product_id: product5
24
product_uom_id: product.product_uom_unit
25
- product_id: product8
26
product_uom_id: product.product_uom_unit
27
- product_id: product9
28
product_uom_id: product.product_uom_unit
29
- product_id: product11
30
product_uom_id: product.product_uom_unit
32
Update the period of consumption
34
!python {model: threshold.value}: |
36
from dateutil.relativedelta import relativedelta
37
self.write(cr, uid, [ref('threshold1')], {'consumption_period_from': (datetime.datetime.today() + relativedelta(day=1, months=-2)).strftime('%Y-%m-%d'),
38
'consumption_period_to': (datetime.datetime.today() + relativedelta(months=1, day=1, days=-1)).strftime('%Y-%m-%d')})
40
I create a threshold rule for product3/4/6/7
42
!record {model: threshold.value, id: threshold2}:
44
location_id: stock.stock_location_stock
47
- product_id: product3
48
product_uom_id: product.product_uom_unit
49
fixed_threshold_value: 250
50
fixed_product_qty: 500
51
- product_id: product4
52
product_uom_id: product.product_uom_unit
53
fixed_threshold_value: 250
55
- product_id: product6
56
product_uom_id: product.product_uom_unit
57
fixed_threshold_value: 250
58
fixed_product_qty: 150
59
- product_id: product7
60
product_uom_id: product.product_uom_unit
61
fixed_threshold_value: 250
62
fixed_product_qty: 150
66
!python {model: procurement.order}: |
67
self.run_threshold_value(cr, uid, False, context={})
69
I check if a procurement order was created
71
!python {model: procurement.order}: |
72
res_ids = self.search(cr, uid, [('name', '=', 'Threshold value: Threshold1'), ('product_id', '=', ref('product1'))], context=context)
73
assert res_ids, "No procurement created for product 1"
74
res = self.browse(cr, uid, res_ids[0], context=context)
75
assert res.product_qty == 175.00, "Bad quantity on procurement order for Product 1 (Expected 175.00 :: %s)" % res.product_qty
77
I check if a procurement order was created
79
!python {model: procurement.order}: |
80
res_ids = self.search(cr, uid, [('name', '=', 'Threshold value: Threshold1'), ('product_id', '=', ref('product2'))], context=context)
81
assert not res_ids, "Procurement created for product 2"
83
I check if a procurement order was created
85
!python {model: procurement.order}: |
86
res_ids = self.search(cr, uid, [('name', '=', 'Threshold value: Threshold2'), ('product_id', '=', ref('product3'))], context=context)
87
assert not res_ids, "Procurement created for product 3"
89
I check if a procurement order was created
91
!python {model: procurement.order}: |
92
res_ids = self.search(cr, uid, [('name', '=', 'Threshold value: Threshold2'), ('product_id', '=', ref('product4'))], context=context)
93
assert res_ids, "No procurement created for product 4"
94
res = self.browse(cr, uid, res_ids[0], context=context)
95
assert res.product_qty == 75.00, "Bad quantity on procurement order for Product 4 (Expected 75.00 :: %s)" % res.product_qty
97
I check if a procurement order was created
99
!python {model: procurement.order}: |
100
res_ids = self.search(cr, uid, [('name', '=', 'Threshold value: Threshold1'), ('product_id', '=', ref('product5'))], context=context)
101
assert res_ids, "No procurement created for product 5"
102
res = self.browse(cr, uid, res_ids[0], context=context)
103
assert res.product_qty == 175.00, "Bad quantity on procurement order for Product 5 (Expected 175.00 :: %s)" % res.product_qty
105
I check if a procurement order was created
107
!python {model: procurement.order}: |
108
res_ids = self.search(cr, uid, [('name', '=', 'Threshold value: Threshold2'), ('product_id', '=', ref('product6'))], context=context)
109
assert res_ids, "No procurement created for product 6"
110
res = self.browse(cr, uid, res_ids[0], context=context)
111
assert res.product_qty == 150.00, "Bad quantity on procurement order for Product 6 (Expected 150.00 :: %s)" % res.product_qty
113
I check if a procurement order was created
115
!python {model: procurement.order}: |
116
res_ids = self.search(cr, uid, [('name', '=', 'Threshold value: Threshold2'), ('product_id', '=', ref('product7'))], context=context)
117
assert not res_ids, "Procurement created for product 7"
119
I check if a procurement order was created
121
!python {model: procurement.order}: |
122
res_ids = self.search(cr, uid, [('name', '=', 'Threshold value: Threshold1'), ('product_id', '=', ref('product8'))], context=context)
123
assert res_ids, "No procurement created for product 8"
124
res = self.browse(cr, uid, res_ids[0], context=context)
125
assert res.product_qty == 175.00, "Bad quantity on procurement order for Product 8 (Expected 175.00 :: %s)" % res.product_qty
127
I check if a procurement order was created
129
!python {model: procurement.order}: |
130
res_ids = self.search(cr, uid, [('name', '=', 'Threshold value: Threshold1'), ('product_id', '=', ref('product9'))], context=context)
131
assert len(res_ids) == 1, "Too procurement created for threshold 9"
132
res = self.browse(cr, uid, res_ids[0], context=context)
133
assert res.product_id.id == ref('product9'), "No procurement created for product 9"
134
assert res.product_qty == 175.00, "Bad quantity on procurement order for Product 9 (Expected 175.00 :: %s)" % res.product_qty
136
I check if a procurement order was created
138
!python {model: procurement.order}: |
139
res_ids = self.search(cr, uid, [('name', '=', 'Threshold value: Threshold1'), ('product_id', '=', ref('product11'))], context=context)
140
assert len(res_ids) == 1, "Too procurement created for threshold 11"
141
res = self.browse(cr, uid, res_ids[0], context=context)
142
assert res.product_id.id == ref('product11'), "Bad product on procurement order for Threshold 11"
143
assert res.product_qty == 175.00, "Bad quantity on procurement order for Product 11 (Expected 175.00 :: %s)" % res.product_qty
b'\\ No newline at end of file'