[FIX] Code and description review

This commit is contained in:
unknown
2013-02-18 23:21:19 +01:00
parent 1624c00c71
commit ea20e8120c
3 changed files with 33 additions and 29 deletions

View File

@@ -21,17 +21,22 @@
{
'name': 'Improved reordering rules',
'version': '0.1',
'version': '0.2',
'category': 'Tools',
'description': """
This module allows to improve reordering rules of stock module.""",
This module allows to improve reordering rules of stock module.
It works forecasting the stock needed per product for n days of sales, with the next formula:
(( Qty sold in days_stats * (1+forecast_gap)) / days_stats * days_warehouse)
where:
- days_stats = days on wich calculate sales stats;
- forecast_gap = forecast of increase/decrease on sales (%);
- days_warehouse = days of stock to keep in the warehouse.""",
'author': 'Sergio Corato',
'website': 'http://www.icstools.it',
'depends': ['procurement','sale',],
'init_xml': [],
'update_xml': ['stock_reord_rule_view.xml',],
'demo_xml' : [],
'data': ['cron_data.xml',],
'data': ['stock_reord_rule_view.xml','cron_data.xml',],
'images': [],
'active': False,
'installable': True,

View File

@@ -19,39 +19,38 @@
#
##############################################################################
from osv import osv, fields
from openerp.osv import orm, fields
class stock_warehouse_orderpoint(osv.osv):
class stock_warehouse_orderpoint(orm.Model):
_inherit = "stock.warehouse.orderpoint"
def _qty_orderpoint_days(self, cr, uid, ids, context=None):
"""Calculate quantity to create warehouse stock for n days of sales.
integer (( Qty sold in days_stats * (1+forecast_gap)) / days_stats * days_warehouse)"""
(( Qty sold in days_stats * (1+forecast_gap)) / days_stats * days_warehouse)"""
res = {}
obj_product = self.pool.get('product.product')
product_ids = tuple(obj_product.search(cr, uid, []))
if len(product_ids) > 1:
sql= """SELECT sol.product_id AS product_id, (sum( product_uos_qty )/pp.days_stats*(1+pp.forecast_gap/100) * pp.days_warehouse) AS quantity FROM sale_order_line sol JOIN sale_order so ON so.id = sol.order_id JOIN product_product pp ON pp.id = sol.product_id WHERE sol.state in ('done','confirmed') AND sol.product_id IN {product_ids} AND date_order > (date(now()) - pp.days_stats) GROUP BY sol.product_uom, sol.product_id, pp.days_stats, pp.forecast_gap, pp.days_warehouse;""".format(product_ids=product_ids)
cr.execute(sql)
sql_res = cr.fetchall()
for val in sql_res:
product_ids = tuple(obj_product.search(cr, uid, [], context=context))
sql= """SELECT sol.product_id AS product_id,
(sum( product_uos_qty )/pp.days_stats*(1+pp.forecast_gap/100) * pp.days_warehouse)
AS quantity FROM sale_order_line sol JOIN sale_order so ON so.id = sol.order_id
JOIN product_product pp ON pp.id = sol.product_id WHERE sol.state in ('done','confirmed')
AND sol.product_id IN %s AND date_order > (date(now()) - pp.days_stats)
GROUP BY sol.product_uom, sol.product_id, pp.days_stats, pp.forecast_gap,
pp.days_warehouse;"""
cr.execute(sql, (product_ids,))
sql_res = cr.fetchall()
for val in sql_res:
if val:
reord_rules_ids = self.search(cr, uid, [('product_id','=', val[0])])
reord_rules_ids = self.search(cr, uid, [('product_id', '=', val[0])], context=context)
if reord_rules_ids:
res['product_max_qty'] = val[1]
self.write(cr, uid, reord_rules_ids, res)
self.write(cr, uid, reord_rules_ids, {'product_max_qty': val[1]}, context=context)
return True
stock_warehouse_orderpoint()
class product_product(osv.osv):
class product_product(orm.Model):
_inherit = "product.product"
_columns = {
'days_warehouse': fields.integer('Nr of days of warehouse stock'),
'days_stats':fields.integer('Nr of days on which calculate stats'),
'forecast_gap':fields.float('Forecast gap%', digits=(6,int(3))),
'days_warehouse': fields.integer('Days of needed warehouse stock'),
'days_stats': fields.integer('Days of sale statistics'),
'forecast_gap': fields.float('Expected sales variation (percent +/-)', digits=(6,3)),
}
product_product()

View File

@@ -9,9 +9,9 @@
<field name="arch" type="xml">
<group name="procurement" position="after">
<group name="Stock Procurement By Days">
<field name="days_warehouse" string="Days of warehouse stock"/>
<field name="days_stats" string="Days of sale stats"/>
<field name="forecast_gap" string="Expected sales variation (percent +/-)"/>
<field name="days_warehouse"/>
<field name="days_stats"/>
<field name="forecast_gap"/>
</group>
</group>
</field>