From 03676ae11a1b280d9e41a33fce9d15ffab7850d9 Mon Sep 17 00:00:00 2001 From: svs-odoo Date: Wed, 20 Oct 2021 13:49:53 +0000 Subject: [PATCH] [IMP] stock: orderpoint by date instead of time Before this commit, the Replenishment orderpoints `qty_to_order` are computed according to a precise forecast which take the time in count. For example, if you plan a consumption for a product with a purchase lead time of 2 days for the 2021-12-12 at 12:30, if the current date is 2021-12-10, the orderpoint for this product will have a quantity to order once the hour is meet too but not before. With this commit, it will take the forecast for the day regardless the time. task-2652920 closes odoo/odoo#78712 Signed-off-by: Tiffany Chang --- addons/stock/models/stock_orderpoint.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/stock/models/stock_orderpoint.py b/addons/stock/models/stock_orderpoint.py index 48946b5341c..53bebd220da 100644 --- a/addons/stock/models/stock_orderpoint.py +++ b/addons/stock/models/stock_orderpoint.py @@ -351,11 +351,12 @@ class StockWarehouseOrderpoint(models.Model): pwh_per_day[(lead_days, warehouse)].append(product.id) # group product by lead_days and warehouse in order to read virtual_available # in batch + today = fields.datetime.now().replace(hour=23, minute=59, second=59) for (days, warehouse), p_ids in pwh_per_day.items(): products = self.env['product.product'].browse(p_ids) qties = products.with_context( warehouse=warehouse.id, - to_date=fields.datetime.now() + relativedelta.relativedelta(days=days) + to_date=today + relativedelta.relativedelta(days=days) ).read(['virtual_available']) for qty in qties: if float_compare(qty['virtual_available'], 0, precision_rounding=product.uom_id.rounding) >= 0: