From 65dd899963cf2bc2d07d26c11c70c1e8e22b0539 Mon Sep 17 00:00:00 2001 From: luis Date: Mon, 6 Oct 2025 12:51:58 +0200 Subject: [PATCH] purchase_order_product_recommendation_supermarket: add a setting in products to suggest a minimum purchase when forecast <= 0 --- .../__init__.py | 1 + .../__manifest__.py | 5 +++- .../i18n/es.po | 29 +++++++++++++++++-- ...der_product_recommendation_supermarket.pot | 25 ++++++++++++++++ .../models/__init__.py | 1 + .../models/product_template.py | 10 +++++++ .../views/product_template_view.xml | 15 ++++++++++ .../wizards/purchase_order_recommendation.py | 11 ++++++- 8 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 purchase_order_product_recommendation_supermarket/models/__init__.py create mode 100644 purchase_order_product_recommendation_supermarket/models/product_template.py create mode 100644 purchase_order_product_recommendation_supermarket/views/product_template_view.xml diff --git a/purchase_order_product_recommendation_supermarket/__init__.py b/purchase_order_product_recommendation_supermarket/__init__.py index 5cb1c49..aee8895 100644 --- a/purchase_order_product_recommendation_supermarket/__init__.py +++ b/purchase_order_product_recommendation_supermarket/__init__.py @@ -1 +1,2 @@ +from . import models from . import wizards diff --git a/purchase_order_product_recommendation_supermarket/__manifest__.py b/purchase_order_product_recommendation_supermarket/__manifest__.py index 51393df..6797bee 100644 --- a/purchase_order_product_recommendation_supermarket/__manifest__.py +++ b/purchase_order_product_recommendation_supermarket/__manifest__.py @@ -9,6 +9,9 @@ "author": "Criptomart", "website": "https://criptomart.net", "depends": ["purchase_order_product_recommendation"], - "data": ["wizards/purchase_order_recommendation.xml"], + "data": [ + "wizards/purchase_order_recommendation.xml", + "views/product_template_view.xml", + ], "demo": [], } diff --git a/purchase_order_product_recommendation_supermarket/i18n/es.po b/purchase_order_product_recommendation_supermarket/i18n/es.po index 1ba61da..937d6f4 100644 --- a/purchase_order_product_recommendation_supermarket/i18n/es.po +++ b/purchase_order_product_recommendation_supermarket/i18n/es.po @@ -15,6 +15,31 @@ msgstr "" "Content-Transfer-Encoding: \n" "Plural-Forms: \n" +#. module: purchase_order_product_recommendation_supermarket +#: model:ir.model.fields,field_description:purchase_order_product_recommendation_supermarket.field_purchase_order_recommendation__include_previous_period +msgid "Include previous period stats" +msgstr "Incluir estadísticas del periodo previo" + +#. module: purchase_order_product_recommendation_supermarket +#: model:ir.model.fields,help:purchase_order_product_recommendation_supermarket.field_purchase_order_recommendation__include_previous_period +msgid "If disabled, the previous period (same number of days immediately preceding) is NOT queried. This saves a read_group on stock move lines and skips zero-stock day analysis for that window." +msgstr "Si se desactiva, no se consulta el periodo previo (mismo número de días inmediatamente anteriores). Ahorra tiempo en el cálculo al no consultar movimientos de stock y omite el análisis de días sin stock para esa ventana de tiempo." + +#. module: purchase_order_product_recommendation_supermarket +#: model:ir.model.fields,field_description:purchase_order_product_recommendation_supermarket.field_product_template__po_min_suggest_if_forecast_le_zero +msgid "Suggest minimum purchase when forecast <= 0" +msgstr "Sugerir compra mínima cuando el stock previsto <= 0" + +#. module: purchase_order_product_recommendation_supermarket +#: model:ir.model.fields,help:purchase_order_product_recommendation_supermarket.field_product_template__po_min_suggest_if_forecast_le_zero +msgid "If enabled, the purchase recommendation wizard will always propose at least 1 unit (or 1 full package when ordering by packages) when the forecasted stock is less or equal to 0." +msgstr "Si se activa, el asistente de recomendación de compras propondrá siempre al menos 1 unidad (o 1 paquete completo al pedir por paquetes) cuando el stock previsto sea menor o igual que 0." + +#. module: purchase_order_product_recommendation_supermarket +#: model_terms:ir.ui.view,arch_db:purchase_order_product_recommendation_supermarket.view_product_template_form_po_min_suggest +msgid "Purchase Recommendation" +msgstr "Recomendación de compra" + #. module: purchase_order_product_recommendation_supermarket #: model:ir.model.fields,help:purchase_order_product_recommendation_supermarket.field_purchase_order_recommendation_line__units_avg_delivered_prev msgid "Average daily consumption during the previous period" @@ -101,9 +126,9 @@ msgid "" "Indicate for how many days the new order should cover the stock. If not set," " the default module behavior is kept." msgstr "" -"Indica durante cuantos días el nuevo pedido debe cubrir el stock. Sino se " +"Indica durante cuantos días el nuevo pedido debe cubrir el stock. Si no se " "rellena este campo las recomendaciones mostradas se calcularán para cubrir " -"un periodo equivalente al mostrado en días totales." +"un periodo equivalente al mostrado en días analizados." #. module: purchase_order_product_recommendation_supermarket #: model:ir.model.fields,help:purchase_order_product_recommendation_supermarket.field_purchase_order_recommendation__order_by_packages diff --git a/purchase_order_product_recommendation_supermarket/i18n/purchase_order_product_recommendation_supermarket.pot b/purchase_order_product_recommendation_supermarket/i18n/purchase_order_product_recommendation_supermarket.pot index 33e561d..0f5845f 100644 --- a/purchase_order_product_recommendation_supermarket/i18n/purchase_order_product_recommendation_supermarket.pot +++ b/purchase_order_product_recommendation_supermarket/i18n/purchase_order_product_recommendation_supermarket.pot @@ -15,6 +15,31 @@ msgstr "" "Content-Transfer-Encoding: \n" "Plural-Forms: \n" +#. module: purchase_order_product_recommendation_supermarket +#: model:ir.model.fields,field_description:purchase_order_product_recommendation_supermarket.field_purchase_order_recommendation__include_previous_period +msgid "Include previous period stats" +msgstr "" + +#. module: purchase_order_product_recommendation_supermarket +#: model:ir.model.fields,help:purchase_order_product_recommendation_supermarket.field_purchase_order_recommendation__include_previous_period +msgid "If disabled, the previous period (same number of days immediately preceding) is NOT queried. This saves a read_group on stock move lines and skips zero-stock day analysis for that window." +msgstr "" + +#. module: purchase_order_product_recommendation_supermarket +#: model:ir.model.fields,field_description:purchase_order_product_recommendation_supermarket.field_product_template__po_min_suggest_if_forecast_le_zero +msgid "Suggest minimum purchase when forecast <= 0" +msgstr "" + +#. module: purchase_order_product_recommendation_supermarket +#: model:ir.model.fields,help:purchase_order_product_recommendation_supermarket.field_product_template__po_min_suggest_if_forecast_le_zero +msgid "If enabled, the purchase recommendation wizard will always propose at least 1 unit (or 1 full package when ordering by packages) when the forecasted stock is less or equal to 0." +msgstr "" + +#. module: purchase_order_product_recommendation_supermarket +#: model_terms:ir.ui.view,arch_db:purchase_order_product_recommendation_supermarket.view_product_template_form_po_min_suggest +msgid "Purchase Recommendation" +msgstr "" + #. module: purchase_order_product_recommendation_supermarket #: model:ir.model.fields,help:purchase_order_product_recommendation_supermarket.field_purchase_order_recommendation_line__units_avg_delivered_prev msgid "Average daily consumption during the previous period" diff --git a/purchase_order_product_recommendation_supermarket/models/__init__.py b/purchase_order_product_recommendation_supermarket/models/__init__.py new file mode 100644 index 0000000..e8fa8f6 --- /dev/null +++ b/purchase_order_product_recommendation_supermarket/models/__init__.py @@ -0,0 +1 @@ +from . import product_template diff --git a/purchase_order_product_recommendation_supermarket/models/product_template.py b/purchase_order_product_recommendation_supermarket/models/product_template.py new file mode 100644 index 0000000..e705777 --- /dev/null +++ b/purchase_order_product_recommendation_supermarket/models/product_template.py @@ -0,0 +1,10 @@ +from odoo import models, fields + + +class ProductTemplate(models.Model): + _inherit = 'product.template' + + po_min_suggest_if_forecast_le_zero = fields.Boolean( + string='Suggest minimum purchase when forecast <= 0', + help='If enabled, the purchase recommendation wizard will always propose at least 1 unit (or 1 full package when ordering by packages) when the forecasted stock is less or equal to 0.' + ) diff --git a/purchase_order_product_recommendation_supermarket/views/product_template_view.xml b/purchase_order_product_recommendation_supermarket/views/product_template_view.xml new file mode 100644 index 0000000..4d241d2 --- /dev/null +++ b/purchase_order_product_recommendation_supermarket/views/product_template_view.xml @@ -0,0 +1,15 @@ + + + + product.template.form.po.min.suggest + product.template + + + + + + + + + + diff --git a/purchase_order_product_recommendation_supermarket/wizards/purchase_order_recommendation.py b/purchase_order_product_recommendation_supermarket/wizards/purchase_order_recommendation.py index 6731a91..d8fd3c2 100644 --- a/purchase_order_product_recommendation_supermarket/wizards/purchase_order_recommendation.py +++ b/purchase_order_product_recommendation_supermarket/wizards/purchase_order_recommendation.py @@ -22,7 +22,7 @@ class PurchaseOrderRecommendationSupermarketWizard(models.TransientModel): ) include_previous_period = fields.Boolean( string="Include previous period stats", - default=True, + default=False, help="If disabled, the previous period (same number of days immediately preceding) is NOT queried. This saves a read_group on stock move lines and skips zero-stock day analysis for that window.", ) total_days = fields.Integer( @@ -181,6 +181,15 @@ class PurchaseOrderRecommendationSupermarketWizard(models.TransientModel): (self.order_days * res["units_avg_delivered"]) - res["units_virtual_available"], ) + + # Force a minimum suggested quantity when forecast <= 0 and product configured + # We apply this BEFORE packaging adjustment so packages logic can upscale it. + if ( + product_id.po_min_suggest_if_forecast_le_zero + and res["units_virtual_available"] <= 0 + ): + # If ordering by packages we later bump to one full package. + qty_to_order = max(qty_to_order, 1) res["units_included_original"] = qty_to_order # Adjust qty_to_order to packaging multiples if order_by_packages is checked