[FIX] account: allow cancelling payment whith draft move

Payment journals have an option to keep moves unposted until bank statement
reconciliation.
When cancelling such payments, it is not necessary to attempt canceling the move
if it is unposted.
This patch allows cancelling such payments without needing to configure the
journal as cancellable while the move is still draft.

To reproduce:
1. check "Post at bank reconciliation" on a bank journal
2. do "Register payment" with that journal on a invoice
3. open the generated payment
4. click cancel => error "You cannot modify a posted entry of this journal..."

closes odoo/odoo#33312

Signed-off-by: Laurent Smet <smetl@users.noreply.github.com>
This commit is contained in:
Stéphane Bidoul (ACSONE)
2019-05-27 14:30:46 +00:00
committed by Martin Trigaux
parent 472bfdca56
commit 060e35f62a
+2 -1
View File
@@ -601,7 +601,8 @@ class account_payment(models.Model):
for move in rec.move_line_ids.mapped('move_id'):
if rec.invoice_ids:
move.line_ids.remove_move_reconcile()
move.button_cancel()
if move.state != 'draft':
move.button_cancel()
move.unlink()
rec.write({
'state': 'cancelled',