Files
account-tools/account_advanced_protection_features/models/account_bank_statement.py

55 lines
2.2 KiB
Python

from odoo import api, 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"
@api.model
def default_get(self, fields_list):
res = super().default_get(fields_list)
journal_id = self._context.get('default_journal_id') or res.get('journal_id')
if journal_id:
journal = self.env["account.journal"].browse(journal_id)
if not journal.allow_bank_statement_line_creation:
raise UserError(
_("Manual creation of bank statement lines is not allowed for the journal %s.")
% journal.display_name
)
return res
@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
journal_id = vals.get("journal_id")
if journal_id:
journal = self.env["account.journal"].browse(journal_id)
if not journal.allow_bank_statement_line_creation:
raise UserError(
_("Manual creation of bank statement lines is not allowed for the journal %s.")
% journal.display_name
)
return super().create(vals_list)
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()