Browse Source

ADD account_tax_balance: Compute tax balances based on date range

IMP filters and views

Avoid create and delete taxes

ADD base balance
pull/190/head
eLBati 9 years ago
parent
commit
7d4cd396a5
  1. 6
      account_tax_balance/__init__.py
  2. 22
      account_tax_balance/__openerp__.py
  3. 5
      account_tax_balance/models/__init__.py
  4. 86
      account_tax_balance/models/account_tax.py
  5. 47
      account_tax_balance/views/account_tax_view.xml
  6. 5
      account_tax_balance/wizard/__init__.py
  7. 41
      account_tax_balance/wizard/open_tax_balances.py
  8. 40
      account_tax_balance/wizard/open_tax_balances_view.xml

6
account_tax_balance/__init__.py

@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
# © 2016 Lorenzo Battistini - Agile Business Group
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import models
from . import wizard

22
account_tax_balance/__openerp__.py

@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
# © 2016 Lorenzo Battistini - Agile Business Group
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Tax Balance",
"summary": "Compute tax balances based on date range",
"version": "9.0.1.0.0",
"category": "Accounting & Finance",
"website": "https://www.agilebg.com/",
"author": "Agile Business Group, Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": [
"account",
"date_range",
],
"data": [
"wizard/open_tax_balances_view.xml",
"views/account_tax_view.xml",
],
}

5
account_tax_balance/models/__init__.py

@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# © 2016 Lorenzo Battistini - Agile Business Group
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import account_tax

86
account_tax_balance/models/account_tax.py

@ -0,0 +1,86 @@
# -*- coding: utf-8 -*-
# © 2016 Lorenzo Battistini - Agile Business Group
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp import models, fields
class AccountTax(models.Model):
_inherit = 'account.tax'
balance = fields.Float(string="Balance", compute="_compute_balance")
base_balance = fields.Float(
string="Base Balance", compute="_compute_balance")
def get_context_values(self):
if not self.env.context.get('from_date'):
from_date = fields.Date.context_today(self)
else:
from_date = self.env.context['from_date']
if not self.env.context.get('to_date'):
to_date = fields.Date.context_today(self)
else:
to_date = self.env.context['to_date']
if not self.env.context.get('target_move'):
target_move = 'posted'
else:
target_move = self.env.context['target_move']
if not self.env.context.get('company_id'):
company_id = self.env.user.company_id.id
else:
company_id = self.env.context['company_id']
return from_date, to_date, company_id, target_move
def _compute_balance(self):
from_date, to_date, company_id, target_move = self.get_context_values()
for tax in self:
tax.balance = tax.compute_balance(
from_date, to_date, company_id, target_move)
tax.base_balance = tax.compute_base_balance(
from_date, to_date, company_id, target_move)
def get_target_state_list(self, target_move="posted"):
if target_move == 'posted':
state = ['posted']
elif target_move == 'all':
state = ['posted', 'draft']
else:
state = []
return state
def get_move_line_domain(self, from_date, to_date, company_id):
return [
('date', '<=', to_date),
('date', '>=', from_date),
('company_id', '=', company_id),
]
def compute_balance(
self, from_date, to_date, company_id, target_move="posted"
):
self.ensure_one()
move_line_model = self.env['account.move.line']
state_list = self.get_target_state_list(target_move)
domain = self.get_move_line_domain(from_date, to_date, company_id)
domain.extend([
('move_id.state', 'in', state_list),
('tax_line_id', '=', self.id),
])
move_lines = move_line_model.search(domain)
total = sum([l.balance for l in move_lines])
return total
def compute_base_balance(
self, from_date, to_date, company_id, target_move="posted"
):
self.ensure_one()
move_line_model = self.env['account.move.line']
state_list = self.get_target_state_list(target_move)
domain = self.get_move_line_domain(from_date, to_date, company_id)
domain.extend([
('move_id.state', 'in', state_list),
('tax_ids', 'in', self.id),
])
move_lines = move_line_model.search(domain)
total = sum([l.balance for l in move_lines])
return total

47
account_tax_balance/views/account_tax_view.xml

@ -0,0 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_tax_tree_balance" model="ir.ui.view">
<field name="name">account.tax.tree.balance</field>
<field name="model">account.tax</field>
<field eval="100" name="priority"/>
<field name="arch" type="xml">
<tree string="Account Tax" create="false" delete="false">
<field name="name"/>
<field name="description" string="Short Name"/>
<field name="account_id"/>
<field name="balance" sum="Total"></field>
<field name="base_balance" sum="Base Total"></field>
</tree>
</field>
</record>
<record id="view_tax_search_balance" model="ir.ui.view">
<field name="name">account.tax.search.balance</field>
<field name="model">account.tax</field>
<field eval="100" name="priority"/>
<field name="arch" type="xml">
<search string="Account Tax">
<field name="name"/>
<field name="tag_ids"/>
<field name="description" string="Short Name"/>
<field name="type_tax_use"/>
<field name="account_id"/>
<group expand="0" string="Group By">
<filter string="Tax Group" domain="[]" context="{'group_by':'tax_group_id'}"/>
<filter string="Tax Scope" domain="[]" context="{'group_by':'type_tax_use'}"/>
<filter string="Account" domain="[]" context="{'group_by':'account_id'}"/>
</group>
</search>
</field>
</record>
<record id="action_tax_balances_tree" model="ir.actions.act_window">
<field name="name">Tax Balances</field>
<field name="res_model">account.tax</field>
<field name="view_type">form</field>
<field name="view_mode">tree</field>
<field name="view_id" ref="view_tax_tree_balance"/>
<field name="search_view_id" ref="view_tax_search_balance"/>
</record>
</data>
</openerp>

5
account_tax_balance/wizard/__init__.py

@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# © 2016 Lorenzo Battistini - Agile Business Group
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import open_tax_balances

41
account_tax_balance/wizard/open_tax_balances.py

@ -0,0 +1,41 @@
# -*- coding: utf-8 -*-
# © 2016 Lorenzo Battistini - Agile Business Group
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp import models, fields, api
from openerp.tools.translate import _
class OpenTaxBalances(models.TransientModel):
_name = 'wizard.open.tax.balances'
company_id = fields.Many2one(
'res.company', 'Company', required=True,
default=lambda self: self.env.user.company_id)
from_date = fields.Date('From date', required=True)
to_date = fields.Date('To date', required=True)
date_range_id = fields.Many2one('date.range', 'Date range')
target_move = fields.Selection([
('posted', 'All Posted Entries'),
('all', 'All Entries'),
], 'Target Moves', required=True, default='posted')
@api.onchange('date_range_id')
def onchange_date_range_id(self):
if self.date_range_id:
self.from_date = self.date_range_id.date_start
self.to_date = self.date_range_id.date_end
else:
self.from_date = self.to_date = None
@api.multi
def open_taxes(self):
self.ensure_one()
action = self.env.ref('account_tax_balance.action_tax_balances_tree')
vals = action.read()[0]
vals['context'] = {
'from_date': self.from_date,
'to_date': self.to_date,
'target_move': self.target_move,
'company_id': self.company_id.id,
}
return vals

40
account_tax_balance/wizard/open_tax_balances_view.xml

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="wizard_open_tax_balances" model="ir.ui.view">
<field name="name">wizard_open_tax_balances</field>
<field name="model">wizard.open.tax.balances</field>
<field name="arch" type="xml">
<form string="Open Tax Balances">
<group>
<field name="company_id"/>
<field name="date_range_id"/>
<field name="from_date"></field>
<field name="to_date"></field>
<field name="target_move"></field>
</group>
<footer>
<button string="Open Taxes" name="open_taxes" type="object" class="oe_highlight"/>
or
<button string="Cancel" class="oe_link" special="cancel"/>
</footer>
</form>
</field>
</record>
<record id="action_open_tax_balances" model="ir.actions.act_window">
<field name="name">Open Tax Balances</field>
<field name="res_model">wizard.open.tax.balances</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="view_id" ref="wizard_open_tax_balances"/>
<field name="target">new</field>
</record>
<menuitem
action="action_open_tax_balances"
id="menu_action_open_tax_balances"
parent="account.menu_finance_reports"
groups="account.group_account_user,account.group_account_manager"></menuitem>
</data>
</openerp>
Loading…
Cancel
Save