From 18a46ce20423232f0458b2503abd5782d8b8ce42 Mon Sep 17 00:00:00 2001 From: mdietrichc2c Date: Wed, 26 Jul 2017 15:40:14 +0200 Subject: [PATCH] [IMP] account_payment_order: Don't allow deletion of an uploaded payment order + allow to cancel an uploaded payment order --- .../models/account_payment_order.py | 18 ++++++++++++++++++ .../views/account_payment_order.xml | 2 ++ 2 files changed, 20 insertions(+) diff --git a/account_payment_order/models/account_payment_order.py b/account_payment_order/models/account_payment_order.py index 3b1263607..c4ca51b6a 100644 --- a/account_payment_order/models/account_payment_order.py +++ b/account_payment_order/models/account_payment_order.py @@ -92,6 +92,14 @@ class AccountPaymentOrder(models.Model): 'account.move', 'payment_order_id', string='Journal Entries', readonly=True) + @api.multi + def unlink(self): + for order in self: + if order.state == 'uploaded': + raise ValidationError(_( + "You cannot delete an uploaded payment order. You can " + "cancel it in order to do so.")) + @api.multi @api.constrains('payment_type', 'payment_mode_id') def payment_order_constraints(self): @@ -173,6 +181,16 @@ class AccountPaymentOrder(models.Model): }) return True + @api.multi + def action_done_cancel(self): + for move in self.move_ids: + move.button_cancel() + for move_line in move.line_ids: + move_line.remove_move_reconcile() + move.unlink() + self.action_cancel() + return True + @api.multi def cancel2draft(self): self.write({'state': 'draft'}) diff --git a/account_payment_order/views/account_payment_order.xml b/account_payment_order/views/account_payment_order.xml index 2318237c3..bfa639387 100644 --- a/account_payment_order/views/account_payment_order.xml +++ b/account_payment_order/views/account_payment_order.xml @@ -21,6 +21,8 @@ string="Back to Draft" />