mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[FIX] Code and description review
This commit is contained in:
@@ -21,17 +21,22 @@
|
|||||||
|
|
||||||
{
|
{
|
||||||
'name': 'Improved reordering rules',
|
'name': 'Improved reordering rules',
|
||||||
'version': '0.1',
|
'version': '0.2',
|
||||||
'category': 'Tools',
|
'category': 'Tools',
|
||||||
'description': """
|
'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',
|
'author': 'Sergio Corato',
|
||||||
'website': 'http://www.icstools.it',
|
'website': 'http://www.icstools.it',
|
||||||
'depends': ['procurement','sale',],
|
'depends': ['procurement','sale',],
|
||||||
'init_xml': [],
|
|
||||||
'update_xml': ['stock_reord_rule_view.xml',],
|
|
||||||
'demo_xml' : [],
|
'demo_xml' : [],
|
||||||
'data': ['cron_data.xml',],
|
'data': ['stock_reord_rule_view.xml','cron_data.xml',],
|
||||||
'images': [],
|
'images': [],
|
||||||
'active': False,
|
'active': False,
|
||||||
'installable': True,
|
'installable': True,
|
||||||
|
|||||||
@@ -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"
|
_inherit = "stock.warehouse.orderpoint"
|
||||||
|
|
||||||
def _qty_orderpoint_days(self, cr, uid, ids, context=None):
|
def _qty_orderpoint_days(self, cr, uid, ids, context=None):
|
||||||
"""Calculate quantity to create warehouse stock for n days of sales.
|
"""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')
|
obj_product = self.pool.get('product.product')
|
||||||
product_ids = tuple(obj_product.search(cr, uid, []))
|
product_ids = tuple(obj_product.search(cr, uid, [], context=context))
|
||||||
if len(product_ids) > 1:
|
sql= """SELECT sol.product_id AS product_id,
|
||||||
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)
|
(sum( product_uos_qty )/pp.days_stats*(1+pp.forecast_gap/100) * pp.days_warehouse)
|
||||||
cr.execute(sql)
|
AS quantity FROM sale_order_line sol JOIN sale_order so ON so.id = sol.order_id
|
||||||
sql_res = cr.fetchall()
|
JOIN product_product pp ON pp.id = sol.product_id WHERE sol.state in ('done','confirmed')
|
||||||
for val in sql_res:
|
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:
|
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:
|
if reord_rules_ids:
|
||||||
res['product_max_qty'] = val[1]
|
self.write(cr, uid, reord_rules_ids, {'product_max_qty': val[1]}, context=context)
|
||||||
self.write(cr, uid, reord_rules_ids, res)
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
stock_warehouse_orderpoint()
|
class product_product(orm.Model):
|
||||||
|
|
||||||
class product_product(osv.osv):
|
|
||||||
_inherit = "product.product"
|
_inherit = "product.product"
|
||||||
|
|
||||||
_columns = {
|
_columns = {
|
||||||
'days_warehouse': fields.integer('Nr of days of warehouse stock'),
|
'days_warehouse': fields.integer('Days of needed warehouse stock'),
|
||||||
'days_stats':fields.integer('Nr of days on which calculate stats'),
|
'days_stats': fields.integer('Days of sale statistics'),
|
||||||
'forecast_gap':fields.float('Forecast gap%', digits=(6,int(3))),
|
'forecast_gap': fields.float('Expected sales variation (percent +/-)', digits=(6,3)),
|
||||||
}
|
}
|
||||||
|
|
||||||
product_product()
|
|
||||||
|
|||||||
@@ -9,9 +9,9 @@
|
|||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<group name="procurement" position="after">
|
<group name="procurement" position="after">
|
||||||
<group name="Stock Procurement By Days">
|
<group name="Stock Procurement By Days">
|
||||||
<field name="days_warehouse" string="Days of warehouse stock"/>
|
<field name="days_warehouse"/>
|
||||||
<field name="days_stats" string="Days of sale stats"/>
|
<field name="days_stats"/>
|
||||||
<field name="forecast_gap" string="Expected sales variation (percent +/-)"/>
|
<field name="forecast_gap"/>
|
||||||
</group>
|
</group>
|
||||||
</group>
|
</group>
|
||||||
</field>
|
</field>
|
||||||
|
|||||||
Reference in New Issue
Block a user