diff --git a/account_advanced_protection_features/models/__init__.py b/account_advanced_protection_features/models/__init__.py index ea6d653..c5a0293 100644 --- a/account_advanced_protection_features/models/__init__.py +++ b/account_advanced_protection_features/models/__init__.py @@ -1,2 +1,3 @@ from . import account_move from . import account_journal +from . import account_bank_statement diff --git a/account_advanced_protection_features/models/account_bank_statement.py b/account_advanced_protection_features/models/account_bank_statement.py new file mode 100644 index 0000000..e867a00 --- /dev/null +++ b/account_advanced_protection_features/models/account_bank_statement.py @@ -0,0 +1,13 @@ +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( + _(f"The deletion of bank statements is not allowed for the journal {statement.journal_id.display_name}.") + ) + return super(AccountBankStatement, self).unlink() diff --git a/account_advanced_protection_features/models/account_journal.py b/account_advanced_protection_features/models/account_journal.py index 5bd793e..9a2c628 100644 --- a/account_advanced_protection_features/models/account_journal.py +++ b/account_advanced_protection_features/models/account_journal.py @@ -5,3 +5,4 @@ class AccountJournal(models.Model): 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 statement deletion") diff --git a/account_advanced_protection_features/views/account_journal_views.xml b/account_advanced_protection_features/views/account_journal_views.xml index d5d1f67..28a0832 100644 --- a/account_advanced_protection_features/views/account_journal_views.xml +++ b/account_advanced_protection_features/views/account_journal_views.xml @@ -13,6 +13,10 @@ name="prevent_reset_to_draft_sent_invoice" attrs="{'invisible': [('type', '!=', 'sale')]}" /> +