From c1cc54eee281c7ef6a7bbe3d9828d03c98a6cf37 Mon Sep 17 00:00:00 2001 From: Lois Rilo Date: Mon, 24 Jul 2023 13:03:58 +0000 Subject: [PATCH] [IMP] stock: add hook method to control skipped procurements closes odoo/odoo#129389 Signed-off-by: William Henrotin (whe) --- addons/stock/models/stock_rule.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/addons/stock/models/stock_rule.py b/addons/stock/models/stock_rule.py index e62d501c5fc..72c4abc76cd 100644 --- a/addons/stock/models/stock_rule.py +++ b/addons/stock/models/stock_rule.py @@ -411,6 +411,12 @@ class ProcurementGroup(models.Model): required=True) stock_move_ids = fields.One2many('stock.move', 'group_id', string="Related Stock Moves") + @api.model + def _skip_procurement(self, procurement): + return procurement.product_id.type not in ("consu", "product") or float_is_zero( + procurement.product_qty, precision_rounding=procurement.product_uom.rounding + ) + @api.model def run(self, procurements, raise_user_error=True): """Fulfil `procurements` with the help of stock rules. @@ -441,10 +447,7 @@ class ProcurementGroup(models.Model): procurement.values.setdefault('company_id', procurement.location_id.company_id) procurement.values.setdefault('priority', '0') procurement.values.setdefault('date_planned', fields.Datetime.now()) - if ( - procurement.product_id.type not in ('consu', 'product') or - float_is_zero(procurement.product_qty, precision_rounding=procurement.product_uom.rounding) - ): + if self._skip_procurement(procurement): continue rule = self._get_rule(procurement.product_id, procurement.location_id, procurement.values) if not rule: