Merge lp:~openbig/bigconsulting/solved_stock_minimum_calculator into lp:bigconsulting

Proposed by gpa(OpenERP)
Status: Merged
Merged at revision: 45
Proposed branch: lp:~openbig/bigconsulting/solved_stock_minimum_calculator
Merge into: lp:bigconsulting
Diff against target: 116 lines (+22/-14)
1 file modified
stock_minimum_calculator/wizard/stock_order_point_calculator.py (+22/-14)
To merge this branch: bzr merge lp:~openbig/bigconsulting/solved_stock_minimum_calculator
Reviewer Review Type Date Requested Status
openbig Pending
Review via email: mp+29360@code.launchpad.net

Description of the change

Improvement in stock_minimum_calculator module

To post a comment you must log in.
48. By gpa(OpenERP)

solved problem in stock minimum calculator

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'stock_minimum_calculator/wizard/stock_order_point_calculator.py'
2--- stock_minimum_calculator/wizard/stock_order_point_calculator.py 2010-06-24 08:01:22 +0000
3+++ stock_minimum_calculator/wizard/stock_order_point_calculator.py 2010-07-07 06:36:41 +0000
4@@ -66,7 +66,8 @@
5 'string': 'Season of Consumption',
6 'type': 'many2one',
7 'relation': 'product.seasonal',
8- 'required': True
9+ 'required': True,
10+ '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.'
11 },
12
13 'date_start': {
14@@ -104,16 +105,18 @@
15 pool = pooler.get_pool(cr.dbname)
16
17 warehouse_id = pool.get('stock.warehouse').search(cr, uid, [])[0]
18- location_id = pool.get('stock.location').search(cr, uid, [('name','=','Stock')])[0]
19+ seasonal_id = pool.get('product.seasonal').search(cr, uid, [])[0]
20
21+ w = pool.get('stock.warehouse').browse(cr,uid,warehouse_id, context)
22+ location_id = w.lot_stock_id.id
23+
24 from_date = now().strftime('%Y-%m-%d')
25 from_date = mx.DateTime.strptime(from_date, '%Y-%m-%d') - RelativeDateTime(months=3)
26 from_date = from_date.strftime('%Y-%m-%d')
27
28- return {'warehouse_id': warehouse_id, 'location_id':location_id,'date_start':from_date}
29+ return {'warehouse_id': warehouse_id, 'location_id':location_id,'date_start':from_date,'seasonal_id':seasonal_id}
30
31 def _do_calculate(self, cr, uid, data, context):
32-
33 pool = pooler.get_pool(cr.dbname)
34
35 purchase_obj = pool.get('purchase.order')
36@@ -122,12 +125,17 @@
37 supp_obj = pool.get('product.supplierinfo')
38 supp_cost_opt_obj = pool.get('supplier.cost.opti.lead.time')
39 min_rule_obj = pool.get('stock.warehouse.orderpoint')
40-
41+ seasonal_obj = pool.get('product.seasonal')
42 ##### Calculation of purchase lead time
43 purchase_lead_time = 0.0
44 company = pool.get('res.users').browse(cr, uid, uid, context).company_id
45 purchase_lead_time = company.po_lead
46
47+ ##### get seasonal factor
48+ seasonal_id = data['form']['seasonal_id']
49+ seasonal_data = seasonal_obj.browse(cr, uid, seasonal_id)
50+ seasonal_factor = seasonal_data.seasonal_factor
51+
52 ##### Calculation of supplier lead time
53
54 for id in data['ids']:
55@@ -152,9 +160,8 @@
56 sale_line_data= sale_line_obj.browse(cr,uid,line_id)
57 consum_qty += sale_line_data.product_uom_qty
58 ###here cosume quantity is total of selected produdct
59-
60 ##################calculation of date difference between first and last sale order
61- sale_ids = sale_obj.search(cr,uid,[])
62+ sale_ids = sale_obj.search(cr,uid,[('date_order','>=',date_start),('date_order','<=',date_stop)])
63 if sale_ids:
64 start_sale_id = min(sale_ids)
65 last_sale_id = max(sale_ids)
66@@ -165,11 +172,14 @@
67 diff_day = (last_date-first_date)/(3600*24)
68 if diff_day > 0:
69 average_daily_consumption = consum_qty / diff_day
70-
71 ###### Calculation of plan_average_daily_consumption
72 plan_average_daily_consumption = 0.0
73 if product_id.plan_avg_consume:
74 plan_average_daily_consumption = product_id.plan_avg_consume
75+
76+ ####### get location #####
77+ location_id = data['form']['location_id']
78+
79 ########## calculation historical consumption of products and open sales orders“
80 ### total sale qty with open state
81
82@@ -193,22 +203,20 @@
83 first_date = time.mktime(time.strptime(first_purchase_date,'%Y-%m-%d'))
84 last_date = time.mktime(time.strptime(last_purchase_date,'%Y-%m-%d'))
85 pur_diff_day = (last_date-first_date)/(3600*24)
86-
87 product_max_qty = 0.0
88 product_min_qty = 0.0
89
90-
91 if data['form']['method_qty_calculation'] == 'his_cons_with_product':
92- product_min_qty = int(math.ceil(average_daily_consumption * (supplier_lead_time + purchase_lead_time)))
93+ product_min_qty = int(math.ceil(average_daily_consumption * (supplier_lead_time + purchase_lead_time) * seasonal_factor))
94 product_max_qty = 2 * product_min_qty
95
96 elif data['form']['method_qty_calculation'] == 'his_cons_without_product':
97- product_min_qty = int(math.ceil(plan_average_daily_consumption * (supplier_lead_time + purchase_lead_time)))
98+ product_min_qty = int(math.ceil(plan_average_daily_consumption * (supplier_lead_time + purchase_lead_time) * seasonal_factor))
99 product_max_qty = 2 * product_min_qty
100
101 else:
102 try:
103- product_min_qty = int(math.ceil((consum_qty + sale_qty) / pur_diff_day * (supplier_lead_time + purchase_lead_time)))
104+ product_min_qty = int(math.ceil((consum_qty + sale_qty) / pur_diff_day * (supplier_lead_time + purchase_lead_time) * seasonal_factor))
105 except Exception,e:
106 product_min_qty = 0.0
107 product_max_qty = 2 * product_min_qty
108@@ -228,7 +236,7 @@
109 'name': name,
110 'active': True,
111 'warehouse_id': data['form']['warehouse_id'],
112- 'location_id': product_id.property_stock_inventory.id,
113+ 'location_id': location_id,
114 'product_id': id,
115 'product_min_qty': product_min_qty,
116 'product_max_qty': product_max_qty,

Subscribers

People subscribed via source and target branches