[IMP] account_advanced_protection_features : correct the way allow_bank_statement_line_creation works
Some checks failed
pre-commit / pre-commit (pull_request) Failing after 1m31s

This commit is contained in:
2026-02-03 16:17:28 +01:00
parent e1f1d748ff
commit 189b068097
2 changed files with 36 additions and 15 deletions

View File

@@ -21,6 +21,9 @@ class AccountBankStatementLine(models.Model):
@api.model_create_multi
def create(self, vals_list):
# Condition on action_name is here to check permissions only for the manual creation.
# Import of files and pulling online bank statements should not be concerned
if self.env.context.get("action_name") == "action_bank_statement_tree":
for vals in vals_list:
journal_id = vals.get("journal_id")
if journal_id:

View File

@@ -14,23 +14,27 @@ class TestBankStatementLineCreation(TransactionCase):
)
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."""
def test_manual_create_blocks_when_not_allowed(self):
"""Test that manual creation from UI raises UserError when not allowed."""
self.bank_journal.allow_bank_statement_line_creation = False
with self.assertRaises(UserError):
self.env["account.bank.statement.line"].create({
self.env["account.bank.statement.line"].with_context(
action_name="action_bank_statement_tree"
).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."""
def test_manual_create_works_when_allowed(self):
"""Test that manual creation from UI works when allowed."""
self.bank_journal.allow_bank_statement_line_creation = True
line = self.env["account.bank.statement.line"].create({
line = self.env["account.bank.statement.line"].with_context(
action_name="action_bank_statement_tree"
).create({
"journal_id": self.bank_journal.id,
"amount": 100.0,
"payment_ref": "Test",
@@ -38,3 +42,17 @@ class TestBankStatementLineCreation(TransactionCase):
})
self.assertTrue(line.exists())
def test_programmatic_create_works_even_when_not_allowed(self):
"""Test that creation without UI context (e.g. OFX import, pulling online bank statements)
works even when manual creation is not allowed."""
self.bank_journal.allow_bank_statement_line_creation = False
line = self.env["account.bank.statement.line"].create({
"journal_id": self.bank_journal.id,
"amount": 100.0,
"payment_ref": "Test Import",
"date": "2024-01-01",
})
self.assertTrue(line.exists())