IMP] account_advanced_protection_features: add option allow_bank_statement_line_creation

This commit is contained in:
2026-01-20 19:03:24 +01:00
parent a948a466cc
commit fefd9a6a34
8 changed files with 103 additions and 9 deletions

View File

@@ -3,9 +3,12 @@ account_advanced_protection_features
====================================
This module adds several protection features about accounting :
* Forbid to delete an invoice that has already been validated
* Forbid to reset to draft an invoice that has already been sent by email
* Allow bank statements and bank statement lines deletion
* Forbid bank statements and bank statement lines deletion. You can allow it per journal.
* Forbid manual bank statement lines creation. You can allow it per journal.
* Per journal, add the option to forbid to delete an invoice that has already been validated.
* Per journal, add the option to forbid to reset to draft an invoice that has already been sent by email.
Installation
============

View File

@@ -2,7 +2,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "account_advanced_protection_features",
"name": "Account advanced protection features",
"version": "16.0.1.0.0",
"author": "Elabore",
"website": "https://elabore.coop",

View File

@@ -6,8 +6,8 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-08-29 08:28+0000\n"
"PO-Revision-Date: 2025-08-29 08:28+0000\n"
"POT-Creation-Date: 2026-01-20 16:50+0000\n"
"PO-Revision-Date: 2026-01-20 16:50+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
@@ -25,6 +25,11 @@ msgstr "Accès aux fonctionnalités avancées de protection des journaux"
msgid "Allow bank statements deletion"
msgstr "Autoriser la suppression de relevé bancaire"
#. module: account_advanced_protection_features
#: model:ir.model.fields,field_description:account_advanced_protection_features.field_account_journal__allow_bank_statement_line_creation
msgid "Allow manual bank statement lines creation"
msgstr "Autoriser l'ajout manuelle des lignes de relevé bancaire"
#. module: account_advanced_protection_features
#: model:ir.model,name:account_advanced_protection_features.model_account_bank_statement
msgid "Bank Statement"
@@ -35,6 +40,13 @@ msgstr "Relevé bancaire"
msgid "Bank Statement Line"
msgstr "Ligne de relevé de compte"
#. module: account_advanced_protection_features
#: model:ir.model.fields,help:account_advanced_protection_features.field_account_journal__allow_bank_statement_line_creation
msgid ""
"If unchecked, users will not be allowed to manually create bank statement "
"lines for this journal."
msgstr "Si décoché, les utilisateurs ne seront pas autorisés à créer des lignes de relevé bancaire pour ce journal."
#. module: account_advanced_protection_features
#: model:ir.model,name:account_advanced_protection_features.model_account_journal
msgid "Journal"
@@ -45,6 +57,16 @@ msgstr ""
msgid "Journal Entry"
msgstr "Pièce comptable"
#. module: account_advanced_protection_features
#. odoo-python
#: code:addons/account_advanced_protection_features/models/account_bank_statement.py:0
#: code:addons/account_advanced_protection_features/models/account_bank_statement.py:0
#, python-format
msgid ""
"Manual creation of bank statement lines is not allowed for the journal %s."
msgstr ""
"La création manuelle de lignes de relevé bancaire n'est pas autorisée pour le journal %s."
#. module: account_advanced_protection_features
#: model:ir.model.fields,field_description:account_advanced_protection_features.field_account_journal__prevent_deletion_of_posted_account_move
msgid "Prevent to delete an already posted account move"
@@ -66,15 +88,18 @@ msgstr ""
#. module: account_advanced_protection_features
#. odoo-python
#: code:addons/account_advanced_protection_features/models/account_bank_statement.py:0
#: code:addons/account_advanced_protection_features/models/account_bank_statement.py:0
#, python-format
msgid ""
"The deletion of bank statement lines is not allowed for the journal %s."
msgstr ""
"La suppression des lignes de relevé bancaire n'est pas autorisée pour le journal %s."
"La suppression des lignes de relevé bancaire n'est pas autorisée pour le "
"journal %s."
#. module: account_advanced_protection_features
#. odoo-python
#: code:addons/account_advanced_protection_features/models/account_bank_statement.py:0
#: code:addons/account_advanced_protection_features/models/account_bank_statement.py:0
#, python-format
msgid "The deletion of bank statements is not allowed for the journal %s."
msgstr ""
@@ -93,8 +118,10 @@ msgstr ""
#. module: account_advanced_protection_features
#. odoo-python
#: code:addons/account_advanced_protection_features/models/account_move.py:0
#: code:addons/account_advanced_protection_features/models/account_move.py:0
#, python-format
msgid "You cannot delete this account move because it has already been posted."
msgid ""
"You cannot delete this account move because it has already been posted."
msgstr ""
"Vous ne pouvez pas supprimer cette pièce comptable car elle à déjà été "
"confirmée."
@@ -102,6 +129,7 @@ msgstr ""
#. module: account_advanced_protection_features
#. odoo-python
#: code:addons/account_advanced_protection_features/models/account_move.py:0
#: code:addons/account_advanced_protection_features/models/account_move.py:0
#, python-format
msgid ""
"You cannot reset to draft this invoice because it has been sent by email."

View File

@@ -1,4 +1,4 @@
from odoo import models, _
from odoo import api, models, _
from odoo.exceptions import UserError
class AccountBankStatement(models.Model):
@@ -19,6 +19,19 @@ class AccountBankStatement(models.Model):
class AccountBankStatementLine(models.Model):
_inherit = "account.bank.statement.line"
@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:

View File

@@ -10,3 +10,7 @@ class AccountJournal(models.Model):
help="Users with group Show Full Accounting Features (id: group_account_user) will be allowed to delete account bank statements "
"and bank statement lines."
)
allow_bank_statement_line_creation = fields.Boolean(
"Allow manual bank statement lines creation",
help="If unchecked, users will not be allowed to manually create bank statement lines for this journal."
)

View File

@@ -1 +1,2 @@
from . import test_account_move
from . import test_account_bank_statement

View File

@@ -0,0 +1,40 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.tests.common import TransactionCase
from odoo.exceptions import UserError
class TestBankStatementLineCreation(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.bank_journal = cls.env["account.journal"].search(
[("type", "=", "bank")], limit=1
)
cls.partner = cls.env["res.partner"].create({"name": "Test Partner"})
def test_create_blocks_creation_when_not_allowed(self):
"""Test that create raises UserError when creation is not allowed."""
self.bank_journal.allow_bank_statement_line_creation = False
with self.assertRaises(UserError):
self.env["account.bank.statement.line"].create({
"journal_id": self.bank_journal.id,
"amount": 100.0,
"payment_ref": "Test",
"date": "2024-01-01",
})
def test_create_allows_creation_when_allowed(self):
"""Test that create works when creation is allowed."""
self.bank_journal.allow_bank_statement_line_creation = True
line = self.env["account.bank.statement.line"].create({
"journal_id": self.bank_journal.id,
"amount": 100.0,
"payment_ref": "Test",
"date": "2024-01-01",
})
self.assertTrue(line.exists())

View File

@@ -20,6 +20,11 @@
groups="account_advanced_protection_features.group_account_protection_manager"
attrs="{'invisible': [('type', 'not in', ['bank', 'cash'])]}"
/>
<field
name="allow_bank_statement_line_creation"
groups="account_advanced_protection_features.group_account_protection_manager"
attrs="{'invisible': [('type', 'not in', ['bank', 'cash'])]}"
/>
</xpath>
</field>
</record>