[IMP] account_advanced_protection_features: use is_move_sent field to prevent_reset_to_draft_sent_invoice

This commit is contained in:
2025-08-29 09:26:42 +02:00
parent 581589afc8
commit 2bef8b4e0c
3 changed files with 2 additions and 20 deletions

View File

@@ -4,15 +4,12 @@ from odoo.exceptions import UserError
class AccountMove(models.Model): class AccountMove(models.Model):
_inherit = 'account.move' _inherit = 'account.move'
sent_by_email = fields.Boolean()
def button_draft(self): def button_draft(self):
res = super(AccountMove, self).button_draft() if self.is_move_sent and self.journal_id.prevent_reset_to_draft_sent_invoice:
if self.sent_by_email and self.journal_id.prevent_reset_to_draft_sent_invoice:
raise UserError(_( raise UserError(_(
"You cannot reset to draft this invoice because it has been sent by email." "You cannot reset to draft this invoice because it has been sent by email."
)) ))
return res return super(AccountMove, self).button_draft()
@api.ondelete(at_uninstall=False) @api.ondelete(at_uninstall=False)
def _check_posted(self): def _check_posted(self):

View File

@@ -1 +0,0 @@
from . import account_invoice_send

View File

@@ -1,14 +0,0 @@
# -*- coding: utf-8 -*-
from odoo import api, fields, models, _
class AccountInvoiceSend(models.TransientModel):
_inherit = 'account.invoice.send'
def send_and_print_action(self):
if self.model == "account.move":
move = self.env[self.model].browse(self.res_id)
move.sent_by_email = True
return super(AccountInvoiceSend, self).send_and_print_action()