bank-payment/account_payment_order_lock_draft/models/account_move.py

35 lines
1.1 KiB
Python
Raw Permalink Normal View History

2024-08-26 14:11:32 +00:00
# Copyright 2024 - TODAY, Kaynnan Lemes <kaynnan.lemes@escflectra.com.br>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
# flake8: noqa: B950
from flectra import _, models
from flectra.exceptions import UserError
class AccountMove(models.Model):
_inherit = "account.move"
def button_draft(self):
"""Handles the action of resetting entries to draft status.
Performs the operation of resetting entries to draft status. It iterates
through each entry, verifies if any associated payment order, and raises a UserError if so, preventing the reset operation.
Raises:
UserError: If an entry is associated with a Payment Order
"""
super().button_draft()
for move in self:
if (
self.env["account.move"]
.sudo()
.browse(move.id)
.line_ids.filtered(lambda line: line.payment_line_ids)
):
raise UserError(
_(
"You can't reset to draft because it's already associated with a Payment Order."
)
)