diff --git a/account_payment_order/models/account_payment_order.py b/account_payment_order/models/account_payment_order.py
index 6badcc8da..46ca03f13 100644
--- a/account_payment_order/models/account_payment_order.py
+++ b/account_payment_order/models/account_payment_order.py
@@ -95,6 +95,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):
@@ -175,6 +183,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 cbddbe024..5d699245e 100644
--- a/account_payment_order/views/account_payment_order.xml
+++ b/account_payment_order/views/account_payment_order.xml
@@ -22,6 +22,8 @@
string="Back to Draft" />
+