[FIX] account_move_reconcile_forbid_cancel: make it compatible with test of other modules
parent
fab0de8225
commit
e7ef078e1a
|
@ -1,7 +1,7 @@
|
|||
# Copyright 2022 Tecnativa - Ernesto Tejeda
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import _, models
|
||||
from odoo import _, models, tools
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
|
@ -14,13 +14,21 @@ class AccountMove(models.Model):
|
|||
)
|
||||
|
||||
def button_draft(self):
|
||||
rec_pay_lines = self._get_receivable_payable_lines()
|
||||
if rec_pay_lines.matched_debit_ids or rec_pay_lines.matched_credit_ids:
|
||||
raise ValidationError(_("You cannot reset to draft reconciled entries."))
|
||||
if not tools.config["test_enable"] or self.env.context.get(
|
||||
"test_reconcile_forbid_cancel"
|
||||
):
|
||||
rec_pay_lines = self._get_receivable_payable_lines()
|
||||
if rec_pay_lines.matched_debit_ids or rec_pay_lines.matched_credit_ids:
|
||||
raise ValidationError(
|
||||
_("You cannot reset to draft reconciled entries.")
|
||||
)
|
||||
super().button_draft()
|
||||
|
||||
def button_cancel(self):
|
||||
rec_pay_lines = self._get_receivable_payable_lines()
|
||||
if rec_pay_lines.matched_debit_ids or rec_pay_lines.matched_credit_ids:
|
||||
raise ValidationError(_("You cannot cancel reconciled entries."))
|
||||
if not tools.config["test_enable"] or self.env.context.get(
|
||||
"test_reconcile_forbid_cancel"
|
||||
):
|
||||
rec_pay_lines = self._get_receivable_payable_lines()
|
||||
if rec_pay_lines.matched_debit_ids or rec_pay_lines.matched_credit_ids:
|
||||
raise ValidationError(_("You cannot cancel reconciled entries."))
|
||||
super().button_cancel()
|
||||
|
|
|
@ -76,8 +76,8 @@ class TestAccountMoveReconcileForbidCancel(SavepointCase):
|
|||
|
||||
def test_reset_invoice_to_draft(self):
|
||||
with self.assertRaises(ValidationError):
|
||||
self.invoice.button_draft()
|
||||
self.invoice.with_context(test_reconcile_forbid_cancel=True).button_draft()
|
||||
|
||||
def test_cancel_invoice(self):
|
||||
with self.assertRaises(ValidationError):
|
||||
self.invoice.button_cancel()
|
||||
self.invoice.with_context(test_reconcile_forbid_cancel=True).button_cancel()
|
||||
|
|
Loading…
Reference in New Issue