From b46bb5fb4b9d30a7e883177e952868e89111e998 Mon Sep 17 00:00:00 2001 From: Joan Sisquella Date: Thu, 30 Apr 2020 11:48:23 +0200 Subject: [PATCH 01/10] [IMP] account_financial_report: open_items & aged_partner_balance * Now account_ids is empty by default and required * Domain is applied in the selection of the accounts --- .../wizard/aged_partner_balance_wizard.py | 19 +++++++++++------ .../wizard/open_items_wizard.py | 21 ++++++++++++------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/account_financial_report/wizard/aged_partner_balance_wizard.py b/account_financial_report/wizard/aged_partner_balance_wizard.py index e1eb65c7..a3a48b87 100644 --- a/account_financial_report/wizard/aged_partner_balance_wizard.py +++ b/account_financial_report/wizard/aged_partner_balance_wizard.py @@ -27,7 +27,10 @@ class AgedPartnerBalanceWizard(models.TransientModel): default="posted", ) account_ids = fields.Many2many( - comodel_name="account.account", string="Filter accounts" + comodel_name='account.account', + string='Filter accounts', + domain=[('reconcile', '=', True)], + required=True, ) receivable_accounts_only = fields.Boolean() payable_accounts_only = fields.Boolean() @@ -56,7 +59,11 @@ class AgedPartnerBalanceWizard(models.TransientModel): res["domain"]["partner_ids"] += self._get_partner_ids_domain() return res - @api.onchange("receivable_accounts_only", "payable_accounts_only") + @api.onchange('account_ids') + def onchange_account_ids(self): + return {'domain': {'account_ids': [('reconcile', '=', True)]}} + + @api.onchange('receivable_accounts_only', 'payable_accounts_only') def onchange_type_accounts_only(self): """Handle receivable/payable accounts only change.""" domain = [("company_id", "=", self.company_id.id)] @@ -66,10 +73,10 @@ class AgedPartnerBalanceWizard(models.TransientModel): elif self.receivable_accounts_only: domain += [("internal_type", "=", "receivable")] elif self.payable_accounts_only: - domain += [("internal_type", "=", "payable")] - elif not self.receivable_accounts_only and not self.payable_accounts_only: - domain += [("reconcile", "=", True)] - self.account_ids = self.env["account.account"].search(domain) + domain += [('internal_type', '=', 'payable')] + self.account_ids = self.env['account.account'].search(domain) + else: + self.account_ids = None def _print_report(self, report_type): self.ensure_one() diff --git a/account_financial_report/wizard/open_items_wizard.py b/account_financial_report/wizard/open_items_wizard.py index 1a5446be..7377dc33 100644 --- a/account_financial_report/wizard/open_items_wizard.py +++ b/account_financial_report/wizard/open_items_wizard.py @@ -28,9 +28,10 @@ class OpenItemsReportWizard(models.TransientModel): default="posted", ) account_ids = fields.Many2many( - comodel_name="account.account", - string="Filter accounts", - domain=[("reconcile", "=", True)], + comodel_name='account.account', + string='Filter accounts', + domain=[('reconcile', '=', True)], + required=True, ) hide_account_at_0 = fields.Boolean( string="Hide account ending balance at 0", @@ -80,7 +81,11 @@ class OpenItemsReportWizard(models.TransientModel): res["domain"]["partner_ids"] += self._get_partner_ids_domain() return res - @api.onchange("receivable_accounts_only", "payable_accounts_only") + @api.onchange('account_ids') + def onchange_account_ids(self): + return {'domain': {'account_ids': [('reconcile', '=', True)]}} + + @api.onchange('receivable_accounts_only', 'payable_accounts_only') def onchange_type_accounts_only(self): """Handle receivable/payable accounts only change.""" domain = [("company_id", "=", self.company_id.id)] @@ -90,10 +95,10 @@ class OpenItemsReportWizard(models.TransientModel): elif self.receivable_accounts_only: domain += [("internal_type", "=", "receivable")] elif self.payable_accounts_only: - domain += [("internal_type", "=", "payable")] - elif not self.receivable_accounts_only and not self.payable_accounts_only: - domain += [("reconcile", "=", True)] - self.account_ids = self.env["account.account"].search(domain) + domain += [('internal_type', '=', 'payable')] + self.account_ids = self.env['account.account'].search(domain) + else: + self.account_ids = None def _print_report(self, report_type): self.ensure_one() From 5f93bdcfdbc9b0337da92a5dedd11992c4952bcf Mon Sep 17 00:00:00 2001 From: Joan Sisquella Date: Thu, 30 Apr 2020 15:35:09 +0200 Subject: [PATCH 02/10] [IMP] account_financial_report: select accounts between two codes --- .../tests/test_vat_report.py | 4 +- .../wizard/aged_partner_balance_wizard.py | 54 ++++++++++++++++--- .../aged_partner_balance_wizard_view.xml | 18 +++++++ .../wizard/general_ledger_wizard.py | 28 ++++++++++ .../wizard/general_ledger_wizard_view.xml | 34 +++++++++--- .../wizard/open_items_wizard.py | 54 ++++++++++++++++--- .../wizard/open_items_wizard_view.xml | 18 +++++++ .../wizard/trial_balance_wizard.py | 28 ++++++++++ .../wizard/trial_balance_wizard_view.xml | 16 ++++++ 9 files changed, 229 insertions(+), 25 deletions(-) diff --git a/account_financial_report/tests/test_vat_report.py b/account_financial_report/tests/test_vat_report.py index e5671835..7ee15f9c 100644 --- a/account_financial_report/tests/test_vat_report.py +++ b/account_financial_report/tests/test_vat_report.py @@ -173,8 +173,8 @@ class TestVATReport(common.TransactionCase): line_form.price_unit = 250.0 line_form.account_id = self.income_account line_form.tax_ids.add(self.tax_20) - self.cbinvoice = move_form.save() - self.cbinvoice.post() + invoice = move_form.save() + invoice.post() def _get_report_lines(self, taxgroups=False): based_on = "taxtags" diff --git a/account_financial_report/wizard/aged_partner_balance_wizard.py b/account_financial_report/wizard/aged_partner_balance_wizard.py index a3a48b87..b1d67361 100644 --- a/account_financial_report/wizard/aged_partner_balance_wizard.py +++ b/account_financial_report/wizard/aged_partner_balance_wizard.py @@ -27,9 +27,9 @@ class AgedPartnerBalanceWizard(models.TransientModel): default="posted", ) account_ids = fields.Many2many( - comodel_name='account.account', - string='Filter accounts', - domain=[('reconcile', '=', True)], + comodel_name="account.account", + string="Filter accounts", + domain=[("reconcile", "=", True)], required=True, ) receivable_accounts_only = fields.Boolean() @@ -37,6 +37,44 @@ class AgedPartnerBalanceWizard(models.TransientModel): partner_ids = fields.Many2many(comodel_name="res.partner", string="Filter partners") show_move_line_details = fields.Boolean() + account_code_from = fields.Many2one( + comodel_name="account.account", + string="Account Code From", + help="Starting account in a range", + ) + account_code_to = fields.Many2one( + comodel_name="account.account", + string="Account Code To", + help="Ending account in a range", + ) + + @api.onchange("account_code_from", "account_code_to") + def on_change_account_range(self): + if ( + self.account_code_from + and self.account_code_from.code.isdigit() + and self.account_code_to + and self.account_code_to.code.isdigit() + ): + start_range = int(self.account_code_from.code) + end_range = int(self.account_code_to.code) + self.account_ids = self.env["account.account"].search( + [ + ("code", "in", [x for x in range(start_range, end_range + 1)]), + ("reconcile", "=", True), + ] + ) + if self.company_id: + self.account_ids = self.account_ids.filtered( + lambda a: a.company_id == self.company_id + ) + return { + "domain": { + "account_code_from": [("reconcile", "=", True)], + "account_code_to": [("reconcile", "=", True)], + } + } + @api.onchange("company_id") def onchange_company_id(self): """Handle company change.""" @@ -59,11 +97,11 @@ class AgedPartnerBalanceWizard(models.TransientModel): res["domain"]["partner_ids"] += self._get_partner_ids_domain() return res - @api.onchange('account_ids') + @api.onchange("account_ids") def onchange_account_ids(self): - return {'domain': {'account_ids': [('reconcile', '=', True)]}} + return {"domain": {"account_ids": [("reconcile", "=", True)]}} - @api.onchange('receivable_accounts_only', 'payable_accounts_only') + @api.onchange("receivable_accounts_only", "payable_accounts_only") def onchange_type_accounts_only(self): """Handle receivable/payable accounts only change.""" domain = [("company_id", "=", self.company_id.id)] @@ -73,8 +111,8 @@ class AgedPartnerBalanceWizard(models.TransientModel): 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) + domain += [("internal_type", "=", "payable")] + self.account_ids = self.env["account.account"].search(domain) else: self.account_ids = None diff --git a/account_financial_report/wizard/aged_partner_balance_wizard_view.xml b/account_financial_report/wizard/aged_partner_balance_wizard_view.xml index bcebe58a..337b2114 100644 --- a/account_financial_report/wizard/aged_partner_balance_wizard_view.xml +++ b/account_financial_report/wizard/aged_partner_balance_wizard_view.xml @@ -35,6 +35,24 @@