From 9e4db5e0b6614a57ed44778d1ad55ee54028e54d Mon Sep 17 00:00:00 2001 From: Andrea Stirpe Date: Fri, 6 Oct 2023 14:49:15 +0200 Subject: [PATCH] [IMP] l10n_nl_tax_statement: refactor tests to increase coverage --- .../tests/test_l10n_nl_vat_statement.py | 45 ++++++++++++++----- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/l10n_nl_tax_statement/tests/test_l10n_nl_vat_statement.py b/l10n_nl_tax_statement/tests/test_l10n_nl_vat_statement.py index 45469ff80..0acf0508c 100644 --- a/l10n_nl_tax_statement/tests/test_l10n_nl_vat_statement.py +++ b/l10n_nl_tax_statement/tests/test_l10n_nl_vat_statement.py @@ -139,6 +139,18 @@ def _create_test_invoice(self): self.invoice_1 = invoice_form.save() self.assertEqual(len(self.invoice_1.line_ids), 5) + def _check_export_xls(self, statement): + """Generate XLS report from action""" + report = "l10n_nl_tax_statement.action_report_tax_statement_xls_export" + self.report_action = self.env.ref(report) + self.assertEqual(self.report_action.report_type, "xlsx") + model = self.env["report.%s" % self.report_action["report_name"]].with_context( + active_model="l10n.nl.vat.statement" + ) + res = model.create_xlsx_report(statement.ids, data=None) + self.assertTrue(res[0]) + self.assertEqual(res[1], "xlsx") + def test_01_onchange(self): form = Form(self.statement_1) form.from_date = datetime.date(2016, 1, 1) @@ -160,6 +172,9 @@ def test_01_onchange(self): self.assertEqual(statement.unreported_move_from_date, new_date) self.assertEqual(statement.btw_total, 0.0) + # Export XLS without errors + self._check_export_xls(statement) + def test_02_post_final(self): # in draft self.assertEqual(self.statement_1.state, "draft") @@ -199,6 +214,9 @@ def test_02_post_final(self): self.assertEqual(self.statement_1.btw_total, 0.0) + # Export XLS without errors + self._check_export_xls(self.statement_1) + def test_03_reset(self): self.statement_1.reset() self.assertEqual(self.statement_1.state, "draft") @@ -211,6 +229,9 @@ def test_03_reset(self): self.assertTrue(line.view_base_lines()) self.assertTrue(line.view_tax_lines()) + # Export XLS without errors + self._check_export_xls(self.statement_1) + def test_04_write(self): self.statement_1.post() with self.assertRaises(UserError): @@ -218,6 +239,9 @@ def test_04_write(self): self.assertEqual(self.statement_1.btw_total, 0.0) + # Export XLS without errors + self._check_export_xls(self.statement_1) + def test_05_unlink_exception(self): self.statement_1.post() with self.assertRaises(UserError): @@ -256,6 +280,9 @@ def test_09_update_working(self): self.assertEqual(self.statement_1.btw_total, 21.0) self.assertEqual(self.statement_1.format_btw_total, "21.00") + # Export XLS without errors + self._check_export_xls(self.statement_1) + def test_10_line_unlink_exception(self): self.assertEqual(len(self.statement_1.line_ids.ids), 0) self.assertEqual(self.statement_1.btw_total, 0.0) @@ -301,6 +328,9 @@ def test_12_undeclared_invoice(self): self.assertTrue(line.view_base_lines()) self.assertTrue(line.view_tax_lines()) + # Export XLS without errors + self._check_export_xls(self.statement_1) + invoice2 = self.invoice_1.copy() invoice2.action_post() statement2 = self.env["l10n.nl.vat.statement"].create({"name": "Statement 2"}) @@ -330,6 +360,9 @@ def test_12_undeclared_invoice(self): with self.assertRaises(UserError): invoice_lines[0].date = fields.Date.today() + # Export XLS without errors + self._check_export_xls(statement2) + def test_13_no_previous_statement_posted(self): statement2 = self.env["l10n.nl.vat.statement"].create({"name": "Statement 2"}) statement2.statement_update() @@ -535,15 +568,3 @@ def test_20_multicompany(self): company_ids_full_list = statement_parent._get_company_ids_full_list() self.assertEqual(len(company_ids_full_list), 3) - - def test_21_action_xls(self): - """Generate XLS report from action""" - report = "l10n_nl_tax_statement.action_report_tax_statement_xls_export" - self.report_action = self.env.ref(report) - self.assertEqual(self.report_action.report_type, "xlsx") - model = self.env["report.%s" % self.report_action["report_name"]].with_context( - active_model="l10n.nl.vat.statement" - ) - res = model.create_xlsx_report(self.statement_1.ids, data=None) - self.assertTrue(res[0]) - self.assertEqual(res[1], "xlsx")