From fb683c9aa5c46a14cf16f962d7ac46fbb832b1ba Mon Sep 17 00:00:00 2001 From: DavidJForgeFlow Date: Tue, 14 Feb 2023 17:31:07 +0100 Subject: [PATCH] [IMP] rma: cancel rma_lines --- rma/models/rma_order_line.py | 20 ++++++++++++++++++++ rma/views/rma_order_line_view.xml | 18 +++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/rma/models/rma_order_line.py b/rma/models/rma_order_line.py index 117d03df..f8b3ff6f 100644 --- a/rma/models/rma_order_line.py +++ b/rma/models/rma_order_line.py @@ -244,6 +244,7 @@ class RmaOrderLine(models.Model): ("to_approve", "To Approve"), ("approved", "Approved"), ("done", "Done"), + ("canceled", "Canceled"), ], default="draft", tracking=True, @@ -652,6 +653,25 @@ class RmaOrderLine(models.Model): ) return super().create(vals_list) + def check_cancel(self): + for move in self.move_ids: + if move.state == "done": + raise UserError( + _("Unable to cancel %s as some receptions have already been done.") + % (self.name) + ) + + def action_rma_cancel(self): + for order in self: + order.check_cancel() + order.write({"state": "canceled"}) + order.move_ids._action_cancel() + shipments = order._get_in_pickings() + shipments |= order._get_out_pickings() + for ship in shipments: + ship.action_cancel() + return True + def _get_price_unit(self): """The price unit corresponds to the cost of that product""" self.ensure_one() diff --git a/rma/views/rma_order_line_view.xml b/rma/views/rma_order_line_view.xml index 21a08327..7ee4d84a 100644 --- a/rma/views/rma_order_line_view.xml +++ b/rma/views/rma_order_line_view.xml @@ -89,7 +89,14 @@ name="action_rma_done" type="object" string="Done" - attrs="{'invisible':[('state', 'in', ('done', 'draft'))]}" + attrs="{'invisible':[('state', 'in', ('done', 'draft', 'canceled'))]}" + groups="rma.group_rma_customer_user" + /> +