Browse Source

[IMP] account_tax_balance: show only taxes with amls

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

20
account_tax_balance/models/account_tax.py

@ -18,6 +18,11 @@ 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(
compute="_compute_balance",
search="_search_has_moves",
string="Has balance in period",
)
def get_context_values(self): def get_context_values(self):
context = self.env.context context = self.env.context
@ -30,8 +35,11 @@ class AccountTax(models.Model):
) )
@api.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): def _compute_regular_and_refund(self, total):
tax_ids = total.keys() tax_ids = total.keys()
@ -43,9 +51,9 @@ class AccountTax(models.Model):
move_types = total[tax_id].keys() move_types = total[tax_id].keys()
for move_type in move_types: for move_type in move_types:
if move_type in ["receivable_refund", "payable_refund"]: 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: 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 return total_regular, total_refund
def _compute_balance(self): def _compute_balance(self):
@ -61,8 +69,8 @@ class AccountTax(models.Model):
founded_taxes_ids = set(list(total_balance_tax.keys())).union( founded_taxes_ids = set(list(total_balance_tax.keys())).union(
set(list(total_balance_base.keys())) 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 = ( tax.balance_regular = (
total_balance_regular[tax.id] total_balance_regular[tax.id]
if tax.id in total_balance_regular.keys() if tax.id in total_balance_regular.keys()

6
account_tax_balance/views/account_tax_view.xml

@ -65,6 +65,11 @@
<field name="name" /> <field name="name" />
<field name="description" string="Short Name" /> <field name="description" string="Short Name" />
<field name="type_tax_use" /> <field name="type_tax_use" />
<filter
name="filter_has_moves"
string="Has Moves"
domain="[('has_moves', '=', True)]"
/>
<group expand="0" string="Group By"> <group expand="0" string="Group By">
<filter <filter
name="tax_group" name="tax_group"
@ -86,6 +91,7 @@
<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="context">{"search_default_filter_has_moves":1}</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