From fe03a58e62a9f144ccbf27d2f9f6d4782db4180c Mon Sep 17 00:00:00 2001 From: Arnold Moyaux Date: Wed, 18 Jan 2023 08:53:21 +0000 Subject: [PATCH] [FIX] stock: be able to have infinite forecast in replenishment Currently if you require internal transit pickings between warehouse, it's not possible to use security days in order to plan them and receive products on time (e.g the second warehouse need times to manufacture them). Also the deadline are impacted by security days, so it's hard to do at the same time replenish on order an use the orderpoints. (either you see them late in orderpoints or they are plan way to early in replenish on order process) To avoid this kind of issue this PR introduces a visibility days global on the orderpoint. It's call `stock.visibility_days`. It will add the number of days in the orderpoint forecast date but it doesn't impact the documents (PO, MO) planned dates. It could for example always show the quantity in 1 years if people don't need the just in time feature and don't care to store for a long period of time. closes odoo/odoo#110303 X-original-commit: 24816bfee9825fecd60bd24a92d1496f30522b8e Signed-off-by: William Henrotin (whe) --- addons/stock/i18n/stock.pot | 7 +++++++ addons/stock/models/stock_orderpoint.py | 3 +++ addons/stock/models/stock_rule.py | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/addons/stock/i18n/stock.pot b/addons/stock/i18n/stock.pot index 732851ea9d3..5a4b63ce83b 100644 --- a/addons/stock/i18n/stock.pot +++ b/addons/stock/i18n/stock.pot @@ -9508,3 +9508,10 @@ msgstr "" msgid "" "{{ object.company_id.name }} Delivery Order (Ref {{ object.name or 'n/a' }})" msgstr "" + +#. module: stock +#. odoo-python +#: code:addons/stock/models/stock_rule.py:0 +#, python-format +msgid "Global Visibility Days" +msgstr "" \ No newline at end of file diff --git a/addons/stock/models/stock_orderpoint.py b/addons/stock/models/stock_orderpoint.py index be6559ba7ec..ce1f6aedefb 100644 --- a/addons/stock/models/stock_orderpoint.py +++ b/addons/stock/models/stock_orderpoint.py @@ -506,6 +506,9 @@ class StockWarehouseOrderpoint(models.Model): origin = orderpoint.name if float_compare(orderpoint.qty_to_order, 0.0, precision_rounding=orderpoint.product_uom.rounding) == 1: date = orderpoint._get_orderpoint_procurement_date() + global_visibility_days = self.env['ir.config_parameter'].sudo().get_param('stock.visibility_days') + if global_visibility_days: + date -= relativedelta.relativedelta(days=int(global_visibility_days)) values = orderpoint._prepare_procurement_values(date=date) procurements.append(self.env['procurement.group'].Procurement( orderpoint.product_id, orderpoint.qty_to_order, orderpoint.product_uom, diff --git a/addons/stock/models/stock_rule.py b/addons/stock/models/stock_rule.py index 8288f922975..12f81374de2 100644 --- a/addons/stock/models/stock_rule.py +++ b/addons/stock/models/stock_rule.py @@ -355,6 +355,9 @@ class StockRule(models.Model): :rtype: tuple[int, list[str, str]] """ delay = sum(self.filtered(lambda r: r.action in ['pull', 'pull_push']).mapped('delay')) + global_visibility_days = self.env['ir.config_parameter'].sudo().get_param('stock.visibility_days') + if global_visibility_days: + delay += int(global_visibility_days) if self.env.context.get('bypass_delay_description'): delay_description = [] else: @@ -363,6 +366,8 @@ class StockRule(models.Model): for rule in self if rule.action in ['pull', 'pull_push'] and rule.delay ] + if global_visibility_days: + delay_description.append((_('Global Visibility Days'), _('+ %d day(s)') % int(global_visibility_days))) return delay, delay_description