diff --git a/rma/models/rma_order_line.py b/rma/models/rma_order_line.py
index 0b81e348..de594f1e 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,
@@ -629,6 +630,25 @@ class RmaOrderLine(models.Model):
self.write({"state": "done"})
return True
+ 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
+
@api.model
def create(self, vals):
if not vals.get("name") or vals.get("name") == "/":
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"
+ />
+
@@ -485,4 +492,13 @@ if records.filtered(lambda x: x.state == "draft"):
+
+ Cancel
+
+
+ code
+
+ records.action_rma_cancel()
+
+