From ae0012ef3ee0c7fe2df5b1516d362c738c232e71 Mon Sep 17 00:00:00 2001 From: Arnold Moyaux Date: Tue, 13 Jul 2021 15:32:29 +0000 Subject: [PATCH] [FIX] stock: replenish report in 3 months Currently the replenishment report look for forecasted quantity of product today. It means that for a product if the delivery is planned for today the forecast will be -1, at j-1 it will be 0. However for the majority of use case, products take days to order and arrive. Example: - Product A, purchase delivery time 5 days. - You are the 01-01-2021 and create a SO for 10-01-2021 Currently: - Product will appear in the replenishment report the 10-01-2021 and you will receive it the 15-01-2021. So you are late to deliver your customer. Desired behavior: - Product appear in the replenishment report the 05-01-2021 and if you order it directly you will receive it the 10-01-2021. If you want to have more time to deliver than one day, security lead time are there for it. However the usecase like: Product arrive in 2 months and you receive it in 3 days, the product won't appear in the replenish report anymore since the forecast in 3months is 0 It could happens that more product are missing in 3 months than today, so the system could have more delivery lead times and forecast at date to compute -> be slower. In that case a parameter could be added to skip the delivery times computation for each product/warehouse and just display the forecast in 3 months and let user compute their schedule themself. closes odoo/odoo#73737 X-original-commit: f988b7629f8f54e8e3f48bf76e6af9d97b4f47da Signed-off-by: Arnold Moyaux --- addons/stock/models/stock_orderpoint.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/addons/stock/models/stock_orderpoint.py b/addons/stock/models/stock_orderpoint.py index 15e960b1165..db4e7dee5a6 100644 --- a/addons/stock/models/stock_orderpoint.py +++ b/addons/stock/models/stock_orderpoint.py @@ -12,7 +12,7 @@ from odoo import SUPERUSER_ID, _, api, fields, models, registry from odoo.addons.stock.models.stock_rule import ProcurementException from odoo.exceptions import UserError, ValidationError from odoo.osv import expression -from odoo.tools import float_compare, frozendict, split_every +from odoo.tools import add, float_compare, frozendict, split_every _logger = logging.getLogger(__name__) @@ -313,8 +313,10 @@ class StockWarehouseOrderpoint(models.Model): to_refill = defaultdict(float) all_product_ids = [] all_warehouse_ids = [] + # Take 3 months since it's the max for the forecast report + to_date = add(fields.date.today(), months=3) qty_by_product_warehouse = self.env['report.stock.quantity'].read_group( - [('date', '=', fields.date.today()), ('state', '=', 'forecast')], + [('date', '=', to_date), ('state', '=', 'forecast')], ['product_id', 'product_qty', 'warehouse_id'], ['product_id', 'warehouse_id'], lazy=False) for group in qty_by_product_warehouse: