diff --git a/account_financial_report/models/__init__.py b/account_financial_report/models/__init__.py index 3871830c..b5fef1fe 100644 --- a/account_financial_report/models/__init__.py +++ b/account_financial_report/models/__init__.py @@ -1,2 +1,3 @@ from . import account from . import account_group +from . import account_move_line diff --git a/account_financial_report/models/account_move_line.py b/account_financial_report/models/account_move_line.py new file mode 100644 index 00000000..fc81af61 --- /dev/null +++ b/account_financial_report/models/account_move_line.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +# Copyright 2019 ACSONE SA/NV () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).- +from odoo import api, models + + +class AccountMoveLine(models.Model): + _inherit = 'account.move.line' + + @api.model_cr + def init(self): + """ + The join between accounts_partners subquery and account_move_line + can be heavy to compute on big databases. + Join sample: + JOIN + account_move_line ml + ON ap.account_id = ml.account_id + AND ml.date < '2018-12-30' + AND ap.partner_id = ml.partner_id + AND ap.include_initial_balance = TRUE + By adding the following index, performances are strongly increased. + :return: + """ + self._cr.execute('SELECT indexname FROM pg_indexes WHERE indexname = ' + '%s', + ('account_move_line_account_id_partner_id_index',)) + if not self._cr.fetchone(): + self._cr.execute(""" + CREATE INDEX account_move_line_account_id_partner_id_index + ON account_move_line (account_id, partner_id)""") diff --git a/account_financial_report/readme/HISTORY.rst b/account_financial_report/readme/HISTORY.rst index 4062d70c..a9568b0b 100644 --- a/account_financial_report/readme/HISTORY.rst +++ b/account_financial_report/readme/HISTORY.rst @@ -3,6 +3,7 @@ * Handle better multicompany behaviour * Improve how title appears in the reports +* Improve performance in General Ledger 11.0.2.3.1 (2018-11-29) diff --git a/account_financial_report/report/abstract_report_xlsx.py b/account_financial_report/report/abstract_report_xlsx.py index 5d53b3fb..4c28d03e 100644 --- a/account_financial_report/report/abstract_report_xlsx.py +++ b/account_financial_report/report/abstract_report_xlsx.py @@ -41,7 +41,7 @@ class AbstractReportXslx(models.AbstractModel): self._define_formats(workbook) - report_name = self._get_report_name(objects) + report_name = self._get_report_name(report) report_footer = self._get_report_footer() filters = self._get_report_filters(report) self.columns = self._get_report_columns(report) @@ -349,7 +349,7 @@ class AbstractReportXslx(models.AbstractModel): """ raise NotImplementedError() - def _get_report_name(self, objects): + def _get_report_name(self, report): """ Allow to define the report name. Report name will be used as sheet name and as report title. diff --git a/account_financial_report/report/aged_partner_balance_xlsx.py b/account_financial_report/report/aged_partner_balance_xlsx.py index 31362c2a..ac42c36a 100644 --- a/account_financial_report/report/aged_partner_balance_xlsx.py +++ b/account_financial_report/report/aged_partner_balance_xlsx.py @@ -10,8 +10,7 @@ class AgedPartnerBalanceXslx(models.AbstractModel): _name = 'report.a_f_r.report_aged_partner_balance_xlsx' _inherit = 'report.account_financial_report.abstract_report_xlsx' - def _get_report_name(self, objects): - report = objects + def _get_report_name(self, report): return _('Aged Partner Balance - %s - %s') % ( report.company_id.name, report.company_id.currency_id.name) diff --git a/account_financial_report/report/general_ledger_xlsx.py b/account_financial_report/report/general_ledger_xlsx.py index f722d154..7db68f9b 100644 --- a/account_financial_report/report/general_ledger_xlsx.py +++ b/account_financial_report/report/general_ledger_xlsx.py @@ -11,8 +11,7 @@ class GeneralLedgerXslx(models.AbstractModel): _name = 'report.a_f_r.report_general_ledger_xlsx' _inherit = 'report.account_financial_report.abstract_report_xlsx' - def _get_report_name(self, objects): - report = objects + def _get_report_name(self, report): return _('General Ledger - %s - %s') % ( report.company_id.name, report.company_id.currency_id.name) diff --git a/account_financial_report/report/journal_ledger_xlsx.py b/account_financial_report/report/journal_ledger_xlsx.py index e9a7351e..f5e5a041 100644 --- a/account_financial_report/report/journal_ledger_xlsx.py +++ b/account_financial_report/report/journal_ledger_xlsx.py @@ -10,8 +10,7 @@ class JournalLedgerXslx(models.AbstractModel): _name = 'report.a_f_r.report_journal_ledger_xlsx' _inherit = 'report.account_financial_report.abstract_report_xlsx' - def _get_report_name(self, objects): - report = objects + def _get_report_name(self, report): return _('Journal Ledger - %s - %s') % ( report.company_id.name, report.company_id.currency_id.name) diff --git a/account_financial_report/report/open_items_xlsx.py b/account_financial_report/report/open_items_xlsx.py index 4a82a27b..a1ef4e25 100644 --- a/account_financial_report/report/open_items_xlsx.py +++ b/account_financial_report/report/open_items_xlsx.py @@ -9,8 +9,7 @@ class OpenItemsXslx(models.AbstractModel): _name = 'report.a_f_r.report_open_items_xlsx' _inherit = 'report.account_financial_report.abstract_report_xlsx' - def _get_report_name(self, objects): - report = objects + def _get_report_name(self, report): return _('Open Items - %s - %s') % ( report.company_id.name, report.company_id.currency_id.name) diff --git a/account_financial_report/report/trial_balance_xlsx.py b/account_financial_report/report/trial_balance_xlsx.py index 647e8491..31d8c9a2 100644 --- a/account_financial_report/report/trial_balance_xlsx.py +++ b/account_financial_report/report/trial_balance_xlsx.py @@ -10,8 +10,7 @@ class TrialBalanceXslx(models.AbstractModel): _name = 'report.a_f_r.report_trial_balance_xlsx' _inherit = 'report.account_financial_report.abstract_report_xlsx' - def _get_report_name(self, objects): - report = objects + def _get_report_name(self, report): return _('Trial Balance - %s - %s') % ( report.company_id.name, report.company_id.currency_id.name) diff --git a/account_financial_report/report/vat_report_xlsx.py b/account_financial_report/report/vat_report_xlsx.py index 3d69ffeb..5dd1951b 100644 --- a/account_financial_report/report/vat_report_xlsx.py +++ b/account_financial_report/report/vat_report_xlsx.py @@ -8,8 +8,7 @@ class VATReportXslx(models.AbstractModel): _name = 'report.a_f_r.report_vat_report_xlsx' _inherit = 'report.account_financial_report.abstract_report_xlsx' - def _get_report_name(self, objects): - report = objects + def _get_report_name(self, report): return _('VAT Report - %s - %s') % ( report.company_id.name, report.company_id.currency_id.name) diff --git a/account_financial_report/wizard/general_ledger_wizard.py b/account_financial_report/wizard/general_ledger_wizard.py index 611c9c01..a7420099 100644 --- a/account_financial_report/wizard/general_ledger_wizard.py +++ b/account_financial_report/wizard/general_ledger_wizard.py @@ -103,6 +103,10 @@ class GeneralLedgerReportWizard(models.TransientModel): if self.company_id and self.date_range_id.company_id and \ self.date_range_id.company_id != self.company_id: self.date_range_id = False + if self.company_id and self.account_journal_ids: + self.account_journal_ids = self.account_journal_ids.filtered( + lambda p: p.company_id == self.company_id or + not p.company_id) if self.company_id and self.partner_ids: self.partner_ids = self.partner_ids.filtered( lambda p: p.company_id == self.company_id or @@ -118,6 +122,7 @@ class GeneralLedgerReportWizard(models.TransientModel): lambda c: c.company_id == self.company_id) res = {'domain': {'account_ids': [], 'partner_ids': [], + 'account_journal_ids': [], 'cost_center_ids': [], 'date_range_id': [] } @@ -127,6 +132,8 @@ class GeneralLedgerReportWizard(models.TransientModel): else: res['domain']['account_ids'] += [ ('company_id', '=', self.company_id.id)] + res['domain']['account_journal_ids'] += [ + ('company_id', '=', self.company_id.id)] res['domain']['partner_ids'] += [ '|', ('company_id', '=', self.company_id.id), ('company_id', '=', False)]