[IMP] rma: cancel rma_lines

This commit is contained in:
DavidJForgeFlow
2023-02-14 17:31:07 +01:00
parent 7d10c1dddd
commit 341fe67390
2 changed files with 37 additions and 1 deletions

View File

@@ -244,6 +244,7 @@ class RmaOrderLine(models.Model):
("to_approve", "To Approve"), ("to_approve", "To Approve"),
("approved", "Approved"), ("approved", "Approved"),
("done", "Done"), ("done", "Done"),
("canceled", "Canceled"),
], ],
default="draft", default="draft",
tracking=True, tracking=True,
@@ -652,6 +653,25 @@ class RmaOrderLine(models.Model):
) )
return super().create(vals_list) return super().create(vals_list)
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
def _get_price_unit(self): def _get_price_unit(self):
"""The price unit corresponds to the cost of that product""" """The price unit corresponds to the cost of that product"""
self.ensure_one() self.ensure_one()

View File

@@ -89,7 +89,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" />
@@ -485,4 +492,13 @@ 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>
</odoo> </odoo>