From 4183ec5f5d894c39fe7c542c9bc83da5d5d6840a Mon Sep 17 00:00:00 2001
From: Jairo Llopis
Date: Fri, 3 Jun 2022 12:39:52 +0100
Subject: [PATCH] [FIX] account_journal_general_sequence: bottleneck at install
On databases with big amounts of account moves, installation would freeze Odoo for some minutes.
We skip now entry number computation at install, to avoid such cases.
@moduon MT-676
---
account_journal_general_sequence/README.rst | 10 +++++
.../__manifest__.py | 1 +
.../models/account_move.py | 11 ++++++
.../readme/INSTALL.rst | 6 +++
.../static/description/index.html | 37 ++++++++++++-------
.../tests/test_numbering.py | 16 ++++++++
6 files changed, 67 insertions(+), 14 deletions(-)
create mode 100644 account_journal_general_sequence/readme/INSTALL.rst
diff --git a/account_journal_general_sequence/README.rst b/account_journal_general_sequence/README.rst
index d69f5e7d..b28e73e0 100644
--- a/account_journal_general_sequence/README.rst
+++ b/account_journal_general_sequence/README.rst
@@ -36,6 +36,16 @@ that Odoo adds by default, and has different purpose.
.. contents::
:local:
+Installation
+============
+
+After installing this module, no entry numbers will be generated because that
+could have a very negative impact in installations that already had a lot of
+account moves.
+
+If you need to add numbers to preexisting account moves, please use the
+renumbering wizard as explained in the *Usage* section.
+
Configuration
=============
diff --git a/account_journal_general_sequence/__manifest__.py b/account_journal_general_sequence/__manifest__.py
index ec43abd2..cf5610c1 100644
--- a/account_journal_general_sequence/__manifest__.py
+++ b/account_journal_general_sequence/__manifest__.py
@@ -9,6 +9,7 @@
"author": "Moduon, Odoo Community Association (OCA)",
"license": "LGPL-3",
"external_dependencies": {"python": ["freezegun"]},
+ "maintainers": ["yajo"],
"depends": [
"account",
],
diff --git a/account_journal_general_sequence/models/account_move.py b/account_journal_general_sequence/models/account_move.py
index c3c2c9c1..c02e517d 100644
--- a/account_journal_general_sequence/models/account_move.py
+++ b/account_journal_general_sequence/models/account_move.py
@@ -6,6 +6,8 @@ from odoo import api, fields, models
_logger = logging.getLogger(__name__)
+ADDON = "account_journal_general_sequence"
+
class AccountMove(models.Model):
_inherit = "account.move"
@@ -30,6 +32,15 @@ class AccountMove(models.Model):
@api.depends("state")
def _compute_entry_number(self):
"""Assign an entry number when posting."""
+ # Skip if installing module, for performance reasons
+ if self.env.context.get("module") == ADDON:
+ module = self.env["ir.module.module"].search([("name", "=", ADDON)])
+ if module.state == "to install":
+ _logger.info(
+ "Skipping entry number generation at install for %s.",
+ self,
+ )
+ return
canceled = self.filtered_domain(
[("state", "=", "cancel"), ("entry_number", "!=", False)]
)
diff --git a/account_journal_general_sequence/readme/INSTALL.rst b/account_journal_general_sequence/readme/INSTALL.rst
new file mode 100644
index 00000000..768a793c
--- /dev/null
+++ b/account_journal_general_sequence/readme/INSTALL.rst
@@ -0,0 +1,6 @@
+After installing this module, no entry numbers will be generated because that
+could have a very negative impact in installations that already had a lot of
+account moves.
+
+If you need to add numbers to preexisting account moves, please use the
+renumbering wizard as explained in the *Usage* section.
diff --git a/account_journal_general_sequence/static/description/index.html b/account_journal_general_sequence/static/description/index.html
index 46b169d8..0c73bf65 100644
--- a/account_journal_general_sequence/static/description/index.html
+++ b/account_journal_general_sequence/static/description/index.html
@@ -375,19 +375,28 @@ that Odoo adds by default, and has different purpose.
Table of contents
+
+
+
After installing this module, no entry numbers will be generated because that
+could have a very negative impact in installations that already had a lot of
+account moves.
+
If you need to add numbers to preexisting account moves, please use the
+renumbering wizard as explained in the Usage section.
+
-
+
To configure journal sequences:
- Have full accounting permissions.
@@ -404,7 +413,7 @@ per journal, make sure they don’t produce colliding results.
-
+
To see journal entry numbers:
- Go to Invoicing > Accounting > Miscellaneous > Journal Entries.
@@ -430,7 +439,7 @@ per journal, make sure they don’t produce colliding results.
-
+
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 smashing it by providing a detailed and welcomed
@@ -438,22 +447,22 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
Do not contact contributors directly about support or help with technical issues.
-
+
-
+
This module is maintained by the OCA.
OCA, or the Odoo Community Association, is a nonprofit organization whose
diff --git a/account_journal_general_sequence/tests/test_numbering.py b/account_journal_general_sequence/tests/test_numbering.py
index 4f59a12c..8e198776 100644
--- a/account_journal_general_sequence/tests/test_numbering.py
+++ b/account_journal_general_sequence/tests/test_numbering.py
@@ -55,3 +55,19 @@ class RenumberCase(TestAccountReconciliationCommon):
wiz = wiz_f.save()
wiz.action_renumber()
self.assertEqual(opening_invoice.entry_number, "2022/0000000000")
+
+ def test_install_no_entry_number(self):
+ """No entry numbers assigned on module installation."""
+ # Imitate installation environment
+ self.env = self.env(
+ context=dict(self.env.context, module="account_journal_general_sequence")
+ )
+ self.env["ir.module.module"].search(
+ [("name", "=", "account_journal_general_sequence")]
+ ).state = "to install"
+ # Do some action that would make the move get an entry number
+ invoice = self._create_invoice()
+ self.assertFalse(invoice.entry_number)
+ invoice.action_post()
+ # Ensure there's no entry number
+ self.assertFalse(invoice.entry_number)