[16.0][IMP] rma: rma group state

This commit is contained in:
chafique.delli
2024-03-25 12:35:44 +01:00
committed by JasminSForgeFlow
parent cd46134010
commit c29d26fdba
3 changed files with 94 additions and 19 deletions

View File

@@ -45,23 +45,19 @@ class RmaOrder(models.Model):
@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 @@ class RmaOrder(models.Model):
("to_approve", "To Approve"),
("approved", "Approved"),
("done", "Done"),
("cancel", "Cancel"),
],
default="draft",
store=True,
@@ -300,6 +297,21 @@ class RmaOrder(models.Model):
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:

View File

@@ -1083,3 +1083,13 @@ class TestRma(common.TransactionCase):
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"]
)

View File

@@ -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>
@@ -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>
@@ -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
@@ -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
@@ -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>