Browse Source

[13.0][MIG] account_tax_balance

pull/619/head
Andrea 5 years ago
parent
commit
ca8d924878
  1. 2
      account_tax_balance/__manifest__.py
  2. 1
      account_tax_balance/models/account_move.py
  3. 5
      account_tax_balance/models/account_move_line.py
  4. 7
      account_tax_balance/models/account_tax.py
  5. 80
      account_tax_balance/tests/test_account_tax_balance.py
  6. 5
      account_tax_balance/views/account_tax_view.xml
  7. 1
      account_tax_balance/wizard/open_tax_balances.py
  8. 1
      account_tax_balance/wizard/open_tax_balances_view.xml

2
account_tax_balance/__manifest__.py

@ -6,7 +6,7 @@
{
"name": "Tax Balance",
"summary": "Compute tax balances based on date range",
"version": "12.0.2.0.0",
"version": "13.0.1.0.0",
"category": "Invoices & Payments",
"website": "https://github.com/OCA/account-financial-reporting",
"author": "Agile Business Group, Therp BV, Tecnativa, ACSONE SA/NV, "

1
account_tax_balance/models/account_move.py

@ -22,7 +22,6 @@ class AccountMove(models.Model):
selection='_selection_move_type',
compute='_compute_move_type', store=True, readonly=True)
@api.multi
@api.depends(
'line_ids.account_id.internal_type', 'line_ids.balance',
'line_ids.account_id.user_type_id.type'

5
account_tax_balance/models/account_move_line.py

@ -1,16 +1,15 @@
# Copyright 2017 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, models
from odoo import models
class AccountMoveLine(models.Model):
_inherit = 'account.move.line'
@api.model_cr
def init(self):
res = super(AccountMoveLine, self).init()
res = super().init()
self._cr.execute("""
SELECT indexname FROM pg_indexes
WHERE indexname = 'account_move_line_date_tax_line_id_idx'

7
account_tax_balance/models/account_tax.py

@ -75,7 +75,6 @@ class AccountTax(models.Model):
req, (company_ids, from_date, to_date, company_ids))
return [r[0] for r in self.env.cr.fetchall()]
@api.multi
def _compute_has_moves(self):
ids_with_moves = set(self._account_tax_ids_with_moves())
for tax in self:
@ -186,32 +185,26 @@ class AccountTax(models.Model):
vals['domain'] = domain
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')
@api.multi
def view_tax_regular_lines(self):
self.ensure_one()
return self.get_lines_action(tax_or_base='tax', move_type='regular')
@api.multi
def view_base_regular_lines(self):
self.ensure_one()
return self.get_lines_action(tax_or_base='base', move_type='regular')
@api.multi
def view_tax_refund_lines(self):
self.ensure_one()
return self.get_lines_action(tax_or_base='tax', move_type='refund')
@api.multi
def view_base_refund_lines(self):
self.ensure_one()
return self.get_lines_action(tax_or_base='base', move_type='refund')

80
account_tax_balance/tests/test_account_tax_balance.py

@ -1,5 +1,6 @@
# © 2016 Lorenzo Battistini - Agile Business Group
# © 2016 Giovanni Capalbo <giovanni@therp.nl>
# Copyright 2016 Lorenzo Battistini - Agile Business Group
# Copyright 2016 Giovanni Capalbo <giovanni@therp.nl>
# Copyright 2019 Andrea Stirpe <a.stirpe@onestein.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from datetime import datetime
@ -15,7 +16,7 @@ from odoo.tests.common import HttpCase
class TestAccountTaxBalance(HttpCase):
def setUp(self):
super(TestAccountTaxBalance, self).setUp()
super().setUp()
self.range_type = self.env['date.range.type'].create(
{'name': 'Fiscal year',
'company_id': False,
@ -28,7 +29,7 @@ class TestAccountTaxBalance(HttpCase):
'name_prefix': '%s-' % self.current_year,
'type_id': self.range_type.id,
'duration_count': 1,
'unit_of_time': MONTHLY,
'unit_of_time': str(MONTHLY),
'count': 12})
range_generator.action_apply()
self.range = self.env['date.range']
@ -45,12 +46,7 @@ class TestAccountTaxBalance(HttpCase):
'name': 'Tax 10.0%',
'amount': 10.0,
'amount_type': 'percent',
'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'].create({
'user_type_id': self.env.ref(
'account.data_account_type_expenses'
@ -58,27 +54,28 @@ class TestAccountTaxBalance(HttpCase):
'code': 'EXPTEST',
'name': 'Test expense account',
}).id
invoice = self.env['account.invoice'].create({
product = self.env.ref('product.product_product_4')
invoice = self.env['account.move'].create({
'partner_id': self.env.ref('base.res_partner_2').id,
'account_id': invoice_account_id,
'type': 'out_invoice',
'invoice_line_ids': [
(0, None, {
'product_id': product.id,
'quantity': 1.0,
'price_unit': 100.0,
'name': 'product that cost 100',
'account_id': invoice_line_account_id,
'tax_ids': [(6, 0, [tax.id])],
}),
]
})
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.action_invoice_open()
invoice.action_post()
self.assertEqual(tax.base_balance, 100.)
self.assertEqual(tax.balance, 10.)
@ -116,12 +113,12 @@ class TestAccountTaxBalance(HttpCase):
base_action = tax.view_base_lines()
tax_action_move_lines = self.env['account.move.line'].\
search(tax_action['domain'])
self.assertTrue(invoice.move_id.line_ids & tax_action_move_lines)
self.assertTrue(invoice.line_ids & tax_action_move_lines)
self.assertEqual(
tax_action['xml_id'], 'account.action_account_moves_all_tree')
base_action_move_lines = self.env['account.move.line'].\
search(base_action['domain'])
self.assertTrue(invoice.move_id.line_ids & base_action_move_lines)
self.assertTrue(invoice.line_ids & base_action_move_lines)
self.assertEqual(
base_action['xml_id'], 'account.action_account_moves_all_tree')
@ -131,27 +128,28 @@ class TestAccountTaxBalance(HttpCase):
state_list = tax.get_target_state_list(target_move='whatever')
self.assertEqual(state_list, [])
refund = self.env['account.invoice'].create({
product = self.env.ref('product.product_product_2')
refund = self.env['account.move'].create({
'partner_id': self.env.ref('base.res_partner_2').id,
'account_id': invoice_account_id,
'type': 'out_refund',
'invoice_line_ids': [
(0, None, {
'product_id': product.id,
'quantity': 1.0,
'price_unit': 25.0,
'name': 'returned product that cost 25',
'account_id': invoice_line_account_id,
'tax_ids': [(6, 0, [tax.id])],
}),
]
})
self.env['account.invoice.line'].create({
'product_id': self.env.ref('product.product_product_2').id,
'quantity': 1.0,
'price_unit': 25.0,
'invoice_id': refund.id,
'name': 'returned product that cost 25',
'account_id': invoice_line_account_id,
'invoice_line_tax_ids': [(6, 0, [tax.id])],
})
refund._onchange_invoice_line_ids()
refund._convert_to_write(invoice._cache)
self.assertEqual(refund.state, 'draft')
# change the state of refund to open by clicking Validate button
refund.action_invoice_open()
refund.action_post()
# force the _compute_balance() to be triggered
tax._compute_balance()
@ -164,9 +162,12 @@ class TestAccountTaxBalance(HttpCase):
self.assertEqual(tax.balance_refund, -2.5)
# Taxes on liquidity type moves are included
tax_repartition_line = tax.invoice_repartition_line_ids\
.filtered(lambda line: line.repartition_type == 'tax')
liquidity_account_id = self.env['account.account'].search(
[('internal_type', '=', 'liquidity')], limit=1).id
self.env['account.move'].create({
move = self.env['account.move'].create({
'type': 'entry',
'date': Date.context_today(self.env.user),
'journal_id': self.env['account.journal'].search(
[('type', '=', 'bank')], limit=1).id,
@ -183,13 +184,14 @@ class TestAccountTaxBalance(HttpCase):
'name': 'Bank Fees',
'tax_ids': [(4, tax.id)]
}), (0, 0, {
'account_id': tax.account_id.id,
'account_id': tax_account_id,
'debit': 0,
'credit': 10,
'name': 'Bank Fees',
'tax_line_id': tax.id,
'tax_repartition_line_id': tax_repartition_line.id,
})],
}).post()
})
move.action_post()
tax.refresh()
self.assertEqual(tax.base_balance, 175.)
self.assertEqual(tax.balance, 17.5)

5
account_tax_balance/views/account_tax_view.xml

@ -12,7 +12,6 @@
<tree string="Account Tax" create="false" delete="false">
<field name="name"/>
<field name="description" string="Short Name"/>
<field name="account_id"/>
<field name="balance_regular" sum="Total"/>
<button type="object" name="view_tax_regular_lines"
string="View tax regular lines" icon="fa-search-plus"/>
@ -42,14 +41,11 @@
<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 name="tax_group" string="Tax Group" domain="[]" context="{'group_by':'tax_group_id'}"/>
<filter name="tax_scope" string="Tax Scope" domain="[]" context="{'group_by':'type_tax_use'}"/>
<filter name="tax_account" string="Account" domain="[]" context="{'group_by':'account_id'}"/>
</group>
</search>
</field>
@ -58,7 +54,6 @@
<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="domain">[('has_moves', '=', True)]</field>
<field name="view_id" ref="view_tax_tree_balance"/>

1
account_tax_balance/wizard/open_tax_balances.py

@ -27,7 +27,6 @@ class WizardOpenTaxBalances(models.TransientModel):
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')

1
account_tax_balance/wizard/open_tax_balances_view.xml

@ -26,7 +26,6 @@
<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>

Loading…
Cancel
Save