[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
This commit is contained in:
Jairo Llopis
2022-06-03 12:39:52 +01:00
parent c545b674e8
commit 2ebd95053f
6 changed files with 67 additions and 14 deletions

View File

@@ -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)]
)