Skip to content

Commit

Permalink
Merge dcc68e6 into b61ced4
Browse files Browse the repository at this point in the history
  • Loading branch information
eLBati committed May 30, 2016
2 parents b61ced4 + dcc68e6 commit 1d42a5b
Show file tree
Hide file tree
Showing 13 changed files with 381 additions and 0 deletions.
60 changes: 60 additions & 0 deletions account_tax_balance/README.rst
@@ -0,0 +1,60 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3

============
Tax Balances
============

This module allows to compute tax balances within a certain date range.
It depends on date_range module and exposes 'compute' methods that can be called by other modules (like localization ones)

Usage
=====

Accounting --> Reporting --> Taxes Balance

Select the company, the date range, the target moves and 'open taxes'

.. figure:: /account_tax_balance/static/description/tax_balance.png

.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/91/9.0

Bug Tracker
===========

Bugs are tracked on `GitHub Issues
<https://github.com/OCA/account-financial-reporting/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smashing it by providing a detailed and welcomed feedback.

Credits
=======

Images
------

* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.

Contributors
------------

* Lorenzo Battistini <lorenzo.battistini@agilebg.com>
* Giovanni Capalbo <giovanni@therp.nl>

Maintainer
----------

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

This module is maintained by the OCA.

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

To contribute to this module, please visit https://odoo-community.org.
6 changes: 6 additions & 0 deletions 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
26 changes: 26 additions & 0 deletions account_tax_balance/__openerp__.py
@@ -0,0 +1,26 @@
# -*- 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, Therp BV, "
"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",
],
"images": [
'images/tax_balance.png',
]
}
5 changes: 5 additions & 0 deletions 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
94 changes: 94 additions & 0 deletions account_tax_balance/models/account_tax.py
@@ -0,0 +1,94 @@
# -*- 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


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):
context = self.env.context
return (
context.get('from_date', fields.Date.context_today(self)),
context.get('to_date', fields.Date.context_today(self)),
context.get('company_id', self.env.user.company_id.id),
context.get('target_move', 'posted')
)

def _compute_balance(self):
for tax in self:
tax.balance = tax.compute_balance(tax_or_base='tax')
tax.base_balance = tax.compute_balance(tax_or_base='base')

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_partial_domain(self, from_date, to_date, company_id):
return [
('date', '<=', to_date),
('date', '>=', from_date),
('company_id', '=', company_id),
]

def compute_balance(self, tax_or_base='tax'):
self.ensure_one()
move_lines = self.get_move_lines_domain(tax_or_base=tax_or_base)
total = sum([l.balance for l in move_lines])
return total

def get_balance_domain(self, state_list):
return [
('move_id.state', 'in', state_list),
('tax_line_id', '=', self.id),
]

def get_base_balance_domain(self, state_list):
return [
('move_id.state', 'in', state_list),
('tax_ids', 'in', self.id),
]

def get_move_lines_domain(self, tax_or_base='tax'):
move_line_model = self.env['account.move.line']
from_date, to_date, company_id, target_move = self.get_context_values()
state_list = self.get_target_state_list(target_move)
domain = self.get_move_line_partial_domain(
from_date, to_date, company_id)
balance_domain = []
if tax_or_base == 'tax':
balance_domain = self.get_balance_domain(state_list)
elif tax_or_base == 'base':
balance_domain = self.get_base_balance_domain(state_list)
domain.extend(balance_domain)
return move_line_model.search(domain)

def get_lines_action(self, tax_or_base='tax'):
move_lines = self.get_move_lines_domain(tax_or_base=tax_or_base)
move_line_ids = [l.id for l in move_lines]
action = self.env.ref('account.action_account_moves_all_tree')
vals = action.read()[0]
vals['context'] = {}
vals['domain'] = [('id', 'in', move_line_ids)]
return vals

@api.multi
def view_tax_lines(self):
self.ensure_one()
return self.get_lines_action(tax_or_base='tax')

@api.multi
def view_base_lines(self):
self.ensure_one()
return self.get_lines_action(tax_or_base='base')
Binary file added account_tax_balance/static/description/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions account_tax_balance/tests/__init__.py
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
# © 2016 Lorenzo Battistini - Agile Business Group
# © 2016 Giovanni Capalbo
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import test_account_tax_balance
50 changes: 50 additions & 0 deletions account_tax_balance/tests/test_account_tax_balance.py
@@ -0,0 +1,50 @@
# -*- coding: utf-8 -*-
# © 2016 Lorenzo Battistini - Agile Business Group
# © 2016 Giovanni Capalbo <giovanni@therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openerp.tests.common import TransactionCase


class TestAccountTaxBalance(TransactionCase):

def test_tax_balance(self):
tax_account_id = self.env['account.account'].search(
[('name', '=', 'Tax Paid')], limit=1).id
tax = self.env['account.tax'].create({
'name': 'Tax 10.0',
'amount': 10.0,
'amount_type': 'fixed',
'account_id': tax_account_id,
})
invoice_account_id = self.env['account.account'].search(
[('user_type_id', '=', self.env.ref(
'account.data_account_type_receivable'
).id)], limit=1).id
invoice_line_account_id = self.env['account.account'].search(
[('user_type_id', '=', self.env.ref(
'account.data_account_type_expenses').id)], limit=1).id
invoice = self.env['account.invoice'].create({
'partner_id': self.env.ref('base.res_partner_2').id,
'account_id': invoice_account_id,
'type': 'out_invoice',
})

self.env['account.invoice.line'].create({
'product_id': self.env.ref('product.product_product_4').id,
'quantity': 1.0,
'price_unit': 100.0,
'invoice_id': invoice.id,
'name': 'product that cost 100',
'account_id': invoice_line_account_id,
'invoice_line_tax_ids': [(6, 0, [tax.id])],
})
invoice._onchange_invoice_line_ids()
invoice._convert_to_write(invoice._cache)
self.assertEqual(invoice.state, 'draft')

# change the state of invoice to open by clicking Validate button
invoice.signal_workflow('invoice_open')

self.assertEquals(tax.base_balance, -100)
self.assertEquals(tax.balance, -10)
49 changes: 49 additions & 0 deletions account_tax_balance/views/account_tax_view.xml
@@ -0,0 +1,49 @@
<?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>
<button type="object" name="view_tax_lines" string="View tax lines" icon="gtk-find"></button>
<button type="object" name="view_base_lines" string="View base lines" icon="gtk-copy"></button>
</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">Taxes Balance</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 changes: 5 additions & 0 deletions 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
40 changes: 40 additions & 0 deletions account_tax_balance/wizard/open_tax_balances.py
@@ -0,0 +1,40 @@
# -*- 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


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 changes: 40 additions & 0 deletions 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="Taxes Balance">
<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">Taxes Balance</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>

0 comments on commit 1d42a5b

Please sign in to comment.