From f5d7ef0596f98395b126b018410e17882cacfe6a 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 | 6 ++++++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/account_tax_balance/models/account_tax.py b/account_tax_balance/models/account_tax.py index d32683e8..9abacf11 100644 --- a/account_tax_balance/models/account_tax.py +++ b/account_tax_balance/models/account_tax.py @@ -18,6 +18,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 @@ -30,8 +35,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() @@ -43,9 +51,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): @@ -61,8 +69,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 bb23ace0..deab5ef2 100644 --- a/account_tax_balance/views/account_tax_view.xml +++ b/account_tax_balance/views/account_tax_view.xml @@ -65,6 +65,11 @@ + Taxes Balance account.tax tree + {"search_default_filter_has_moves":1}