[IMP] rma: cancel rma_lines

This commit is contained in:
DavidJForgeFlow
2023-02-14 17:31:07 +01:00
parent 7ce2e72ec5
commit 7c414b9ff5
2 changed files with 38 additions and 1 deletions

View File

@@ -231,6 +231,7 @@ class RmaOrderLine(models.Model):
("to_approve", "To Approve"), ("to_approve", "To Approve"),
("approved", "Approved"), ("approved", "Approved"),
("done", "Done"), ("done", "Done"),
("canceled", "Canceled"),
], ],
string="State", string="State",
default="draft", default="draft",
@@ -620,6 +621,25 @@ class RmaOrderLine(models.Model):
self.write({"state": "done"}) self.write({"state": "done"})
return True return True
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
@api.model @api.model
def create(self, vals): def create(self, vals):
if not vals.get("name") or vals.get("name") == "/": if not vals.get("name") or vals.get("name") == "/":

View File

@@ -318,7 +318,14 @@
name="action_rma_done" name="action_rma_done"
type="object" type="object"
string="Done" string="Done"
attrs="{'invisible':[('state', 'in', ('done', 'draft'))]}" attrs="{'invisible':[('state', 'in', ('done', 'draft', 'canceled'))]}"
groups="rma.group_rma_customer_user"
/>
<button
name="action_rma_cancel"
type="object"
string="Cancel"
attrs="{'invisible':[('state', 'in', ('done', 'canceled'))]}"
groups="rma.group_rma_customer_user" groups="rma.group_rma_customer_user"
/> />
<field name="state" widget="statusbar" nolabel="1" /> <field name="state" widget="statusbar" nolabel="1" />
@@ -682,5 +689,15 @@ if records.filtered(lambda x: x.state == "draft"):
</field> </field>
</record> </record>
<record model="ir.actions.server" id="action_request_cancel_rma_order_line">
<field name="name">Cancel</field>
<field name="model_id" ref="rma.model_rma_order_line" />
<field name="binding_model_id" ref="rma.model_rma_order_line" />
<field name="state">code</field>
<field name="code">
records.action_rma_cancel()
</field>
</record>
</data> </data>
</odoo> </odoo>