From 3169ba2255653567a2f9acf2f9f815fa0dc95caf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Todorovich?= Date: Fri, 31 Jan 2020 16:06:25 +0100 Subject: [PATCH 1/4] [IMP] Use of account.account.type instead of hardcoded receivable and payable booleans --- .../wizard/general_ledger_wizard.py | 35 +++++++++---------- .../wizard/general_ledger_wizard_view.xml | 18 ++++------ 2 files changed, 24 insertions(+), 29 deletions(-) diff --git a/account_financial_report/wizard/general_ledger_wizard.py b/account_financial_report/wizard/general_ledger_wizard.py index bbe6ff4c..1da3dd97 100644 --- a/account_financial_report/wizard/general_ledger_wizard.py +++ b/account_financial_report/wizard/general_ledger_wizard.py @@ -4,6 +4,7 @@ # Copyright 2016 Camptocamp SA # Copyright 2017 Akretion - Alexis de Lattre # Copyright 2017 Eficent Business and IT Consulting Services, S.L. +# Copyright 2020 Druidoo # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). @@ -57,8 +58,10 @@ class GeneralLedgerReportWizard(models.TransientModel): show_analytic_tags = fields.Boolean( string='Show analytic tags', ) - receivable_accounts_only = fields.Boolean() - payable_accounts_only = fields.Boolean() + account_type_ids = fields.Many2many( + 'account.account.type', + string='Account Types', + ) partner_ids = fields.Many2many( comodel_name='res.partner', string='Filter partners', @@ -133,8 +136,8 @@ class GeneralLedgerReportWizard(models.TransientModel): lambda p: p.company_id == self.company_id or not p.company_id) if self.company_id and self.account_ids: - if self.receivable_accounts_only or self.payable_accounts_only: - self.onchange_type_accounts_only() + if self.account_type_ids: + self._onchange_account_type_ids() else: self.account_ids = self.account_ids.filtered( lambda a: a.company_id == self.company_id) @@ -180,18 +183,11 @@ class GeneralLedgerReportWizard(models.TransientModel): _('The Company in the General Ledger Report Wizard and in ' 'Date Range must be the same.')) - @api.onchange('receivable_accounts_only', 'payable_accounts_only') - def onchange_type_accounts_only(self): - """Handle receivable/payable accounts only change.""" - if self.receivable_accounts_only or self.payable_accounts_only: - domain = [('company_id', '=', self.company_id.id)] - if self.receivable_accounts_only and self.payable_accounts_only: - domain += [('internal_type', 'in', ('receivable', 'payable'))] - elif self.receivable_accounts_only: - domain += [('internal_type', '=', 'receivable')] - elif self.payable_accounts_only: - domain += [('internal_type', '=', 'payable')] - self.account_ids = self.env['account.account'].search(domain) + @api.onchange('account_type_ids') + def _onchange_account_type_ids(self): + if self.account_type_ids: + self.account_ids = self.env['account.account'].search([ + ('user_type_id', 'in', self.account_type_ids.ids)]) else: self.account_ids = None @@ -199,9 +195,12 @@ class GeneralLedgerReportWizard(models.TransientModel): def onchange_partner_ids(self): """Handle partners change.""" if self.partner_ids: - self.receivable_accounts_only = self.payable_accounts_only = True + self.account_type_ids = self.env['account.account.type'].search([ + ('type', 'in', ['receivable', 'payable'])]) else: - self.receivable_accounts_only = self.payable_accounts_only = False + self.account_type_ids = None + # Somehow this is required to force onchange on _default_partners() + self._onchange_account_type_ids() @api.multi def button_export_html(self): diff --git a/account_financial_report/wizard/general_ledger_wizard_view.xml b/account_financial_report/wizard/general_ledger_wizard_view.xml index 2d3aa384..c2790a1d 100644 --- a/account_financial_report/wizard/general_ledger_wizard_view.xml +++ b/account_financial_report/wizard/general_ledger_wizard_view.xml @@ -28,14 +28,14 @@ - - - + + + + + + + - From e71076850b75a999e6738037043a2588a180ed03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Todorovich?= Date: Fri, 31 Jan 2020 16:13:54 +0100 Subject: [PATCH 2/4] [IMP] Improve UX --- .../wizard/general_ledger_wizard_view.xml | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/account_financial_report/wizard/general_ledger_wizard_view.xml b/account_financial_report/wizard/general_ledger_wizard_view.xml index c2790a1d..eb67d759 100644 --- a/account_financial_report/wizard/general_ledger_wizard_view.xml +++ b/account_financial_report/wizard/general_ledger_wizard_view.xml @@ -20,10 +20,26 @@ - - - - + From 38aa71fe9d8c734b65dfc7bf19ad0df6633b9a8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Todorovich?= Date: Fri, 31 Jan 2020 16:18:43 +0100 Subject: [PATCH 3/4] Update contributors --- account_financial_report/readme/CONTRIBUTORS.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/account_financial_report/readme/CONTRIBUTORS.rst b/account_financial_report/readme/CONTRIBUTORS.rst index 4c3dafc7..4d06ad1a 100644 --- a/account_financial_report/readme/CONTRIBUTORS.rst +++ b/account_financial_report/readme/CONTRIBUTORS.rst @@ -19,6 +19,9 @@ * Pedro M. Baeza * Sergio Teruel +* `Druidoo `__: + + * Iván Todorovich Much of the work in this module was done at a sprint in Sorrento, Italy in April 2016. From 131f9dc162afae7f08a5d87253a29ba92e151e95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Todorovich?= Date: Sun, 2 Feb 2020 15:11:47 +0100 Subject: [PATCH 4/4] [FIX] Missing company domain --- account_financial_report/wizard/general_ledger_wizard.py | 1 + 1 file changed, 1 insertion(+) diff --git a/account_financial_report/wizard/general_ledger_wizard.py b/account_financial_report/wizard/general_ledger_wizard.py index 1da3dd97..83f416f8 100644 --- a/account_financial_report/wizard/general_ledger_wizard.py +++ b/account_financial_report/wizard/general_ledger_wizard.py @@ -187,6 +187,7 @@ class GeneralLedgerReportWizard(models.TransientModel): def _onchange_account_type_ids(self): if self.account_type_ids: self.account_ids = self.env['account.account'].search([ + ('company_id', '=', self.company_id.id), ('user_type_id', 'in', self.account_type_ids.ids)]) else: self.account_ids = None