From 574bdad1787fbd5da6d0bb229dd58a679abaa448 Mon Sep 17 00:00:00 2001
From: JordiMForgeFlow
Date: Fri, 3 Jan 2025 13:21:01 +0100
Subject: [PATCH] [IMP] account_journal_restrict_mode: do not force hash on
bank and cash journals
Forcing the hashing of bank and cash journals results in errors when creating bank transactions,
due to the commit added in Odoo: https://github.com/odoo/odoo/commit/9740189bc59658a62da6a624e166505841ac30a4
---
account_journal_restrict_mode/README.rst | 18 ++++-----
account_journal_restrict_mode/hooks.py | 5 ++-
.../models/account_journal.py | 19 +++++++---
.../readme/DESCRIPTION.md | 6 ++-
.../readme/ROADMAP.md | 5 ---
.../static/description/index.html | 37 ++++++++-----------
6 files changed, 45 insertions(+), 45 deletions(-)
delete mode 100644 account_journal_restrict_mode/readme/ROADMAP.md
diff --git a/account_journal_restrict_mode/README.rst b/account_journal_restrict_mode/README.rst
index fb678065d45..8cead99d0ac 100644
--- a/account_journal_restrict_mode/README.rst
+++ b/account_journal_restrict_mode/README.rst
@@ -29,25 +29,21 @@ Account Journal Restrict Mode
|badge1| |badge2| |badge3| |badge4| |badge5|
This module enables by default the setting *Lock Posted Entries with
-Hash* in all Journals and prevents the setting to be modified.
+Hash* in all Sales, Purchase and Miscellaneous Journals, and prevents
+the setting to be modified.
The goal is to assure that all journal entries are locked when posted to
prevent them to be modified.
+Bank and Cash journals can't be hashed as it conflicts with Odoo's logic
+when creating bank transactions
+(https://github.com/odoo/odoo/commit/9740189bc59658a62da6a624e166505841ac30a4).
+
**Table of contents**
.. contents::
:local:
-Known issues / Roadmap
-======================
-
-- Odoo hides the setting *Lock Posted Entries with Hash* on Bank and
- Cash Journals, but enabling it does not cause issues in the
- reconciliation for now. If the Odoo logic changes at any point, the
- module may need to be adapted to only force the setting on other types
- of journals.
-
Bug Tracker
===========
@@ -69,7 +65,7 @@ Authors
Contributors
------------
-- Jordi Masvidal
+- Jordi Masvidal
Maintainers
-----------
diff --git a/account_journal_restrict_mode/hooks.py b/account_journal_restrict_mode/hooks.py
index b2adf0dad02..1a3f5192a0f 100644
--- a/account_journal_restrict_mode/hooks.py
+++ b/account_journal_restrict_mode/hooks.py
@@ -5,6 +5,9 @@
def post_init_hook(env):
"""Enable restrict mode on all journals"""
journals_to_update = env["account.journal"].search(
- [("restrict_mode_hash_table", "=", False)]
+ [
+ ("restrict_mode_hash_table", "=", False),
+ ("type", "in", ["sale", "purchase", "general"]),
+ ]
)
journals_to_update.write({"restrict_mode_hash_table": True})
diff --git a/account_journal_restrict_mode/models/account_journal.py b/account_journal_restrict_mode/models/account_journal.py
index edf0aa704b7..89c10f4766c 100644
--- a/account_journal_restrict_mode/models/account_journal.py
+++ b/account_journal_restrict_mode/models/account_journal.py
@@ -10,10 +10,10 @@ class AccountJournal(models.Model):
_inherit = "account.journal"
restrict_mode_hash_table = fields.Boolean(
- default=lambda self: self._default_restrict_mode_hash_table(), readonly=True
+ compute="_compute_restrict_mode_hash_table", store=True, readonly=True
)
- @api.constrains("restrict_mode_hash_table")
+ @api.constrains("restrict_mode_hash_table", "type")
def _check_journal_restrict_mode(self):
test_condition = not config["test_enable"] or (
config["test_enable"]
@@ -22,15 +22,24 @@ def _check_journal_restrict_mode(self):
if not test_condition:
return
for rec in self:
- if not rec.restrict_mode_hash_table:
+ if not rec.restrict_mode_hash_table and rec.type in [
+ "sale",
+ "purchase",
+ "general",
+ ]:
raise UserError(
self.env._("Journal %s must have Lock Posted Entries enabled.")
% rec.name
)
- def _default_restrict_mode_hash_table(self):
+ @api.depends("type")
+ def _compute_restrict_mode_hash_table(self):
test_condition = not config["test_enable"] or (
config["test_enable"]
and self.env.context.get("test_account_journal_restrict_mode")
)
- return bool(test_condition)
+ for rec in self:
+ if not test_condition:
+ rec.restrict_mode_hash_table = False
+ continue
+ rec.restrict_mode_hash_table = rec.type in ["sale", "purchase", "general"]
diff --git a/account_journal_restrict_mode/readme/DESCRIPTION.md b/account_journal_restrict_mode/readme/DESCRIPTION.md
index b04f34f8df9..091f4f270ec 100644
--- a/account_journal_restrict_mode/readme/DESCRIPTION.md
+++ b/account_journal_restrict_mode/readme/DESCRIPTION.md
@@ -1,5 +1,9 @@
This module enables by default the setting *Lock Posted Entries with
-Hash* in all Journals and prevents the setting to be modified.
+Hash* in all Sales, Purchase and Miscellaneous Journals, and prevents
+the setting to be modified.
The goal is to assure that all journal entries are locked when posted to
prevent them to be modified.
+
+Bank and Cash journals can't be hashed as it conflicts with Odoo's logic when
+creating bank transactions (https://github.com/odoo/odoo/commit/9740189bc59658a62da6a624e166505841ac30a4).
diff --git a/account_journal_restrict_mode/readme/ROADMAP.md b/account_journal_restrict_mode/readme/ROADMAP.md
deleted file mode 100644
index c5b8315434d..00000000000
--- a/account_journal_restrict_mode/readme/ROADMAP.md
+++ /dev/null
@@ -1,5 +0,0 @@
-- Odoo hides the setting *Lock Posted Entries with Hash* on Bank and
- Cash Journals, but enabling it does not cause issues in the
- reconciliation for now. If the Odoo logic changes at any point, the
- module may need to be adapted to only force the setting on other types
- of journals.
diff --git a/account_journal_restrict_mode/static/description/index.html b/account_journal_restrict_mode/static/description/index.html
index d53ee23b234..833e4141cb4 100644
--- a/account_journal_restrict_mode/static/description/index.html
+++ b/account_journal_restrict_mode/static/description/index.html
@@ -371,34 +371,27 @@ Account Journal Restrict Mode
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

This module enables by default the setting Lock Posted Entries with
-Hash in all Journals and prevents the setting to be modified.
+Hash in all Sales, Purchase and Miscellaneous Journals, and prevents
+the setting to be modified.
The goal is to assure that all journal entries are locked when posted to
prevent them to be modified.
+Bank and Cash journals can’t be hashed as it conflicts with Odoo’s logic
+when creating bank transactions
+(https://github.com/odoo/odoo/commit/9740189bc59658a62da6a624e166505841ac30a4).
Table of contents
-
-
-
-- Odoo hides the setting Lock Posted Entries with Hash on Bank and
-Cash Journals, but enabling it does not cause issues in the
-reconciliation for now. If the Odoo logic changes at any point, the
-module may need to be adapted to only force the setting on other types
-of journals.
-
-
-
+
Bugs are tracked on GitHub Issues.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
@@ -406,21 +399,21 @@
Do not contact contributors directly about support or help with technical issues.
-
+
-
+
This module is maintained by the OCA.