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..06719318 100644 --- a/rma/views/rma_order_line_view.xml +++ b/rma/views/rma_order_line_view.xml @@ -86,13 +86,18 @@ groups="rma.group_rma_customer_user" />