Skip to content

Commit

Permalink
[16.0][IMP] rma: rma group state
Browse files Browse the repository at this point in the history
  • Loading branch information
chafique-delli authored and AaronHForgeFlow committed May 6, 2024
1 parent 88e803b commit 6f9117d
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 19 deletions.
46 changes: 29 additions & 17 deletions rma/models/rma_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -169,6 +165,7 @@ def _default_warehouse_id(self):
("to_approve", "To Approve"),
("approved", "Approved"),
("done", "Done"),
("cancel", "Cancel"),
],
default="draft",
store=True,
Expand Down Expand Up @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions rma/tests/test_rma.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
)
57 changes: 55 additions & 2 deletions rma/views/rma_order_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<field name="reference" />
<field name="partner_id" groups="base.group_user" string="Customer" />
<field name="date_rma" />
<field name="state" />
</tree>
</field>
</record>
Expand All @@ -22,6 +23,7 @@
<field name="reference" />
<field name="partner_id" groups="base.group_user" string="Supplier" />
<field name="date_rma" />
<field name="state" />
</tree>
</field>
</record>
Expand All @@ -31,7 +33,58 @@
<field name="model">rma.order</field>
<field name="arch" type="xml">
<form string="RMA">
<header />
<header>
<button
name="action_rma_to_approve"
type="object"
string="Request Approval"
attrs="{'invisible':[('state', '!=', 'draft')]}"
class="oe_highlight"
groups="rma.group_rma_customer_user"
/>
<button
name="action_rma_draft"
type="object"
string="Back to Draft"
attrs="{'invisible':[('state', '=', 'draft')]}"
groups="rma.group_rma_customer_user,rma.group_rma_supplier_user"
/>
<button
name="action_rma_approve"
type="object"
string="Approve"
attrs="{'invisible':[('state', '!=', 'to_approve')]}"
class="oe_highlight"
groups="rma.group_rma_manager"
/>
<button
name="action_rma_approve"
type="object"
string="Back to Approved"
attrs="{'invisible':[('state', '!=', 'done')]}"
groups="rma.group_rma_customer_user"
/>
<button
name="action_rma_done"
type="object"
string="Done"
attrs="{'invisible':[('state', 'in', ('done', 'draft', 'cancel'))]}"
groups="rma.group_rma_customer_user"
/>
<button
name="action_rma_cancel"
type="object"
string="Cancel"
attrs="{'invisible':[('state', 'in', ('done', 'cancel'))]}"
groups="rma.group_rma_customer_user"
/>
<field
name="state"
widget="statusbar"
statusbar_visible="draft,to_approve,approved,done"
nolabel="1"
/>
</header>
<sheet name='rma' string="RMA">
<div class="oe_button_box" name="button_box">
<button
Expand Down Expand Up @@ -186,7 +239,6 @@
create="0"
>
<field name="sequence" widget="handle" />
<field name="state" invisible="True" />
<field name="partner_id" invisible="True" />
<field name="product_id" />
<field
Expand All @@ -212,6 +264,7 @@
<field name="delivery_address_id" invisible="True" />
<field name="product_qty" />
<field name="price_unit" />
<field name="state" />
</tree>
</field>
</page>
Expand Down

0 comments on commit 6f9117d

Please sign in to comment.