Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
astirpe committed Dec 4, 2018
1 parent 9ae6bc0 commit 32c2ec5
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 1 deletion.
1 change: 0 additions & 1 deletion l10n_nl_tax_statement_icp/readme/ROADMAP.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
* Add checks to avoid errors in the report, e.g. no country, wrong country, no VAT code, tax-code not matching fiscal position, etc..
* Add unit tests
119 changes: 119 additions & 0 deletions l10n_nl_tax_statement_icp/tests/test_l10n_nl_tax_statement_icp.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
# Copyright 2018 Onestein (<http://www.onestein.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from datetime import datetime
from dateutil.relativedelta import relativedelta

from odoo import fields
from odoo.exceptions import UserError
from odoo.tools import DEFAULT_SERVER_DATE_FORMAT as DF
from odoo.tests.common import at_install, post_install

from odoo.addons.l10n_nl_tax_statement.tests.test_l10n_nl_vat_statement\
import TestVatStatement

Expand Down Expand Up @@ -37,6 +44,8 @@ def test_03_post_final(self):
self.statement_with_icp.statement_update()
with self.assertRaises(UserError):
self.statement_with_icp.post()

self.statement_1.statement_update()
self.statement_1.post()
self.assertEqual(self.statement_1.state, 'posted')

Expand All @@ -55,3 +64,113 @@ def test_03_post_final(self):

with self.assertRaises(UserError):
self.statement_with_icp.icp_update()

def test_12_undeclared_invoice(self):
self.invoice_1._onchange_invoice_line_ids()
self.invoice_1.action_invoice_open()
self.invoice_1.move_id.add_move_in_statement()
for line in self.invoice_1.move_id.line_ids:
self.assertEqual(line.l10n_nl_vat_statement_include, True)
self.invoice_1.move_id.unlink_move_from_statement()
for line in self.invoice_1.move_id.line_ids:
self.assertEqual(line.l10n_nl_vat_statement_include, False)

self.statement_1.statement_update()
self.assertEqual(len(self.statement_1.line_ids.ids), 22)
self.statement_1.post()

invoice2 = self.invoice_1.copy()
invoice2._onchange_invoice_line_ids()
invoice2.action_invoice_open()
statement2 = self.env['l10n.nl.vat.statement'].create({
'name': 'Statement 2',
})
statement2.statement_update()
statement2.unreported_move_from_date = fields.Date.today()
statement2.onchange_unreported_move_from_date()
self.assertFalse(statement2.unreported_move_ids)

self.assertEqual(self.statement_1.btw_total, 10.5)
self.assertEqual(self.statement_1.format_btw_total, '10.50')

for line in self.statement_1.line_ids:
self.assertTrue(line.is_readonly)

def test_13_no_previous_statement_posted(self):
statement2 = self.env['l10n.nl.vat.statement'].create({
'name': 'Statement 2',
})
statement2.statement_update()
with self.assertRaises(UserError):
statement2.post()

self.assertEqual(self.statement_1.btw_total, 0.)
self.assertEqual(self.statement_1.format_btw_total, '0.00')

for line in self.statement_1.line_ids:
self.assertFalse(line.is_readonly)

@at_install(False)
@post_install(True)
def test_14_is_invoice_basis(self):
company = self.statement_1.company_id
has_invoice_basis = self.env['ir.model.fields'].sudo().search_count([
('model', '=', 'res.company'),
('name', '=', 'l10n_nl_tax_invoice_basis')
])
if has_invoice_basis:
company.l10n_nl_tax_invoice_basis = True
self.statement_1._compute_is_invoice_basis()
self.assertEqual(self.statement_1.is_invoice_basis, True)
company.l10n_nl_tax_invoice_basis = False
self.statement_1._compute_is_invoice_basis()
self.assertEqual(self.statement_1.is_invoice_basis, False)

self.assertEqual(self.statement_1.btw_total, 0.)
self.assertEqual(self.statement_1.format_btw_total, '0.00')

for line in self.statement_1.line_ids:
self.assertTrue(line.is_readonly)

@at_install(False)
@post_install(True)
def test_15_invoice_basis_undeclared_invoice(self):
self.invoice_1._onchange_invoice_line_ids()
self.invoice_1.action_invoice_open()
self.statement_1.statement_update()
self.assertEqual(len(self.statement_1.line_ids.ids), 22)
self.statement_1.with_context(
skip_check_config_tag_3b_omzet=True
).post()

has_invoice_basis = self.env['ir.model.fields'].sudo().search_count([
('model', '=', 'res.company'),
('name', '=', 'l10n_nl_tax_invoice_basis')
])
if has_invoice_basis:

self.statement_1.company_id.l10n_nl_tax_invoice_basis = True
self.statement_1.company_id.country_id = self.env.ref('base.nl')

invoice2 = self.invoice_1.copy()
d_date = datetime.strptime(fields.Date.today(), DF)
d_date = d_date + relativedelta(months=-4, day=1)
old_date = fields.Date.to_string(d_date)
invoice2.date_invoice = old_date
invoice2.action_invoice_open()

statement2 = self.env['l10n.nl.vat.statement'].create({
'name': 'Statement 2',
})
statement2.unreported_move_from_date = fields.Date.today()
statement2.onchange_unreported_move_from_date()
statement2.statement_update()
statement2.with_context(
skip_check_config_tag_3b_omzet=True
).post()

self.assertEqual(self.statement_1.btw_total, 10.5)
self.assertEqual(self.statement_1.format_btw_total, '10.50')

for line in self.statement_1.line_ids:
self.assertTrue(line.is_readonly)

0 comments on commit 32c2ec5

Please sign in to comment.