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