From ca69537f8e0e7ab911fdb210c74edfc098f0a2bc Mon Sep 17 00:00:00 2001 From: Ivan Yelizariev <iel@odoo.com> Date: Tue, 9 Feb 2021 11:00:03 +0000 Subject: [PATCH] [FIX] account: reconcile by batches of 1000 lines Neither server, no browser cannot handle unlimited number of lines at the same time. On server side it leads to series of heavy sql requests. On client side, browser will eat all the memory on trying to render all of those lines. This also prevents loading reconciled lines ids to browser. Size of the batches can be customized via System Parameter ``account.reconcile.batch`` Details: * ``action_bank_reconcile_bank_statements`` is used on clicking `[Reconcile]` button in ``account.bank.statement`` form * ``action_open_reconcile`` is used on clicking `[Reconcile]` for a journal in Account Dashboard --- opw-2424992 opw-2344807 closes odoo/odoo#65789 Signed-off-by: Laurent Smet <smetl@users.noreply.github.com> --- addons/account/models/account_bank_statement.py | 9 ++++++++- addons/account/models/account_journal_dashboard.py | 10 +++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/addons/account/models/account_bank_statement.py b/addons/account/models/account_bank_statement.py index 22cc1b88db44..c0c3fd4d31b9 100644 --- a/addons/account/models/account_bank_statement.py +++ b/addons/account/models/account_bank_statement.py @@ -341,7 +341,14 @@ class AccountBankStatement(models.Model): def action_bank_reconcile_bank_statements(self): self.ensure_one() - bank_stmt_lines = self.mapped('line_ids') + limit = int(self.env["ir.config_parameter"].get_param("account.reconcile.batch", 1000)) + bank_stmt_lines = self.env['account.bank.statement.line'].search([ + ('statement_id', 'in', self.ids), + # take not reconciled lines only. See _check_lines_reconciled method + ('account_id', '=', False), + ('journal_entry_ids', '=', False), + ('amount', '!=', 0), + ], limit=limit) return { 'type': 'ir.actions.client', 'tag': 'bank_statement_reconciliation_view', diff --git a/addons/account/models/account_journal_dashboard.py b/addons/account/models/account_journal_dashboard.py index c3dc0f8752d4..c4089e67252e 100644 --- a/addons/account/models/account_journal_dashboard.py +++ b/addons/account/models/account_journal_dashboard.py @@ -423,7 +423,15 @@ class account_journal(models.Model): def action_open_reconcile(self): if self.type in ['bank', 'cash']: # Open reconciliation view for bank statements belonging to this journal - bank_stmt = self.env['account.bank.statement'].search([('journal_id', 'in', self.ids)]).mapped('line_ids') + limit = int(self.env["ir.config_parameter"].get_param("account.reconcile.batch", 1000)) + bank_stmt = self.env['account.bank.statement.line'].search([ + ('journal_id', 'in', self.ids), + # take not reconciled lines only. See _check_lines_reconciled method + ('account_id', '=', False), + ('journal_entry_ids', '=', False), + ('amount', '!=', 0), + ], limit=limit) + return { 'type': 'ir.actions.client', 'tag': 'bank_statement_reconciliation_view', -- GitLab