[ADD] migrate account_advanced_protection_features module to version 18

This commit is contained in:
2025-10-07 16:08:37 +02:00
parent 9cd897fb0c
commit b56abcd13b
12 changed files with 960 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
from . import account_move
from . import account_journal
from . import account_bank_statement

View File

@@ -0,0 +1,28 @@
from odoo import models, _
from odoo.exceptions import UserError
class AccountBankStatement(models.Model):
_inherit = "account.bank.statement"
def unlink(self):
for statement in self:
if not statement.journal_id.allow_bank_statement_deletion:
raise UserError(
_("The deletion of bank statements is not allowed for the journal %s.") % statement.journal_id.display_name
)
# we delete all the statement lines before deleting the statement itself
for line in statement.line_ids:
line.unlink()
return super(AccountBankStatement, self).unlink()
class AccountBankStatementLine(models.Model):
_inherit = "account.bank.statement.line"
def unlink(self):
for line in self:
if not line.journal_id.allow_bank_statement_deletion:
raise UserError(
_("The deletion of bank statement lines is not allowed for the journal %s.") % line.journal_id.display_name
)
return super(AccountBankStatementLine, self).unlink()

View File

@@ -0,0 +1,12 @@
from odoo import models, fields
class AccountJournal(models.Model):
_inherit = "account.journal"
prevent_reset_to_draft_sent_invoice = fields.Boolean("Prevent to reset to draft a sent invoice")
prevent_deletion_of_posted_account_move = fields.Boolean("Prevent to delete an already posted account move")
allow_bank_statement_deletion = fields.Boolean(
"Allow bank statements deletion",
help="Users with group Show Full Accounting Features (id: group_account_user) will be allowed to delete account bank statements "
"and bank statement lines."
)

View File

@@ -0,0 +1,23 @@
from odoo import models, api, fields, _
from odoo.exceptions import UserError
class AccountMove(models.Model):
_inherit = 'account.move'
def button_draft(self):
if self.is_move_sent and self.journal_id.prevent_reset_to_draft_sent_invoice:
raise UserError(_(
"You cannot reset to draft this invoice because it has been sent by email."
))
return super(AccountMove, self).button_draft()
@api.ondelete(at_uninstall=False)
def _check_posted(self):
""" Prevent deletion of an account move if it has already been posted and
journal parameter prevent_deletion_of_posted_account_move is activated
"""
for rec in self:
if rec.posted_before and rec.journal_id.prevent_deletion_of_posted_account_move:
raise UserError(_(
"You cannot delete this account move because it has already been posted."
))