From 409aff365800004db7a0957c64049cfe9a15786a Mon Sep 17 00:00:00 2001 From: Joan Sisquella Date: Thu, 22 Apr 2021 10:22:36 +0200 Subject: [PATCH] [IMP] account_tax_balance: show only taxes with amls --- account_tax_balance/models/account_tax.py | 20 +++++++++++++------ .../views/account_tax_view.xml | 2 ++ .../wizard/open_tax_balances.py | 1 + 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/account_tax_balance/models/account_tax.py b/account_tax_balance/models/account_tax.py index 73b9f1d4..21c8a55d 100644 --- a/account_tax_balance/models/account_tax.py +++ b/account_tax_balance/models/account_tax.py @@ -26,6 +26,11 @@ class AccountTax(models.Model): base_balance_refund = fields.Float( string="Base Balance Refund", compute="_compute_balance", ) + has_moves = fields.Boolean( + compute="_compute_balance", + search="_search_has_moves", + string="Has balance in period", + ) def get_context_values(self): context = self.env.context @@ -37,8 +42,11 @@ class AccountTax(models.Model): ) @api.model - def _is_unsupported_search_operator(self, operator): - return operator != '=' + def _search_has_moves(self, operator, value): + assert isinstance(value, bool), "Not implemented" + assert operator == "=", "Not implemented" + ids_with_moves = self.search([]).filtered(lambda t: t.has_moves == value) + return [('id', 'in', ids_with_moves.ids)] def _compute_regular_and_refund(self, total): tax_ids = total.keys() @@ -50,9 +58,9 @@ class AccountTax(models.Model): move_types = total[tax_id].keys() for move_type in move_types: if move_type in ["receivable_refund", "payable_refund"]: - total_refund[tax_id] += total[tax_id][move_type] + total_refund[tax_id] += (-1) * total[tax_id][move_type] else: - total_regular[tax_id] += total[tax_id][move_type] + total_regular[tax_id] += (-1) * total[tax_id][move_type] return total_regular, total_refund def _compute_balance(self): @@ -68,8 +76,8 @@ class AccountTax(models.Model): founded_taxes_ids = set(list(total_balance_tax.keys())).union( set(list(total_balance_base.keys())) ) - for tax_id in list(founded_taxes_ids): - tax = self.browse(tax_id) + for tax in self: + tax.has_moves = tax.id in list(founded_taxes_ids) tax.balance_regular = ( total_balance_regular[tax.id] if tax.id in total_balance_regular.keys() diff --git a/account_tax_balance/views/account_tax_view.xml b/account_tax_balance/views/account_tax_view.xml index b5ea3f86..7ade7524 100644 --- a/account_tax_balance/views/account_tax_view.xml +++ b/account_tax_balance/views/account_tax_view.xml @@ -46,6 +46,7 @@ + @@ -60,6 +61,7 @@ account.tax form tree + {"search_default_filter_has_moves":1} diff --git a/account_tax_balance/wizard/open_tax_balances.py b/account_tax_balance/wizard/open_tax_balances.py index 6063a9db..b5dedb8b 100644 --- a/account_tax_balance/wizard/open_tax_balances.py +++ b/account_tax_balance/wizard/open_tax_balances.py @@ -55,5 +55,6 @@ class WizardOpenTaxBalances(models.TransientModel): 'to_date': self.to_date, 'target_move': self.target_move, 'company_id': self.company_id.id, + 'search_default_filter_has_moves': True, } return vals