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] [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 @@ - - - + + + + + + + -