From ed24b99ee6c31c5b1252b0401e40fab654d8a296 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Carreras Date: Fri, 20 Dec 2024 11:11:21 -0300 Subject: [PATCH] [FIX] stock_secondary_unit: partial delivery --- stock_secondary_unit/models/__init__.py | 1 + stock_secondary_unit/models/stock_picking.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 stock_secondary_unit/models/stock_picking.py diff --git a/stock_secondary_unit/models/__init__.py b/stock_secondary_unit/models/__init__.py index d342115d5a6d..9e594bcca7bd 100644 --- a/stock_secondary_unit/models/__init__.py +++ b/stock_secondary_unit/models/__init__.py @@ -4,3 +4,4 @@ from . import product_product from . import product_template from . import stock_move +from . import stock_picking diff --git a/stock_secondary_unit/models/stock_picking.py b/stock_secondary_unit/models/stock_picking.py new file mode 100644 index 000000000000..6d1abe39fdfb --- /dev/null +++ b/stock_secondary_unit/models/stock_picking.py @@ -0,0 +1,18 @@ +from odoo import models + +class StockPicking(models.Model): + _inherit = "stock.picking" + + def _create_backorder(self): + res = super(StockPicking, self)._create_backorder() + for original_move in self.move_ids: + corresponding_move = next((move for move in res.move_ids if move.product_id == original_move.product_id), None) + if corresponding_move and corresponding_move.secondary_uom_qty: + # To avoid rounding errors, Saving the current value of product_uom_qty + # before recalculating the secondary unit. Afterward, I'll restore the original value + product_uom_qty = corresponding_move.product_uom_qty + corresponding_move.with_context(bypass_compute_field_qty=True)._compute_secondary_uom_qty() + corresponding_move.product_uom_qty = product_uom_qty + else: + continue + return res