Browse Source

[IMP] remove unused field has_moves

pull/767/head
Joan Sisquella 4 years ago
parent
commit
1aeded7fe2
  1. 54
      account_tax_balance/models/account_tax.py
  2. 1
      account_tax_balance/views/account_tax_view.xml

54
account_tax_balance/models/account_tax.py

@ -2,7 +2,7 @@
# Copyright 2016 Antonio Espinosa <antonio.espinosa@tecnativa.com> # Copyright 2016 Antonio Espinosa <antonio.espinosa@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import _, api, fields, models
from odoo import api, fields, models
class AccountTax(models.Model): class AccountTax(models.Model):
@ -18,11 +18,6 @@ class AccountTax(models.Model):
base_balance_refund = fields.Float( base_balance_refund = fields.Float(
string="Base Balance Refund", compute="_compute_balance" string="Base Balance Refund", compute="_compute_balance"
) )
has_moves = fields.Boolean(
string="Has balance in period",
compute="_compute_has_moves",
search="_search_has_moves",
)
def get_context_values(self): def get_context_values(self):
context = self.env.context context = self.env.context
@ -34,57 +29,10 @@ class AccountTax(models.Model):
context.get("target_move", "posted"), context.get("target_move", "posted"),
) )
def _account_tax_ids_with_moves(self):
""" Return all account.tax ids for which there is at least
one account.move.line in the context period
for the user company.
Caveat: this ignores record rules and ACL but it is good
enough for filtering taxes with activity during the period.
"""
from_date, to_date, company_ids, _ = self.get_context_values()
company_ids = tuple(company_ids)
req = """
SELECT id
FROM account_tax at
WHERE
company_id in %s AND
EXISTS (
SELECT 1 FROM account_move_Line aml
WHERE
date >= %s AND
date <= %s AND
company_id in %s AND (
tax_line_id = at.id OR
EXISTS (
SELECT 1 FROM account_move_line_account_tax_rel
WHERE account_move_line_id = aml.id AND
account_tax_id = at.id
)
)
)
"""
self.env.cr.execute(
req, (company_ids, from_date, to_date, company_ids)
) # pylint: disable=E8103
return [r[0] for r in self.env.cr.fetchall()]
def _compute_has_moves(self):
ids_with_moves = set(self._account_tax_ids_with_moves())
for tax in self:
tax.has_moves = tax.id in ids_with_moves
@api.model @api.model
def _is_unsupported_search_operator(self, operator): def _is_unsupported_search_operator(self, operator):
return operator != "=" return operator != "="
@api.model
def _search_has_moves(self, operator, value):
if self._is_unsupported_search_operator(operator) or not value:
raise ValueError(_("Unsupported search operator"))
ids_with_moves = self._account_tax_ids_with_moves()
return [("id", "in", ids_with_moves)]
def _compute_balance(self): def _compute_balance(self):
total_balance_regular = self.compute_balance( total_balance_regular = self.compute_balance(
tax_or_base="tax", move_type="regular" tax_or_base="tax", move_type="regular"

1
account_tax_balance/views/account_tax_view.xml

@ -86,7 +86,6 @@
<field name="name">Taxes Balance</field> <field name="name">Taxes Balance</field>
<field name="res_model">account.tax</field> <field name="res_model">account.tax</field>
<field name="view_mode">tree</field> <field name="view_mode">tree</field>
<field name="domain">[('has_moves', '=', True)]</field>
<field name="view_id" ref="view_tax_tree_balance" /> <field name="view_id" ref="view_tax_tree_balance" />
<field name="search_view_id" ref="view_tax_search_balance" /> <field name="search_view_id" ref="view_tax_search_balance" />
</record> </record>

Loading…
Cancel
Save