From 4e33e3ad8e1604bd2b15b4843be22ba1d3ef6a37 Mon Sep 17 00:00:00 2001 From: Lois Rilo Date: Wed, 28 Dec 2022 13:11:19 +0100 Subject: [PATCH] [FIX] rma: Ensure that configuration on the operation is applied Without this, some policies are not being copied from the operation selected when creating new rma line from a rma group. In v16 this patch and the usage of such onchange can be removed in favor of (pre)computed stored editable fields for all policies and configuration in the RMA operation. --- rma/wizards/rma_add_serial.py | 8 ++++++- rma/wizards/rma_add_stock_move.py | 24 ++++++++++++++----- .../rma_order_line_make_supplier_rma.py | 8 ++++++- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/rma/wizards/rma_add_serial.py b/rma/wizards/rma_add_serial.py index b271f28e..41362be3 100644 --- a/rma/wizards/rma_add_serial.py +++ b/rma/wizards/rma_add_serial.py @@ -133,5 +133,11 @@ class RmaAddSerialWiz(models.TransientModel): ) vals = self._prepare_rma_line_from_lot_vals(lot) - rma_line_obj.create(vals) + rec = rma_line_obj.create(vals) + # Ensure that configuration on the operation is applied (like + # policies). + # TODO MIG: in v16 the usage of such onchange can be removed in + # favor of (pre)computed stored editable fields for all policies + # and configuration in the RMA operation. + rec._onchange_operation_id() return {"type": "ir.actions.act_window_close"} diff --git a/rma/wizards/rma_add_stock_move.py b/rma/wizards/rma_add_stock_move.py index 408f8a6b..40911194 100644 --- a/rma/wizards/rma_add_stock_move.py +++ b/rma/wizards/rma_add_stock_move.py @@ -158,9 +158,15 @@ class RmaAddStockMove(models.TransientModel): if sm not in existing_stock_moves or tracking_move: if sm.product_id.tracking == "none": data = self._prepare_rma_line_from_stock_move(sm, lot=False) - rma_line_obj.with_context(default_rma_id=self.rma_id.id).create( - data - ) + rec = rma_line_obj.with_context( + default_rma_id=self.rma_id.id + ).create(data) + # Ensure that configuration on the operation is applied (like + # policies). + # TODO MIG: in v16 the usage of such onchange can be removed in + # favor of (pre)computed stored editable fields for all policies + # and configuration in the RMA operation. + rec._onchange_operation_id() else: for lot in sm.move_line_ids.mapped("lot_id").filtered( lambda x: x.id in self.lot_ids.ids @@ -168,7 +174,13 @@ class RmaAddStockMove(models.TransientModel): if lot.id in self.rma_id.rma_line_ids.mapped("lot_id").ids: continue data = self._prepare_rma_line_from_stock_move(sm, lot) - rma_line_obj.with_context(default_rma_id=self.rma_id.id).create( - data - ) + rec = rma_line_obj.with_context( + default_rma_id=self.rma_id.id + ).create(data) + # Ensure that configuration on the operation is applied (like + # policies). + # TODO MIG: in v16 the usage of such onchange can be removed in + # favor of (pre)computed stored editable fields for all policies + # and configuration in the RMA operation. + rec._onchange_operation_id() return {"type": "ir.actions.act_window_close"} diff --git a/rma/wizards/rma_order_line_make_supplier_rma.py b/rma/wizards/rma_order_line_make_supplier_rma.py index bc95899a..57e27786 100644 --- a/rma/wizards/rma_order_line_make_supplier_rma.py +++ b/rma/wizards/rma_order_line_make_supplier_rma.py @@ -157,7 +157,13 @@ class RmaLineMakeSupplierRma(models.TransientModel): rma = rma_obj.create(rma_data) rma_line_data = self._prepare_supplier_rma_line(rma, item) - rma_line_obj.create(rma_line_data) + rec = rma_line_obj.create(rma_line_data) + # Ensure that configuration on the operation is applied (like + # policies). + # TODO MIG: in v16 the usage of such onchange can be removed in + # favor of (pre)computed stored editable fields for all policies + # and configuration in the RMA operation. + rec._onchange_operation_id() action = self.env.ref("rma.action_rma_supplier_lines") rma_lines = self.item_ids.mapped("line_id.supplier_rma_line_ids").ids result = action.sudo().read()[0]