diff --git a/account_financial_report/tests/test_general_ledger.py b/account_financial_report/tests/test_general_ledger.py index 8e0537e5..ee9f9e64 100644 --- a/account_financial_report/tests/test_general_ledger.py +++ b/account_financial_report/tests/test_general_ledger.py @@ -493,3 +493,20 @@ class TestGeneralLedgerReport(common.TransactionCase): self.assertEqual(lines['unaffected'].final_debit, 500) self.assertEqual(lines['unaffected'].final_credit, 0) self.assertEqual(lines['unaffected'].final_balance, 500) + + def test_partner_filter(self): + partner_1 = self.env.ref('base.res_partner_1') + partner_2 = self.env.ref('base.res_partner_2') + partner_3 = self.env.ref('base.res_partner_3') + partner_4 = self.env.ref('base.res_partner_4') + partner_1.write({'is_company': False, + 'parent_id': partner_2.id}) + partner_3.write({'is_company': False}) + + expected_list = [partner_2.id, partner_3.id, partner_4.id] + context = {'active_ids': + [partner_1.id, partner_2.id, partner_3.id, partner_4.id], + 'active_model': 'res.partner'} + + wizard = self.env["general.ledger.report.wizard"].with_context(context) + self.assertEqual(wizard._default_partners(), expected_list) \ No newline at end of file diff --git a/account_financial_report/tests/test_open_items.py b/account_financial_report/tests/test_open_items.py index 197dfb72..570589df 100644 --- a/account_financial_report/tests/test_open_items.py +++ b/account_financial_report/tests/test_open_items.py @@ -39,3 +39,19 @@ class TestOpenItems(a_t_f_c.AbstractTestForeignCurrency): {'hide_account_at_0': True}, {'only_posted_moves': True, 'hide_account_at_0': True}, ] + def test_partner_filter(self): + partner_1 = self.env.ref('base.res_partner_1') + partner_2 = self.env.ref('base.res_partner_2') + partner_3 = self.env.ref('base.res_partner_3') + partner_4 = self.env.ref('base.res_partner_4') + partner_1.write({'is_company': False, + 'parent_id': partner_2.id}) + partner_3.write({'is_company': False}) + + expected_list = [partner_2.id, partner_3.id, partner_4.id] + context = {'active_ids': + [partner_1.id, partner_2.id, partner_3.id, partner_4.id], + 'active_model': 'res.partner'} + + wizard = self.env["open.items.report.wizard"].with_context(context) + self.assertEqual(wizard._default_partners(), expected_list) \ No newline at end of file diff --git a/account_financial_report/wizard/general_ledger_wizard.py b/account_financial_report/wizard/general_ledger_wizard.py index 915b236f..be6c62cb 100644 --- a/account_financial_report/wizard/general_ledger_wizard.py +++ b/account_financial_report/wizard/general_ledger_wizard.py @@ -58,6 +58,7 @@ class GeneralLedgerReportWizard(models.TransientModel): partner_ids = fields.Many2many( comodel_name='res.partner', string='Filter partners', + default=lambda self: self._default_partners(), ) analytic_tag_ids = fields.Many2many( comodel_name='account.analytic.tag', @@ -80,8 +81,25 @@ class GeneralLedgerReportWizard(models.TransientModel): string='Show foreign currency', help='Display foreign currency for move lines, unless ' 'account currency is not setup through chart of accounts ' - 'will display initial and final balance in that currency.' + 'will display initial and final balance in that currency.', + default=lambda self: self._default_foreign_currency(), ) + + def _default_foreign_currency(self): + return self.env.user.has_group('base.group_multi_currency') + + def _default_partners(self): + context = self.env.context + + if context.get('active_ids') and context.get('active_model') \ + == 'res.partner': + partner_ids = context['active_ids'] + corp_partners = self.env['res.partner'].browse(partner_ids). \ + filtered(lambda p: p.parent_id) + + partner_ids = set(partner_ids) - set(corp_partners.ids) + partner_ids |= set(corp_partners.mapped('parent_id.id')) + return list(partner_ids) @api.depends('date_from') def _compute_fy_start_date(self): diff --git a/account_financial_report/wizard/open_items_wizard.py b/account_financial_report/wizard/open_items_wizard.py index 426f3416..5853aa3b 100644 --- a/account_financial_report/wizard/open_items_wizard.py +++ b/account_financial_report/wizard/open_items_wizard.py @@ -44,14 +44,32 @@ class OpenItemsReportWizard(models.TransientModel): partner_ids = fields.Many2many( comodel_name='res.partner', string='Filter partners', + default=lambda self: self._default_partners(), ) foreign_currency = fields.Boolean( string='Show foreign currency', help='Display foreign currency for move lines, unless ' 'account currency is not setup through chart of accounts ' - 'will display initial and final balance in that currency.' + 'will display initial and final balance in that currency.', + default=lambda self: self._default_foreign_currency(), ) + def _default_foreign_currency(self): + return self.env.user.has_group('base.group_multi_currency') + + def _default_partners(self): + context = self.env.context + + if context.get('active_ids') and context.get('active_model') \ + == 'res.partner': + partner_ids = context['active_ids'] + corp_partners = self.env['res.partner'].browse(partner_ids). \ + filtered(lambda p: p.parent_id) + + partner_ids = set(partner_ids) - set(corp_partners.ids) + partner_ids |= set(corp_partners.mapped('parent_id.id')) + return list(partner_ids) + @api.onchange('company_id') def onchange_company_id(self): """Handle company change."""