Merge lp:~openbig/bigconsulting/automatically_scanned_qanutity into lp:bigconsulting
- automatically_scanned_qanutity
- Merge into addons
Proposed by
gpa(OpenERP)
Status: | Merged |
---|---|
Merged at revision: | 76 |
Proposed branch: | lp:~openbig/bigconsulting/automatically_scanned_qanutity |
Merge into: | lp:bigconsulting |
Diff against target: |
446 lines (+233/-132) 4 files modified
packing_barcode_check/packing_barcode_check.py (+2/-2) packing_barcode_check/wizard/select_picking.py (+1/-0) stock_minimum_calculator/stock_minimum_calculator_wizard.xml (+1/-1) stock_minimum_calculator/wizard/stock_order_point_calculator.py (+229/-129) |
To merge this branch: | bzr merge lp:~openbig/bigconsulting/automatically_scanned_qanutity |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
openbig | Pending | ||
Review via email: mp+32764@code.launchpad.net |
Commit message
Description of the change
solved the problem of not increment bug/616645
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'packing_barcode_check/packing_barcode_check.py' | |||
2 | --- packing_barcode_check/packing_barcode_check.py 2010-08-11 12:37:21 +0000 | |||
3 | +++ packing_barcode_check/packing_barcode_check.py 2010-08-16 13:34:43 +0000 | |||
4 | @@ -31,8 +31,8 @@ | |||
5 | 31 | def _compute_quantity(self, cr, uid, ids, fieldnames, args, context=None): | 31 | def _compute_quantity(self, cr, uid, ids, fieldnames, args, context=None): |
6 | 32 | res = {} | 32 | res = {} |
7 | 33 | for obj in self.browse(cr, uid, ids, context=context): | 33 | for obj in self.browse(cr, uid, ids, context=context): |
10 | 34 | total_quantity = sum(move_id.product_qty for move_id in obj.move_lines) | 34 | total_quantity = sum(to_be_id.quantity for to_be_id in obj.tobe_scan_ids) |
11 | 35 | scanned_quantity = sum(scan.scan_quantity for scan in obj.scaned_ids) | 35 | scanned_quantity = sum(to_be_id.scan_quantity for to_be_id in obj.tobe_scan_ids) |
12 | 36 | res[obj.id] = { | 36 | res[obj.id] = { |
13 | 37 | 'total_quantity' : total_quantity, | 37 | 'total_quantity' : total_quantity, |
14 | 38 | 'scanned_quantity' : scanned_quantity, | 38 | 'scanned_quantity' : scanned_quantity, |
15 | 39 | 39 | ||
16 | === modified file 'packing_barcode_check/wizard/select_picking.py' | |||
17 | --- packing_barcode_check/wizard/select_picking.py 2010-08-11 13:15:42 +0000 | |||
18 | +++ packing_barcode_check/wizard/select_picking.py 2010-08-16 13:34:43 +0000 | |||
19 | @@ -47,6 +47,7 @@ | |||
20 | 47 | 'res_model': 'stock.picking', | 47 | 'res_model': 'stock.picking', |
21 | 48 | 'type': 'ir.actions.act_window', | 48 | 'type': 'ir.actions.act_window', |
22 | 49 | 'view_id':[resource_id], | 49 | 'view_id':[resource_id], |
23 | 50 | 'auto_refresh':1, | ||
24 | 50 | 'res_id':data['form']['picking_id'], | 51 | 'res_id':data['form']['picking_id'], |
25 | 51 | 'context':"{'contact_display':'partner'}", | 52 | 'context':"{'contact_display':'partner'}", |
26 | 52 | } | 53 | } |
27 | 53 | 54 | ||
28 | === modified file 'stock_minimum_calculator/stock_minimum_calculator_wizard.xml' | |||
29 | --- stock_minimum_calculator/stock_minimum_calculator_wizard.xml 2010-07-27 09:27:59 +0000 | |||
30 | +++ stock_minimum_calculator/stock_minimum_calculator_wizard.xml 2010-08-16 13:34:43 +0000 | |||
31 | @@ -9,7 +9,7 @@ | |||
32 | 9 | id="id_set_seasonal_trend"/> | 9 | id="id_set_seasonal_trend"/> |
33 | 10 | <wizard | 10 | <wizard |
34 | 11 | string="Order Point Cacluator" | 11 | string="Order Point Cacluator" |
36 | 12 | model="product.product" | 12 | model="res.partner" |
37 | 13 | name="orderpoint.calculator" | 13 | name="orderpoint.calculator" |
38 | 14 | menu="True" | 14 | menu="True" |
39 | 15 | id="id_order_point_cacluator"/> | 15 | id="id_order_point_cacluator"/> |
40 | 16 | 16 | ||
41 | === modified file 'stock_minimum_calculator/wizard/stock_order_point_calculator.py' | |||
42 | --- stock_minimum_calculator/wizard/stock_order_point_calculator.py 2010-08-04 13:12:02 +0000 | |||
43 | +++ stock_minimum_calculator/wizard/stock_order_point_calculator.py 2010-08-16 13:34:43 +0000 | |||
44 | @@ -34,13 +34,9 @@ | |||
45 | 34 | <field name="warehouse_id"/> | 34 | <field name="warehouse_id"/> |
46 | 35 | <field name="location_id"/> | 35 | <field name="location_id"/> |
47 | 36 | <field name="seasonal_id"/> | 36 | <field name="seasonal_id"/> |
48 | 37 | <field name="max_qty_factor"/> | ||
49 | 37 | <field name="delactive"/> | 38 | <field name="delactive"/> |
50 | 38 | <field name="method_qty_calculation" colspan="4"/> | 39 | <field name="method_qty_calculation" colspan="4"/> |
51 | 39 | <group attrs="{'invisible':[('method_qty_calculation','=','his_cons_without_product')]}" colspan="4"> | ||
52 | 40 | <separator string="Configuration of Base Consumptions Periods" colspan="4"/> | ||
53 | 41 | <field name="date_start"/> | ||
54 | 42 | <field name="date_stop"/> | ||
55 | 43 | </group> | ||
56 | 44 | </form>""" | 40 | </form>""" |
57 | 45 | 41 | ||
58 | 46 | orderpoint_calculator_fields = { | 42 | orderpoint_calculator_fields = { |
59 | @@ -70,24 +66,19 @@ | |||
60 | 70 | 'required': True, | 66 | 'required': True, |
61 | 71 | 'help':'Use this field as index. Reference index is Main Season with 1.00. If you want to change the orderpoint rules you are able to define new season with a seasonal index. This index should reference to 1.00. For example if you expect - 10% consumption for autumn season in comparition to main season enter 0.90.' | 67 | 'help':'Use this field as index. Reference index is Main Season with 1.00. If you want to change the orderpoint rules you are able to define new season with a seasonal index. This index should reference to 1.00. For example if you expect - 10% consumption for autumn season in comparition to main season enter 0.90.' |
62 | 72 | }, | 68 | }, |
73 | 73 | 69 | ||
74 | 74 | 'date_start': { | 70 | 'max_qty_factor': { |
75 | 75 | 'string':'From Date', | 71 | 'string':'Max. Qty. Factor', |
76 | 76 | 'type':'date' | 72 | 'type':'float', |
77 | 77 | }, | 73 | 'required': True |
68 | 78 | |||
69 | 79 | 'date_stop': { | ||
70 | 80 | 'string':'To Date', | ||
71 | 81 | 'type':'date', | ||
72 | 82 | 'default': lambda *a: time.strftime('%Y-%m-%d') | ||
78 | 83 | }, | 74 | }, |
79 | 84 | 75 | ||
80 | 85 | 'method_qty_calculation':{ | 76 | 'method_qty_calculation':{ |
81 | 86 | 'string':"Method Calculation", | 77 | 'string':"Method Calculation", |
82 | 87 | 'type':'selection', | 78 | 'type':'selection', |
84 | 88 | 'selection':[('his_cons_with_product', 'Calculate with historical consumptions of products'), | 79 | 'selection':[('his_cons_with_product', 'Calculate with planning values'), |
85 | 89 | ('his_cons_without_product', 'Calculate with Out historical consumptions of product'), | 80 | ('his_cons_without_product', 'Calculate with Out historical consumptions of product'), |
87 | 90 | ('hist_cons_and_open_sale', 'Calculate with historical consumptions of product and Open sales orders'), | 81 | ('hist_cons_and_open_sale', 'Calculate with historical values'), |
88 | 91 | ],'required': True, | 82 | ],'required': True, |
89 | 92 | 'default': lambda *a:'his_cons_with_product' | 83 | 'default': lambda *a:'his_cons_with_product' |
90 | 93 | }, | 84 | }, |
91 | @@ -116,16 +107,99 @@ | |||
92 | 116 | 107 | ||
93 | 117 | return {'warehouse_id': warehouse_id, 'location_id':location_id,'date_start':from_date,'seasonal_id':seasonal_id} | 108 | return {'warehouse_id': warehouse_id, 'location_id':location_id,'date_start':from_date,'seasonal_id':seasonal_id} |
94 | 118 | 109 | ||
95 | 110 | |||
96 | 111 | def _sale_consume_qty(self, cr, uid, product_id, from_date, to_date, state, context): | ||
97 | 112 | """calculation of consumption of product from_date to to_date , where state is done """ | ||
98 | 113 | |||
99 | 114 | pool = pooler.get_pool(cr.dbname) | ||
100 | 115 | |||
101 | 116 | sale_obj = pool.get('sale.order') | ||
102 | 117 | sale_line_obj = pool.get("sale.order.line") | ||
103 | 118 | consum_qty = 0.0 | ||
104 | 119 | sale_ids = sale_obj.search(cr,uid,[('date_order','>=',from_date),('date_order','<=',to_date), ('state','=',state)]) | ||
105 | 120 | if sale_ids: | ||
106 | 121 | for sid in sale_ids: | ||
107 | 122 | sale_line_id = sale_line_obj.search(cr,uid,[('order_id','=',sid),('product_id','=',product_id)]) | ||
108 | 123 | for line_id in sale_line_id: | ||
109 | 124 | sale_line_data= sale_line_obj.browse(cr, uid, line_id, context=context).product_uom_qty | ||
110 | 125 | consum_qty += sale_line_data | ||
111 | 126 | |||
112 | 127 | return consum_qty | ||
113 | 128 | |||
114 | 129 | def _sale_open_qty(self, cr, uid, product_id, state, context): | ||
115 | 130 | """Calculation of open sale orders""" | ||
116 | 131 | |||
117 | 132 | pool = pooler.get_pool(cr.dbname) | ||
118 | 133 | |||
119 | 134 | sale_obj = pool.get('sale.order') | ||
120 | 135 | sale_line_obj = pool.get("sale.order.line") | ||
121 | 136 | open_sale_qty = 0.0 | ||
122 | 137 | open_sale_ids = sale_obj.search(cr, uid, [('state','in',state)]) | ||
123 | 138 | if open_sale_ids: | ||
124 | 139 | for sale_id in open_sale_ids: | ||
125 | 140 | sale_open_line_ids = sale_line_obj.search(cr,uid,[('order_id','=',sale_id),('product_id','=',product_id)]) | ||
126 | 141 | for open_line_id in sale_open_line_ids: | ||
127 | 142 | sale_line_data= sale_line_obj.browse(cr,uid,open_line_id) | ||
128 | 143 | open_sale_qty += sale_line_data.product_uom_qty | ||
129 | 144 | |||
130 | 145 | return open_sale_qty | ||
131 | 146 | |||
132 | 147 | def _purchase_open_qty(self, cr, uid, product_id, state, context): | ||
133 | 148 | """ Calculation of open purchase orders """ | ||
134 | 149 | |||
135 | 150 | pool = pooler.get_pool(cr.dbname) | ||
136 | 151 | |||
137 | 152 | purchase_obj = pool.get('purchase.order') | ||
138 | 153 | purchase_order_line_obj = pool.get('purchase.order.line') | ||
139 | 154 | open_purchase_qty = 0.0 | ||
140 | 155 | open_purchase_ids = purchase_obj.search(cr,uid,[('state','=',state)]) | ||
141 | 156 | if open_purchase_ids: | ||
142 | 157 | for purchase_id in open_purchase_ids: | ||
143 | 158 | open_purchase_line_ids= purchase_order_line_obj.search(cr,uid,[('order_id','=',purchase_id),('product_id','=',product_id)]) | ||
144 | 159 | for open_pur_id in open_purchase_line_ids: | ||
145 | 160 | purchase_line_data = purchase_order_line_obj.browse(cr, uid, open_pur_id, context=context) | ||
146 | 161 | open_purchase_qty += purchase_line_data.product_qty | ||
147 | 162 | |||
148 | 163 | return open_purchase_qty | ||
149 | 164 | |||
150 | 165 | def _refund_qty(self, cr, uid, product_id, from_date, to_date, state, context): | ||
151 | 166 | """ Calculation of the refund quantities of the prduct from the refund invoice, between from_date, to_date""" | ||
152 | 167 | |||
153 | 168 | pool = pooler.get_pool(cr.dbname) | ||
154 | 169 | |||
155 | 170 | account_invoice_obj = pool.get('account.invoice') | ||
156 | 171 | account_invoice_line_obj = pool.get('account.invoice.line') | ||
157 | 172 | refund_qty = 0.0 | ||
158 | 173 | refund_invoice_ids = account_invoice_obj.search(cr,uid,[('type','in',state),('date_invoice','>=',from_date),('date_invoice','<=',to_date)]) | ||
159 | 174 | for refund_id in refund_invoice_ids: | ||
160 | 175 | invoie_line_ids = account_invoice_line_obj.search(cr,uid,[('invoice_id','=',refund_id),('product_id','=',product_id)]) | ||
161 | 176 | for invoice_line_id in invoie_line_ids: | ||
162 | 177 | inovice_line_data = account_invoice_line_obj.browse(cr, uid, invoice_line_id, context=context).quantity | ||
163 | 178 | refund_qty += inovice_line_data | ||
164 | 179 | |||
165 | 180 | return refund_qty | ||
166 | 181 | |||
167 | 182 | |||
168 | 183 | def _date_diff(self, cr, uid, product_id, from_date, to_date, context): | ||
169 | 184 | """ Date difference between from_date and to_date """ | ||
170 | 185 | |||
171 | 186 | first_date = time.mktime(time.strptime(from_date,'%Y-%m-%d %H:%M:%S')) | ||
172 | 187 | last_date = time.mktime(time.strptime(to_date,'%Y-%m-%d %H:%M:%S')) | ||
173 | 188 | diff_day = (last_date-first_date)/(3600*24) | ||
174 | 189 | return diff_day | ||
175 | 190 | |||
176 | 119 | def _do_calculate(self, cr, uid, data, context): | 191 | def _do_calculate(self, cr, uid, data, context): |
177 | 120 | pool = pooler.get_pool(cr.dbname) | 192 | pool = pooler.get_pool(cr.dbname) |
178 | 121 | 193 | ||
179 | 122 | purchase_obj = pool.get('purchase.order') | 194 | purchase_obj = pool.get('purchase.order') |
181 | 123 | sale_obj = pool.get('sale.order') | 195 | purchase_order_line_obj = pool.get('purchase.order.line') |
182 | 124 | product_obj = pool.get('product.product') | 196 | product_obj = pool.get('product.product') |
183 | 125 | supp_obj = pool.get('product.supplierinfo') | 197 | supp_obj = pool.get('product.supplierinfo') |
184 | 126 | supp_cost_opt_obj = pool.get('supplier.cost.opti.lead.time') | 198 | supp_cost_opt_obj = pool.get('supplier.cost.opti.lead.time') |
185 | 127 | min_rule_obj = pool.get('stock.warehouse.orderpoint') | 199 | min_rule_obj = pool.get('stock.warehouse.orderpoint') |
186 | 128 | seasonal_obj = pool.get('product.seasonal') | 200 | seasonal_obj = pool.get('product.seasonal') |
187 | 201 | stock_move_obj = pool.get('stock.move') | ||
188 | 202 | |||
189 | 129 | ##### Calculation of purchase lead time | 203 | ##### Calculation of purchase lead time |
190 | 130 | purchase_lead_time = 0.0 | 204 | purchase_lead_time = 0.0 |
191 | 131 | company = pool.get('res.users').browse(cr, uid, uid, context).company_id | 205 | company = pool.get('res.users').browse(cr, uid, uid, context).company_id |
192 | @@ -135,117 +209,143 @@ | |||
193 | 135 | seasonal_id = data['form']['seasonal_id'] | 209 | seasonal_id = data['form']['seasonal_id'] |
194 | 136 | seasonal_data = seasonal_obj.browse(cr, uid, seasonal_id) | 210 | seasonal_data = seasonal_obj.browse(cr, uid, seasonal_id) |
195 | 137 | seasonal_factor = seasonal_data.seasonal_factor | 211 | seasonal_factor = seasonal_data.seasonal_factor |
307 | 138 | 212 | ||
308 | 139 | ##### Calculation of supplier lead time | 213 | # max_qty_factor factor |
309 | 140 | 214 | max_qty_factor = data['form']['max_qty_factor'] | |
310 | 141 | for id in data['ids']: | 215 | |
311 | 142 | product_id = product_obj.browse(cr, uid, id, context) | 216 | # 1. Calculation of the date date start in one year later than current date |
312 | 143 | supplier_lead_time = 0.0 | 217 | from_date = (datetime.now() - relativedelta(months=12)).strftime('%Y-%m-%d %H:%M:%S') |
313 | 144 | if product_id: | 218 | to_date = datetime.now().strftime('%Y-%m-%d %H:%M:%S') |
314 | 145 | for supp in product_id.seller_ids: | 219 | |
315 | 146 | sup = supp_obj.browse(cr, uid, supp.id, context) | 220 | # 2.1 first find the all the product which fullfill the criteria of the 2.1 |
316 | 147 | supplier_lead_time = sup.delay | 221 | product_ids = product_obj.search(cr,uid,[('active','=',True),('type','=','product'), |
317 | 148 | 222 | ('procure_method','=','make_to_stock'), | |
318 | 149 | ###### Calculation of average_daily_consumption | 223 | ('supply_method','=','buy'), |
319 | 150 | date_start = data['form']['date_start'] | 224 | ('purchase_ok','=',True), |
320 | 151 | date_stop = data['form']['date_stop'] | 225 | ('state','not in',['end','obsolete']), |
321 | 152 | average_daily_consumption = 0.0 | 226 | ]) |
322 | 153 | sale_line_obj = pool.get("sale.order.line") | 227 | ####### get location ##### |
323 | 154 | consum_qty = 0.0 | 228 | location_id = data['form']['location_id'] |
324 | 155 | sale_ids = sale_obj.search(cr,uid,[('date_order','>=',date_start),('date_order','<=',date_stop)]) | 229 | ########### |
325 | 156 | if sale_ids: | 230 | |
326 | 157 | for sid in sale_ids: | 231 | #2. Second point find the products for the perticular suppliers |
327 | 158 | sale_line_id = sale_line_obj.search(cr,uid,[('order_id','=',sid),('product_id','=',product_id.id)]) | 232 | for partner_id in data['ids']: |
328 | 159 | for line_id in sale_line_id: | 233 | filter_products = [] |
329 | 160 | sale_line_data= sale_line_obj.browse(cr,uid,line_id) | 234 | for product_id in product_ids: |
330 | 161 | consum_qty += sale_line_data.product_uom_qty | 235 | product_data = product_obj.browse(cr, uid, product_id, context=context) |
331 | 162 | ###here consume quantity is total of selected product | 236 | for seller_id in product_data.seller_ids: |
332 | 163 | ##################calculation of date difference between first and last sale order | 237 | if seller_id.name.id == partner_id: |
333 | 164 | sale_ids = sale_obj.search(cr,uid,[('date_order','>=',date_start),('date_order','<=',date_stop)], order='date_order asc') | 238 | filter_products.append(product_id) |
334 | 165 | if sale_ids: | 239 | |
335 | 166 | start_sale_id = sale_ids[0] | 240 | #3. Calculation of the first stock input date as first input |
336 | 167 | last_sale_id = sale_ids[-1] | 241 | for filter_product_id in filter_products: |
337 | 168 | first_sale_date = sale_obj.browse(cr,uid,start_sale_id).date_order | 242 | product_data = pool.get('product.product').browse(cr, uid, filter_product_id, context=context) |
338 | 169 | last_sale_date = sale_obj.browse(cr,uid,last_sale_id).date_order | 243 | supplier_lead_time = 0.0 |
339 | 170 | first_date = time.mktime(time.strptime(first_sale_date,'%Y-%m-%d')) | 244 | |
340 | 171 | last_date = time.mktime(time.strptime(last_sale_date,'%Y-%m-%d')) | 245 | # supplier_lead_time of the supplier delay |
341 | 172 | diff_day = (last_date-first_date)/(3600*24) | 246 | for seller_id in product_data.seller_ids: |
342 | 173 | if diff_day > 0: | 247 | if seller_id.name.id == partner_id: |
343 | 174 | average_daily_consumption = consum_qty / diff_day | 248 | supplier_lead_time = seller_id.delay |
344 | 175 | ###### Calculation of plan_average_daily_consumption | 249 | |
345 | 176 | plan_average_daily_consumption = 0.0 | 250 | stock_move_ids = stock_move_obj.search(cr, uid, [('product_id','=',filter_product_id)]) |
346 | 177 | if product_id.plan_avg_consume: | 251 | |
347 | 178 | plan_average_daily_consumption = product_id.plan_avg_consume | 252 | average_daily_consumption = 0.0 |
348 | 179 | 253 | first_stock_move_ids = [] | |
349 | 180 | ####### get location ##### | 254 | # Take the first input date of the stock move where stock move of incoming picking or stock move not have any picking |
350 | 181 | location_id = data['form']['location_id'] | 255 | for first_stock_id in stock_move_ids: |
351 | 182 | 256 | first_data = stock_move_obj.browse(cr, uid, first_stock_id, context=context) | |
352 | 183 | ########## calculation historical consumption of products and open sales orders“ | 257 | if first_data.picking_id: |
353 | 184 | ### total sale qty with open state | 258 | if first_data.picking_id.type == 'in': |
354 | 185 | 259 | first_stock_move_ids.append(first_stock_id) | |
355 | 186 | sale_qty = 0.0 | 260 | else: |
356 | 187 | open_sale_ids = sale_obj.search(cr, uid, [('state','in',['manual','progress'])]) | 261 | first_stock_move_ids.append(first_stock_id) |
357 | 188 | if sale_ids: | 262 | |
358 | 189 | for sale_id in open_sale_ids: | 263 | if first_stock_move_ids: |
359 | 190 | sale_open_line_ids= sale_line_obj.search(cr,uid,[('order_id','=',sale_id),('product_id','=',product_id.id)]) | 264 | first_stock_move_id = first_stock_move_ids[0] |
360 | 191 | for open_line_id in sale_open_line_ids: | 265 | first_input = stock_move_obj.browse(cr, uid, first_stock_move_id, context=context).date_planned |
361 | 192 | sale_line_data= sale_line_obj.browse(cr,uid,open_line_id) | 266 | |
362 | 193 | sale_qty += sale_line_data.product_uom_qty | 267 | # Case 1 if first input is less than from date |
363 | 194 | ################### | 268 | if first_input < from_date: |
364 | 195 | purchase_ids = purchase_obj.search(cr,uid,[]) | 269 | consum_qty = _sale_consume_qty(self, cr, uid, from_date, to_date, 'done', context) |
365 | 196 | if purchase_ids: | 270 | refund_qty = _refund_qty(self, cr, uid, filter_product_id, from_date, to_date, ['out_refund','in_refund'], context) |
366 | 197 | start_pur_id = min(purchase_ids) | 271 | open_sale_qty = _sale_open_qty(self, cr, uid, filter_product_id, from_date, to_date, ['manual','progress'], context) |
367 | 198 | last_pur_id = max(purchase_ids) | 272 | open_purchase_qty = _purchase_open_qty(self, cr, uid, filter_product_id, 'approved', context) |
368 | 199 | 273 | pur_diff_day = _date_diff(self, cr, uid, filter_product_id, from_date, to_date, context) | |
369 | 200 | ##################calculation of date difference between first and last purchase order | 274 | ### calculation of average_daily_consumption |
370 | 201 | first_purchase_date = purchase_obj.browse(cr,uid,start_pur_id).date_order | 275 | if pur_diff_day > 0: |
371 | 202 | last_purchase_date = purchase_obj.browse(cr,uid,last_pur_id).date_order | 276 | average_daily_consumption = (consum_qty - refund_qty + open_sale_qty - open_purchase_qty) / pur_diff_day |
372 | 203 | first_date = time.mktime(time.strptime(first_purchase_date,'%Y-%m-%d')) | 277 | |
373 | 204 | last_date = time.mktime(time.strptime(last_purchase_date,'%Y-%m-%d')) | 278 | elif from_date < first_input and first_input < to_date: |
374 | 205 | pur_diff_day = (last_date-first_date)/(3600*24) | 279 | first_date = first_input |
375 | 206 | product_max_qty = 0.0 | 280 | consum_qty = _sale_consume_qty(self, cr, uid, filter_product_id, first_date, to_date, 'done', context) |
376 | 207 | product_min_qty = 0.0 | 281 | refund_qty = _refund_qty(self, cr, uid, filter_product_id, first_date, to_date, ['out_refund','in_refund'], context) |
377 | 208 | 282 | open_sale_qty = _sale_open_qty(self, cr, uid, filter_product_id, ['manual','progress'], context) | |
378 | 209 | if data['form']['method_qty_calculation'] == 'his_cons_with_product': | 283 | open_purchase_qty = _purchase_open_qty(self, cr, uid, filter_product_id, 'approved', context) |
379 | 210 | product_min_qty = int(math.ceil(average_daily_consumption * (supplier_lead_time + purchase_lead_time) * seasonal_factor)) | 284 | pur_diff_day = _date_diff(self, cr, uid, filter_product_id, first_date, to_date, context) |
380 | 211 | product_max_qty = 2 * product_min_qty | 285 | |
381 | 212 | 286 | ### calculation of average_daily_consumption | |
382 | 213 | elif data['form']['method_qty_calculation'] == 'his_cons_without_product': | 287 | if pur_diff_day>0: |
383 | 214 | product_min_qty = int(math.ceil(plan_average_daily_consumption * (supplier_lead_time + purchase_lead_time) * seasonal_factor)) | 288 | average_daily_consumption = (consum_qty - refund_qty + open_sale_qty - open_purchase_qty) / pur_diff_day |
384 | 215 | product_max_qty = 2 * product_min_qty | 289 | else: |
385 | 216 | 290 | open_sale_qty = _sale_open_qty(self, cr, uid, filter_product_id, ['manual','progress'], context) | |
386 | 217 | else: | 291 | open_purchase_qty = _purchase_open_qty(self, cr, uid, filter_product_id, 'approved', context) |
387 | 218 | try: | 292 | |
388 | 219 | product_min_qty = int(math.ceil((consum_qty + sale_qty) / pur_diff_day * (supplier_lead_time + purchase_lead_time) * seasonal_factor)) | 293 | # calculation of first open purchase order date |
389 | 220 | except Exception,e: | 294 | open_purchase_ids = purchase_obj.search(cr,uid,[('state','=','approved')]) |
390 | 221 | product_min_qty = 0.0 | 295 | first_open_purchase_order = min(open_purchase_ids) |
391 | 222 | product_max_qty = 2 * product_min_qty | 296 | fst_open_pur_date = purchase_obj.browse(cr, uid, first_open_purchase_order, context=context).date_order |
392 | 223 | 297 | ||
393 | 224 | if data['form']['delactive']: | 298 | # Days difference between to date and first purchase date |
394 | 225 | stock_rule_ids = min_rule_obj.search(cr,uid,[('warehouse_id','=',data['form']['warehouse_id']),('product_id','=',product_id.id)]) | 299 | pur_to_date = time.mktime(time.strptime(to_date,'%Y-%m-%d %H:%M:%S')) |
395 | 226 | for stock_rule_id in stock_rule_ids: | 300 | pur_open_date = time.mktime(time.strptime(fst_open_pur_date,'%Y-%m-%d')) |
396 | 227 | min_rule_obj.unlink(cr, uid, [stock_rule_id],context=context) | 301 | pur_diff_day = (pur_to_date-pur_open_date)/(3600*24) |
397 | 228 | 302 | ||
398 | 229 | mini_stock_rule_id = min_rule_obj.search(cr,uid,[('warehouse_id','=',data['form']['warehouse_id']),('product_id','=',product_id.id)]) | 303 | if pur_diff_day>0: |
399 | 230 | if mini_stock_rule_id: | 304 | average_daily_consumption = (open_sale_qty - open_purchase_qty)/pur_diff_day |
400 | 231 | for stock_rule_id in mini_stock_rule_id: | 305 | |
401 | 232 | min_rule_obj.write(cr, uid, [stock_rule_id],{'product_min_qty':product_min_qty,'product_max_qty':product_max_qty,},context=context) | 306 | ###### Calculation of plan_average_daily_consumption |
402 | 233 | else: | 307 | plan_average_daily_consumption = 0.0 |
403 | 234 | name = pool.get('ir.sequence').get(cr, uid, 'stock.orderpoint.calculator') | 308 | plan_average_daily_consumption = product_data.plan_avg_consume |
404 | 235 | pool.get('stock.warehouse.orderpoint').create(cr, uid, { | 309 | |
405 | 236 | 'name': name, | 310 | if data['form']['method_qty_calculation'] == 'his_cons_with_product': |
406 | 237 | 'active': True, | 311 | product_min_qty = int(math.ceil(average_daily_consumption * (supplier_lead_time + purchase_lead_time) * seasonal_factor)) |
407 | 238 | 'warehouse_id': data['form']['warehouse_id'], | 312 | product_max_qty = max_qty_factor * product_min_qty |
408 | 239 | 'location_id': location_id, | 313 | |
409 | 240 | 'product_id': id, | 314 | elif data['form']['method_qty_calculation'] == 'his_cons_without_product': |
410 | 241 | 'product_min_qty': product_min_qty, | 315 | product_min_qty = int(math.ceil(plan_average_daily_consumption * (supplier_lead_time + purchase_lead_time) * seasonal_factor)) |
411 | 242 | 'product_max_qty': product_max_qty, | 316 | product_max_qty = max_qty_factor * product_min_qty |
412 | 243 | 'qty_multiple':1, | 317 | |
413 | 244 | 'product_uom':product_id.uom_id.id, | 318 | else: |
414 | 245 | 'logic':'max' | 319 | try: |
415 | 246 | } ) | 320 | product_min_qty = int(math.ceil((consum_qty + open_sale_qty) / pur_diff_day * (supplier_lead_time + purchase_lead_time) * seasonal_factor)) |
416 | 247 | 321 | except Exception,e: | |
417 | 248 | 322 | product_min_qty = 0.0 | |
418 | 323 | product_max_qty = max_qty_factor * product_min_qty | ||
419 | 324 | |||
420 | 325 | if data['form']['delactive']: | ||
421 | 326 | stock_rule_ids = min_rule_obj.search(cr,uid,[('warehouse_id','=',data['form']['warehouse_id']),('product_id','=',filter_product_id)]) | ||
422 | 327 | for stock_rule_id in stock_rule_ids: | ||
423 | 328 | min_rule_obj.unlink(cr, uid, [stock_rule_id],context=context) | ||
424 | 329 | |||
425 | 330 | mini_stock_rule_id = min_rule_obj.search(cr,uid,[('warehouse_id','=',data['form']['warehouse_id']),('product_id','=',filter_product_id)]) | ||
426 | 331 | if mini_stock_rule_id: | ||
427 | 332 | for stock_rule_id in mini_stock_rule_id: | ||
428 | 333 | min_rule_obj.write(cr, uid, [stock_rule_id],{'product_min_qty':product_min_qty,'product_max_qty':product_max_qty,},context=context) | ||
429 | 334 | else: | ||
430 | 335 | name = pool.get('ir.sequence').get(cr, uid, 'stock.orderpoint.calculator') | ||
431 | 336 | pool.get('stock.warehouse.orderpoint').create(cr, uid, { | ||
432 | 337 | 'name': name, | ||
433 | 338 | 'active': True, | ||
434 | 339 | 'warehouse_id': data['form']['warehouse_id'], | ||
435 | 340 | 'location_id': location_id, | ||
436 | 341 | 'product_id': filter_product_id, | ||
437 | 342 | 'product_min_qty': product_min_qty, | ||
438 | 343 | 'product_max_qty': product_max_qty, | ||
439 | 344 | 'qty_multiple':1, | ||
440 | 345 | 'product_uom':product_data.uom_id.id, | ||
441 | 346 | 'logic':'price', | ||
442 | 347 | } ) | ||
443 | 348 | |||
444 | 249 | return {} | 349 | return {} |
445 | 250 | 350 | ||
446 | 251 | def _get_message(self, cr, uid, data, context): | 351 | def _get_message(self, cr, uid, data, context): |