mirror of
https://github.com/ForgeFlow/stock-rma.git
synced 2025-01-21 12:57:49 +02:00
[16.0][IMP] rma: rma group state
This commit is contained in:
committed by
JasminSForgeFlow
parent
cd46134010
commit
c29d26fdba
@@ -45,23 +45,19 @@ class RmaOrder(models.Model):
|
|||||||
@api.depends("rma_line_ids", "rma_line_ids.state")
|
@api.depends("rma_line_ids", "rma_line_ids.state")
|
||||||
def _compute_state(self):
|
def _compute_state(self):
|
||||||
for rec in self:
|
for rec in self:
|
||||||
rma_line_done = self.env["rma.order.line"].search_count(
|
state = "draft"
|
||||||
[("id", "in", rec.rma_line_ids.ids), ("state", "=", "done")]
|
if rec.rma_line_ids:
|
||||||
)
|
states = set(rec.rma_line_ids.mapped("state"))
|
||||||
rma_line_approved = self.env["rma.order.line"].search_count(
|
if states == {"cancel"}:
|
||||||
[("id", "in", rec.rma_line_ids.ids), ("state", "=", "approved")]
|
state = "cancel"
|
||||||
)
|
elif "draft" in states:
|
||||||
rma_line_to_approve = self.env["rma.order.line"].search_count(
|
state = "draft"
|
||||||
[("id", "in", rec.rma_line_ids.ids), ("state", "=", "to_approve")]
|
elif "to_approved" in states:
|
||||||
)
|
state = "to_approved"
|
||||||
if rma_line_done != 0:
|
elif "approved" in states:
|
||||||
state = "done"
|
state = "approved"
|
||||||
elif rma_line_approved != 0:
|
else:
|
||||||
state = "approved"
|
state = "done"
|
||||||
elif rma_line_to_approve != 0:
|
|
||||||
state = "to_approve"
|
|
||||||
else:
|
|
||||||
state = "draft"
|
|
||||||
rec.state = state
|
rec.state = state
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
@@ -169,6 +165,7 @@ class RmaOrder(models.Model):
|
|||||||
("to_approve", "To Approve"),
|
("to_approve", "To Approve"),
|
||||||
("approved", "Approved"),
|
("approved", "Approved"),
|
||||||
("done", "Done"),
|
("done", "Done"),
|
||||||
|
("cancel", "Cancel"),
|
||||||
],
|
],
|
||||||
default="draft",
|
default="draft",
|
||||||
store=True,
|
store=True,
|
||||||
@@ -300,6 +297,21 @@ class RmaOrder(models.Model):
|
|||||||
result["res_id"] = related_lines[0]
|
result["res_id"] = related_lines[0]
|
||||||
return result
|
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")
|
@api.onchange("in_warehouse_id")
|
||||||
def _onchange_in_warehouse_id(self):
|
def _onchange_in_warehouse_id(self):
|
||||||
if self.in_warehouse_id and self.rma_line_ids:
|
if self.in_warehouse_id and self.rma_line_ids:
|
||||||
|
|||||||
@@ -1083,3 +1083,13 @@ class TestRma(common.TransactionCase):
|
|||||||
self.assertTrue(partner, "Partner is not defined or False")
|
self.assertTrue(partner, "Partner is not defined or False")
|
||||||
moves = picking.move_ids
|
moves = picking.move_ids
|
||||||
self.assertEqual(len(moves), 1, "Incorrect number of moves created")
|
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"]
|
||||||
|
)
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
<field name="reference" />
|
<field name="reference" />
|
||||||
<field name="partner_id" groups="base.group_user" string="Customer" />
|
<field name="partner_id" groups="base.group_user" string="Customer" />
|
||||||
<field name="date_rma" />
|
<field name="date_rma" />
|
||||||
|
<field name="state" />
|
||||||
</tree>
|
</tree>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
@@ -22,6 +23,7 @@
|
|||||||
<field name="reference" />
|
<field name="reference" />
|
||||||
<field name="partner_id" groups="base.group_user" string="Supplier" />
|
<field name="partner_id" groups="base.group_user" string="Supplier" />
|
||||||
<field name="date_rma" />
|
<field name="date_rma" />
|
||||||
|
<field name="state" />
|
||||||
</tree>
|
</tree>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
@@ -31,7 +33,58 @@
|
|||||||
<field name="model">rma.order</field>
|
<field name="model">rma.order</field>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<form string="RMA">
|
<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">
|
<sheet name='rma' string="RMA">
|
||||||
<div class="oe_button_box" name="button_box">
|
<div class="oe_button_box" name="button_box">
|
||||||
<button
|
<button
|
||||||
@@ -186,7 +239,6 @@
|
|||||||
create="0"
|
create="0"
|
||||||
>
|
>
|
||||||
<field name="sequence" widget="handle" />
|
<field name="sequence" widget="handle" />
|
||||||
<field name="state" invisible="True" />
|
|
||||||
<field name="partner_id" invisible="True" />
|
<field name="partner_id" invisible="True" />
|
||||||
<field name="product_id" />
|
<field name="product_id" />
|
||||||
<field
|
<field
|
||||||
@@ -212,6 +264,7 @@
|
|||||||
<field name="delivery_address_id" invisible="True" />
|
<field name="delivery_address_id" invisible="True" />
|
||||||
<field name="product_qty" />
|
<field name="product_qty" />
|
||||||
<field name="price_unit" />
|
<field name="price_unit" />
|
||||||
|
<field name="state" />
|
||||||
</tree>
|
</tree>
|
||||||
</field>
|
</field>
|
||||||
</page>
|
</page>
|
||||||
|
|||||||
Reference in New Issue
Block a user