diff --git a/rma/models/rma_order.py b/rma/models/rma_order.py
index edd4d5637..14f95c298 100644
--- a/rma/models/rma_order.py
+++ b/rma/models/rma_order.py
@@ -45,23 +45,19 @@ def _compute_line_count(self):
@api.depends("rma_line_ids", "rma_line_ids.state")
def _compute_state(self):
for rec in self:
- rma_line_done = self.env["rma.order.line"].search_count(
- [("id", "in", rec.rma_line_ids.ids), ("state", "=", "done")]
- )
- rma_line_approved = self.env["rma.order.line"].search_count(
- [("id", "in", rec.rma_line_ids.ids), ("state", "=", "approved")]
- )
- rma_line_to_approve = self.env["rma.order.line"].search_count(
- [("id", "in", rec.rma_line_ids.ids), ("state", "=", "to_approve")]
- )
- if rma_line_done != 0:
- state = "done"
- elif rma_line_approved != 0:
- state = "approved"
- elif rma_line_to_approve != 0:
- state = "to_approve"
- else:
- state = "draft"
+ state = "draft"
+ if rec.rma_line_ids:
+ states = set(rec.rma_line_ids.mapped("state"))
+ if states == {"cancel"}:
+ state = "cancel"
+ elif "draft" in states:
+ state = "draft"
+ elif "to_approved" in states:
+ state = "to_approved"
+ elif "approved" in states:
+ state = "approved"
+ else:
+ state = "done"
rec.state = state
@api.model
@@ -169,6 +165,7 @@ def _default_warehouse_id(self):
("to_approve", "To Approve"),
("approved", "Approved"),
("done", "Done"),
+ ("cancel", "Cancel"),
],
default="draft",
store=True,
@@ -300,6 +297,21 @@ def action_view_supplier_lines(self):
result["res_id"] = related_lines[0]
return result
+ def action_rma_to_approve(self):
+ return self.rma_line_ids.action_rma_to_approve()
+
+ def action_rma_draft(self):
+ return self.rma_line_ids.action_rma_draft()
+
+ def action_rma_approve(self):
+ return self.rma_line_ids.action_rma_approve()
+
+ def action_rma_done(self):
+ return self.rma_line_ids.action_rma_done()
+
+ def action_rma_cancel(self):
+ return self.rma_line_ids.action_rma_cancel()
+
@api.onchange("in_warehouse_id")
def _onchange_in_warehouse_id(self):
if self.in_warehouse_id and self.rma_line_ids:
diff --git a/rma/tests/test_rma.py b/rma/tests/test_rma.py
index 35059202f..5ab4bbd40 100644
--- a/rma/tests/test_rma.py
+++ b/rma/tests/test_rma.py
@@ -1083,3 +1083,13 @@ def test_08_supplier_rma_single_line(self):
self.assertTrue(partner, "Partner is not defined or False")
moves = picking.move_ids
self.assertEqual(len(moves), 1, "Incorrect number of moves created")
+
+ def test_09_rma_state(self):
+ rma = self.rma_customer_id
+ self.assertEqual(rma.state, "approved")
+ rma.rma_line_ids.action_rma_draft()
+ self.assertEqual(rma.state, "draft")
+ rma.action_rma_approve()
+ self.assertEqual(
+ rma.rma_line_ids.mapped("state"), ["approved", "approved", "approved"]
+ )
diff --git a/rma/views/rma_order_view.xml b/rma/views/rma_order_view.xml
index 7a042423c..1333c70a0 100644
--- a/rma/views/rma_order_view.xml
+++ b/rma/views/rma_order_view.xml
@@ -9,6 +9,7 @@
+
@@ -22,6 +23,7 @@
+
@@ -31,7 +33,58 @@
rma.order