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
=== modified file 'stock_minimum_calculator/wizard/stock_order_point_calculator.py'
--- stock_minimum_calculator/wizard/stock_order_point_calculator.py 2010-06-24 08:01:22 +0000
+++ stock_minimum_calculator/wizard/stock_order_point_calculator.py 2010-07-07 06:36:41 +0000
@@ -66,7 +66,8 @@
66 'string': 'Season of Consumption', 66 'string': 'Season of Consumption',
67 'type': 'many2one', 67 'type': 'many2one',
68 'relation': 'product.seasonal', 68 'relation': 'product.seasonal',
69 'required': True69 'required': True,
70 '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.'
70 },71 },
71 72
72 'date_start': {73 'date_start': {
@@ -104,16 +105,18 @@
104 pool = pooler.get_pool(cr.dbname)105 pool = pooler.get_pool(cr.dbname)
105106
106 warehouse_id = pool.get('stock.warehouse').search(cr, uid, [])[0]107 warehouse_id = pool.get('stock.warehouse').search(cr, uid, [])[0]
107 location_id = pool.get('stock.location').search(cr, uid, [('name','=','Stock')])[0]108 seasonal_id = pool.get('product.seasonal').search(cr, uid, [])[0]
108109
110 w = pool.get('stock.warehouse').browse(cr,uid,warehouse_id, context)
111 location_id = w.lot_stock_id.id
112
109 from_date = now().strftime('%Y-%m-%d')113 from_date = now().strftime('%Y-%m-%d')
110 from_date = mx.DateTime.strptime(from_date, '%Y-%m-%d') - RelativeDateTime(months=3)114 from_date = mx.DateTime.strptime(from_date, '%Y-%m-%d') - RelativeDateTime(months=3)
111 from_date = from_date.strftime('%Y-%m-%d')115 from_date = from_date.strftime('%Y-%m-%d')
112116
113 return {'warehouse_id': warehouse_id, 'location_id':location_id,'date_start':from_date}117 return {'warehouse_id': warehouse_id, 'location_id':location_id,'date_start':from_date,'seasonal_id':seasonal_id}
114118
115def _do_calculate(self, cr, uid, data, context):119def _do_calculate(self, cr, uid, data, context):
116
117 pool = pooler.get_pool(cr.dbname)120 pool = pooler.get_pool(cr.dbname)
118121
119 purchase_obj = pool.get('purchase.order')122 purchase_obj = pool.get('purchase.order')
@@ -122,12 +125,17 @@
122 supp_obj = pool.get('product.supplierinfo')125 supp_obj = pool.get('product.supplierinfo')
123 supp_cost_opt_obj = pool.get('supplier.cost.opti.lead.time')126 supp_cost_opt_obj = pool.get('supplier.cost.opti.lead.time')
124 min_rule_obj = pool.get('stock.warehouse.orderpoint')127 min_rule_obj = pool.get('stock.warehouse.orderpoint')
125128 seasonal_obj = pool.get('product.seasonal')
126 ##### Calculation of purchase lead time 129 ##### Calculation of purchase lead time
127 purchase_lead_time = 0.0130 purchase_lead_time = 0.0
128 company = pool.get('res.users').browse(cr, uid, uid, context).company_id131 company = pool.get('res.users').browse(cr, uid, uid, context).company_id
129 purchase_lead_time = company.po_lead132 purchase_lead_time = company.po_lead
130 133
134 ##### get seasonal factor
135 seasonal_id = data['form']['seasonal_id']
136 seasonal_data = seasonal_obj.browse(cr, uid, seasonal_id)
137 seasonal_factor = seasonal_data.seasonal_factor
138
131 ##### Calculation of supplier lead time139 ##### Calculation of supplier lead time
132140
133 for id in data['ids']:141 for id in data['ids']:
@@ -152,9 +160,8 @@
152 sale_line_data= sale_line_obj.browse(cr,uid,line_id)160 sale_line_data= sale_line_obj.browse(cr,uid,line_id)
153 consum_qty += sale_line_data.product_uom_qty161 consum_qty += sale_line_data.product_uom_qty
154 ###here cosume quantity is total of selected produdct162 ###here cosume quantity is total of selected produdct
155
156 ##################calculation of date difference between first and last sale order163 ##################calculation of date difference between first and last sale order
157 sale_ids = sale_obj.search(cr,uid,[])164 sale_ids = sale_obj.search(cr,uid,[('date_order','>=',date_start),('date_order','<=',date_stop)])
158 if sale_ids:165 if sale_ids:
159 start_sale_id = min(sale_ids)166 start_sale_id = min(sale_ids)
160 last_sale_id = max(sale_ids)167 last_sale_id = max(sale_ids)
@@ -165,11 +172,14 @@
165 diff_day = (last_date-first_date)/(3600*24)172 diff_day = (last_date-first_date)/(3600*24)
166 if diff_day > 0:173 if diff_day > 0:
167 average_daily_consumption = consum_qty / diff_day174 average_daily_consumption = consum_qty / diff_day
168
169 ###### Calculation of plan_average_daily_consumption175 ###### Calculation of plan_average_daily_consumption
170 plan_average_daily_consumption = 0.0176 plan_average_daily_consumption = 0.0
171 if product_id.plan_avg_consume:177 if product_id.plan_avg_consume:
172 plan_average_daily_consumption = product_id.plan_avg_consume178 plan_average_daily_consumption = product_id.plan_avg_consume
179
180 ####### get location #####
181 location_id = data['form']['location_id']
182
173 ########## calculation historical consumption of products and open sales orders“183 ########## calculation historical consumption of products and open sales orders“
174 ### total sale qty with open state184 ### total sale qty with open state
175 185
@@ -193,22 +203,20 @@
193 first_date = time.mktime(time.strptime(first_purchase_date,'%Y-%m-%d'))203 first_date = time.mktime(time.strptime(first_purchase_date,'%Y-%m-%d'))
194 last_date = time.mktime(time.strptime(last_purchase_date,'%Y-%m-%d'))204 last_date = time.mktime(time.strptime(last_purchase_date,'%Y-%m-%d'))
195 pur_diff_day = (last_date-first_date)/(3600*24)205 pur_diff_day = (last_date-first_date)/(3600*24)
196
197 product_max_qty = 0.0 206 product_max_qty = 0.0
198 product_min_qty = 0.0207 product_min_qty = 0.0
199 208
200
201 if data['form']['method_qty_calculation'] == 'his_cons_with_product':209 if data['form']['method_qty_calculation'] == 'his_cons_with_product':
202 product_min_qty = int(math.ceil(average_daily_consumption * (supplier_lead_time + purchase_lead_time)))210 product_min_qty = int(math.ceil(average_daily_consumption * (supplier_lead_time + purchase_lead_time) * seasonal_factor))
203 product_max_qty = 2 * product_min_qty211 product_max_qty = 2 * product_min_qty
204 212
205 elif data['form']['method_qty_calculation'] == 'his_cons_without_product':213 elif data['form']['method_qty_calculation'] == 'his_cons_without_product':
206 product_min_qty = int(math.ceil(plan_average_daily_consumption * (supplier_lead_time + purchase_lead_time)))214 product_min_qty = int(math.ceil(plan_average_daily_consumption * (supplier_lead_time + purchase_lead_time) * seasonal_factor))
207 product_max_qty = 2 * product_min_qty215 product_max_qty = 2 * product_min_qty
208 216
209 else:217 else:
210 try:218 try:
211 product_min_qty = int(math.ceil((consum_qty + sale_qty) / pur_diff_day * (supplier_lead_time + purchase_lead_time)))219 product_min_qty = int(math.ceil((consum_qty + sale_qty) / pur_diff_day * (supplier_lead_time + purchase_lead_time) * seasonal_factor))
212 except Exception,e:220 except Exception,e:
213 product_min_qty = 0.0221 product_min_qty = 0.0
214 product_max_qty = 2 * product_min_qty222 product_max_qty = 2 * product_min_qty
@@ -228,7 +236,7 @@
228 'name': name,236 'name': name,
229 'active': True,237 'active': True,
230 'warehouse_id': data['form']['warehouse_id'],238 'warehouse_id': data['form']['warehouse_id'],
231 'location_id': product_id.property_stock_inventory.id,239 'location_id': location_id,
232 'product_id': id,240 'product_id': id,
233 'product_min_qty': product_min_qty,241 'product_min_qty': product_min_qty,
234 'product_max_qty': product_max_qty,242 'product_max_qty': product_max_qty,

Subscribers

People subscribed via source and target branches