mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
[13.0][FIX] Remove wrong account_document_reversal to fix the broken branch.
https://github.com/OCA/account-financial-tools/pull/965
This commit is contained in:
@@ -1,37 +0,0 @@
|
||||
# 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, fields
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
|
||||
class AccountPayment(models.Model):
|
||||
_name = "account.payment"
|
||||
_inherit = ["account.payment", "account.document.reversal"]
|
||||
|
||||
def cancel_reversal(self):
|
||||
return self.reverse_document_wizard()
|
||||
|
||||
def action_draft(self):
|
||||
""" Case cancel reversal, set to draft allowed only when no moves """
|
||||
for rec in self:
|
||||
if rec.is_cancel_reversal and rec.move_line_ids:
|
||||
raise UserError(_("Cannot set to draft!"))
|
||||
return super().action_draft()
|
||||
|
||||
def action_document_reversal(self, date=None, journal_id=None):
|
||||
""" Reverse all moves related to this payment + set state to cancel """
|
||||
# Check document readiness
|
||||
valid_state = len(self.mapped("state")) == 1 and \
|
||||
list(set(self.mapped("state")))[0] == "posted"
|
||||
if not valid_state:
|
||||
raise UserError(
|
||||
_("Only validated document can be cancelled (reversal)"))
|
||||
# Find moves to get reversed
|
||||
move_lines = self.mapped("move_line_ids").filtered(
|
||||
lambda x: x.journal_id == self.mapped("journal_id")[0])
|
||||
moves = move_lines.mapped("move_id")
|
||||
# Create reverse entries
|
||||
moves._cancel_reversal(journal_id)
|
||||
# Set state cancelled and unlink with account.move
|
||||
self.write({"state": "cancelled"})
|
||||
return True
|
||||
Reference in New Issue
Block a user