mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
[12.0][ADD] account_document_reversal
This commit is contained in:
committed by
Jordi Ballester Alomar
parent
3a53ba8f7d
commit
0e44a9de54
40
account_document_reversal/models/account_payment.py
Normal file
40
account_document_reversal/models/account_payment.py
Normal file
@@ -0,0 +1,40 @@
|
||||
# Copyright 2019 Ecosoft Co., Ltd (http://ecosoft.co.th/)
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)
|
||||
from odoo import api, models, _
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class AccountPayment(models.Model):
|
||||
_name = 'account.payment'
|
||||
_inherit = ['account.payment', 'account.document.reversal']
|
||||
|
||||
@api.multi
|
||||
def cancel(self):
|
||||
""" If cancel method is to reverse, use document reversal wizard """
|
||||
cancel_reversal = all(
|
||||
self.mapped('move_line_ids.move_id.journal_id.is_cancel_reversal'))
|
||||
states = self.mapped('state')
|
||||
if cancel_reversal and 'draft' not in states:
|
||||
return self.reverse_document_wizard()
|
||||
return super().cancel()
|
||||
|
||||
@api.multi
|
||||
def action_document_reversal(self, date=None, journal_id=None):
|
||||
""" Reverse all moves related to this payment + set state to cancel """
|
||||
# Check document state
|
||||
if 'cancelled' in self.mapped('state'):
|
||||
raise ValidationError(
|
||||
_('You are trying to cancel the cancelled document'))
|
||||
move_lines = self.mapped('move_line_ids')
|
||||
moves = move_lines.mapped('move_id')
|
||||
# Set all moves to unreconciled
|
||||
move_lines.filtered(lambda x:
|
||||
x.account_id.reconcile).remove_move_reconcile()
|
||||
# Important to remove relation with move.line before reverse
|
||||
move_lines.write({'payment_id': False})
|
||||
# Create reverse entries
|
||||
moves.reverse_moves(date, journal_id)
|
||||
# Set state cancelled and unlink with account.move
|
||||
self.write({'move_name': False,
|
||||
'state': 'cancelled'})
|
||||
return True
|
||||
Reference in New Issue
Block a user