1
# -*- encoding: utf-8 -*-
2
##############################################################################
4
# Automatic Stock Procurement by days for OpenERP
5
# Copyright (C) 2012 Sergio Corato (<http://www.icstools.it>)
7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU Affero General Public License as
9
# published by the Free Software Foundation, either version 3 of the
10
# License, or (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU Affero General Public License for more details.
17
# You should have received a copy of the GNU Affero General Public License
18
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
##############################################################################
22
from osv import osv, fields
24
class stock_warehouse_orderpoint(osv.osv):
25
_inherit = "stock.warehouse.orderpoint"
27
def _qty_orderpoint_days(self, cr, uid, ids, context=None):
28
"""Calculate quantity to create warehouse stock for n days of sales.
29
integer (( Qty sold in days_stats * (1+forecast_gap)) / days_stats * days_warehouse)"""
32
obj_product = self.pool.get('product.product')
33
product_ids = tuple(obj_product.search(cr, uid, []))
34
if len(product_ids) > 1:
35
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)
37
sql_res = cr.fetchall()
40
reord_rules_ids = self.search(cr, uid, [('product_id','=', val[0])])
42
res['product_max_qty'] = val[1]
43
self.write(cr, uid, reord_rules_ids, res)
46
stock_warehouse_orderpoint()
48
class product_product(osv.osv):
49
_inherit = "product.product"
52
'days_warehouse': fields.integer('Nr of days of warehouse stock'),
53
'days_stats':fields.integer('Nr of days on which calculate stats'),
54
'forecast_gap':fields.float('Forecast gap%', digits=(6,int(3))),