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"
+ />
+
@@ -485,4 +492,13 @@ if records.filtered(lambda x: x.state == "draft"):
+
+ Cancel
+
+
+ code
+
+ records.action_rma_cancel()
+
+