# pylint: disable=C0326 # Part of Odoo. See LICENSE file for full copyright and licensing details. import os from freezegun import freeze_time from unittest import skipIf from odoo import fields from odoo.addons.account_reports.tests.common import TestAccountReportsCommon from odoo.addons.account_reports.tests.account_sales_report_common import AccountSalesReportCommon from odoo.tests import tagged @tagged('post_install_l10n', 'post_install', '-at_install') class TestNlICPSBR(AccountSalesReportCommon): @classmethod @AccountSalesReportCommon.setup_country('nl') def setUpClass(cls): super().setUpClass() cls.env.company.write({ 'vat': 'NL123456782B90', 'l10n_nl_reports_sbr_ob_nummer': '987654321B09', }) cls.partner_c = cls.env['res.partner'].create({ 'name': 'Partner C', 'country_id': cls.env.ref('base.de').id, 'vat': 'DE123456788', }) @freeze_time('2019-02-23 18:45') def test_icp_xbrl_export(self): # Create a new partner for the representative and link it to the company. representative = self.env['res.partner'].create({ 'company_type': 'company', 'name': 'Fidu NL', 'street': 'Fidu Street 123', 'city': 'Amsterdam', 'zip': '1019', 'country_id': self.env.ref('base.nl').id, 'vat': 'NL123456782B90', 'phone': '+31470123456', 'email': 'info@fidu.nl', }) self.env.company.account_representative_id = representative.id self.env.user.phone = '+31432112345' t_tax = self.env.ref(f'account.{self.env.company.id}_btw_X0_ABC_levering') s_tax = self.env.ref(f'account.{self.env.company.id}_btw_X0_diensten') product_service = self.env['product.product'].create({ 'name': 'product_service', 'lst_price': 750.0, 'taxes_id': [s_tax.id], 'type': 'service', }) product_triangular = self.env['product.product'].create({ 'name': 'product_triangular', 'lst_price': 500.0, 'taxes_id': [t_tax.id], }) self.init_invoice('out_invoice', partner=self.partner_a, invoice_date=fields.Date.from_string('2019-02-15'), post=True, products=[self.product_a, product_service, product_triangular]) self.init_invoice('out_invoice', partner=self.partner_b, invoice_date=fields.Date.from_string('2019-06-20'), post=True, products=[self.product_a, product_service]) # Credit note for a fictitious invoice in a previous month, tests that negative values are also included in the export self.init_invoice('out_refund', partner=self.partner_c, invoice_date=fields.Date.from_string('2019-06-30'), post=True, products=[product_triangular]) self.env['account.move.line'].flush_model() report = self.env.ref('l10n_nl_reports.dutch_icp_report') date_from = fields.Date.from_string('2019-01-01') date_to = fields.Date.from_string('2019-12-31') options = self._generate_options(report, date_from, date_to) wizard = self.env['l10n_nl_reports.sbr.icp.wizard'] \ .with_context(default_date_from=date_from, default_date_to=date_to, options=options) \ .create({'tax_consultant_number': '123456'}) # This call will add the wanted values in the options wizard.action_download_xbrl_file() generated_xbrl = self.get_xml_tree_from_string(self.env['l10n_nl_reports.ec.sales.report.handler'].export_icp_report_to_xbrl(options).get('file_content')) expected_xbrl = self.get_xml_tree_from_string(''' 987654321B09 2019-01-01 2019-12-31 987654321B09 2019-01-01 2019-12-31 1 987654321B09 2019-01-01 2019-12-31 23334175221 FR 987654321B09 2019-01-01 2019-12-31 0477472701 BE 987654321B09 2019-01-01 2019-12-31 123456788 DE iso4217:EUR ___ignore___ swo02770 Odoo ___ignore___ 201902231845 NBA 123456 BIAA I am accountman! +31432112345 123456782B90 1000 1000 750 750 500 -500 ''') self.assertXmlTreeEqual(generated_xbrl, expected_xbrl) @tagged('external_l10n', 'post_install', '-at_install', '-standard', 'external') @skipIf(not os.getenv("NL_SBR_CERT"), "No SBR certificate") class TestNlSBRFlow(TestAccountReportsCommon): @classmethod @TestAccountReportsCommon.setup_country('nl') def setUpClass(cls): super().setUpClass() cls.env.company.write({ 'vat': 'NL123456782B90', 'l10n_nl_reports_sbr_ob_nummer': '987654321B09', }) cls.NL_SBR_CERT = os.getenv("NL_SBR_CERT") cls.NL_SBR_PWD = os.getenv("NL_SBR_PWD") def test_sbr_flow(self): # Load the certificate and key in the company certificate = self.env['certificate.certificate'].create({ 'name': 'SBR NL certificate', 'content': self.NL_SBR_CERT.encode(), 'pkcs12_password': self.NL_SBR_PWD, 'company_id': self.env.company.id, }) self.assertTrue(certificate.private_key_id) self.env.company.l10n_nl_reports_sbr_cert_id = certificate date_from = fields.Date.from_string('2019-01-01') date_to = fields.Date.from_string('2019-12-31') report = self.env.ref('l10n_nl_reports.dutch_icp_report') options = self._generate_options(report, date_from, date_to) wizard = self.env['l10n_nl_reports.sbr.icp.wizard']\ .with_context(default_date_from=date_from, default_date_to=date_to, options=options)\ .create({'is_test': True}) res = wizard.send_xbrl() self.assertTrue(res)