From 24cb7c4c32fe43d2ac4f5acac04b39c5e0cae40d Mon Sep 17 00:00:00 2001 From: David Date: Thu, 9 Mar 2023 17:03:01 +0100 Subject: [PATCH 1/2] [FIX] rma_sale_mrp: avoid reopening of kit RMAs As we rely on the kit_qty field have the kit/component relation an that's computed when the RMA is created, we want to avoid reopening the RMA to avoid inconsitencies. The user should create a new RMA. TT41943 --- rma_sale_mrp/models/rma.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/rma_sale_mrp/models/rma.py b/rma_sale_mrp/models/rma.py index 0fbf87b2..2ce607fb 100644 --- a/rma_sale_mrp/models/rma.py +++ b/rma_sale_mrp/models/rma.py @@ -62,3 +62,13 @@ class Rma(models.Model): "state": "refunded", } ) + + def action_draft(self): + if self.filtered(lambda r: r.state == "cancelled" and r.phantom_bom_product): + raise UserError( + _( + "To avoid kit quantities inconsistencies it is not possible to convert " + "to draft a cancelled RMA. You should do a new one from the sales order." + ) + ) + return super().action_draft() From 056c06ad3b563e94d6caba8f0310ff234ebfc306 Mon Sep 17 00:00:00 2001 From: David Date: Thu, 9 Mar 2023 17:29:45 +0100 Subject: [PATCH 2/2] [FIX] rma: avoid reopening a cancelled RMA when the reception is deleted When we delete the reception for an RMA, we're setting it to draft automatically so we can confirm it again and create a new reception. This is unconvenient when the RMA is cancelled, as we don't wan't to reopen it automatically. TT41943 --- rma/models/stock_move.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rma/models/stock_move.py b/rma/models/stock_move.py index 38f416e5..01df6b8b 100644 --- a/rma/models/stock_move.py +++ b/rma/models/stock_move.py @@ -28,7 +28,9 @@ class StockMove(models.Model): rma_receiver = self.sudo().mapped("rma_receiver_ids") rma = self.sudo().mapped("rma_id") res = super().unlink() - rma_receiver.write({"state": "draft"}) + rma_receiver.filtered(lambda x: x.state != "cancelled").write( + {"state": "draft"} + ) rma.update_received_state() rma.update_replaced_state() return res