| 1 |
from odoo import Command |
| 2 |
from odoo.addons.account.tests.common import AccountTestInvoicingCommon |
| 3 |
from odoo.addons.l10n_hr_edi.tests.test_hr_edi_common import TestL10nHrEdiCommon |
| 4 |
from odoo.tests import tagged |
| 5 |
from odoo.tools import misc |
| 6 |
|
| 7 |
|
| 8 |
@tagged('post_install_l10n', 'post_install', '-at_install', 'l10n_hr_edi_xml') |
| 9 |
class TestL10nHrEdiXml(TestL10nHrEdiCommon, AccountTestInvoicingCommon): |
| 10 |
|
| 11 |
@classmethod |
| 12 |
def setUpClass(cls): |
| 13 |
super().setUpClass() |
| 14 |
cls.env.company.partner_id.l10n_hr_business_unit_code = '12345' |
| 15 |
|
| 16 |
def test_export_invoice_from_account_edi_xml_ubl_hr(self): |
| 17 |
""" |
| 18 |
Test content of a generated basic invoice in Croation UBL format. |
| 19 |
""" |
| 20 |
self.setup_partner_as_hr(self.env.company.partner_id) |
| 21 |
self.setup_partner_as_hr_alt(self.partner_a) |
| 22 |
tax = self.env['account.chart.template'].ref('VAT_S_IN_ROC_25') |
| 23 |
|
| 24 |
invoice = self.env['account.move'].create({ |
| 25 |
'move_type': 'out_invoice', |
| 26 |
'partner_id': self.partner_a.id, |
| 27 |
'invoice_date': '2025-01-01', |
| 28 |
'l10n_hr_process_type': 'P99', |
| 29 |
'l10n_hr_customer_defined_process_name': 'Test custom process type', |
| 30 |
'invoice_line_ids': [ |
| 31 |
Command.create({ |
| 32 |
'product_id': self.product_a.id, |
| 33 |
'price_unit': 100.0, |
| 34 |
'tax_ids': [Command.set(tax.ids)], |
| 35 |
}), |
| 36 |
], |
| 37 |
}) |
| 38 |
invoice.action_post() |
| 39 |
# Manually create the addendum which normally happens during sending |
| 40 |
invoice.l10n_hr_edi_addendum_id = self.env['l10n_hr_edi.addendum'].create({ |
| 41 |
'move_id': invoice.id, |
| 42 |
'invoice_sending_time': '2025-01-02', |
| 43 |
'fiscalization_number': self.env['account.move']._get_l10n_hr_fiscalization_number(invoice.name), |
| 44 |
}) |
| 45 |
actual_content, _dummy = self.env['account.edi.xml.ubl_hr'].with_context(lang='en_US')._export_invoice(invoice) |
| 46 |
with misc.file_open(f'addons/{self.test_module}/tests/test_files/test_invoice.xml', 'rb') as file: |
| 47 |
expected_content = file.read() |
| 48 |
self.assertXmlTreeEqual( |
| 49 |
self.get_xml_tree_from_string(actual_content), |
| 50 |
self.get_xml_tree_from_string(expected_content), |
| 51 |
) |
| 52 |
|
| 53 |
def test_export_invoice_with_cash_basis(self): |
| 54 |
""" |
| 55 |
Test content of a generated invoice with an 'on_payment' exigibility tax in Croation UBL format. |
| 56 |
""" |
| 57 |
self.setup_partner_as_hr(self.env.company.partner_id) |
| 58 |
self.setup_partner_as_hr_alt(self.partner_a) |
| 59 |
tax = self.env['account.chart.template'].ref('VAT_S_IN_ROC_25') |
| 60 |
tax.cash_basis_transition_account_id = self.safe_copy(self.company_data['default_account_tax_sale']) |
| 61 |
tax.cash_basis_transition_account_id.reconcile = True |
| 62 |
tax.tax_exigibility = 'on_payment' |
| 63 |
|
| 64 |
invoice = self.env['account.move'].create({ |
| 65 |
'move_type': 'out_invoice', |
| 66 |
'partner_id': self.partner_a.id, |
| 67 |
'invoice_date': '2025-01-01', |
| 68 |
'l10n_hr_process_type': 'P99', |
| 69 |
'l10n_hr_customer_defined_process_name': 'Test custom process type', |
| 70 |
'invoice_line_ids': [ |
| 71 |
Command.create({ |
| 72 |
'product_id': self.product_a.id, |
| 73 |
'price_unit': 100.0, |
| 74 |
'tax_ids': [Command.set(tax.ids)], |
| 75 |
}), |
| 76 |
], |
| 77 |
}) |
| 78 |
invoice.action_post() |
| 79 |
invoice.l10n_hr_edi_addendum_id = self.env['l10n_hr_edi.addendum'].create({ |
| 80 |
'move_id': invoice.id, |
| 81 |
'invoice_sending_time': '2025-01-02', |
| 82 |
'fiscalization_number': self.env['account.move']._get_l10n_hr_fiscalization_number(invoice.name), |
| 83 |
}) |
| 84 |
actual_content, _dummy = self.env['account.edi.xml.ubl_hr'].with_context(lang='en_US')._export_invoice(invoice) |
| 85 |
with misc.file_open(f'addons/{self.test_module}/tests/test_files/test_invoice_cash_basis.xml', 'rb') as file: |
| 86 |
expected_content = file.read() |
| 87 |
self.assertXmlTreeEqual( |
| 88 |
self.get_xml_tree_from_string(actual_content), |
| 89 |
self.get_xml_tree_from_string(expected_content), |
| 90 |
) |
| 91 |
|
| 92 |
def test_export_invoice_with_exemption_k(self): |
| 93 |
""" |
| 94 |
Test the content of a generated invoice with HR:K exemption in Croation UBL format. |
| 95 |
""" |
| 96 |
self.setup_partner_as_hr(self.env.company.partner_id) |
| 97 |
self.setup_partner_as_hr_alt(self.partner_a) |
| 98 |
tax = self.env['account.chart.template'].ref('VAT_S_EU_G') |
| 99 |
|
| 100 |
invoice = self.env['account.move'].create({ |
| 101 |
'move_type': 'out_invoice', |
| 102 |
'partner_id': self.partner_a.id, |
| 103 |
'invoice_date': '2025-01-01', |
| 104 |
'invoice_line_ids': [ |
| 105 |
Command.create({ |
| 106 |
'product_id': self.product_a.id, |
| 107 |
'price_unit': 100.0, |
| 108 |
'tax_ids': [Command.set(tax.ids)], |
| 109 |
}), |
| 110 |
], |
| 111 |
}) |
| 112 |
invoice.action_post() |
| 113 |
invoice.l10n_hr_edi_addendum_id = self.env['l10n_hr_edi.addendum'].create({ |
| 114 |
'move_id': invoice.id, |
| 115 |
'invoice_sending_time': '2025-01-02', |
| 116 |
'fiscalization_number': self.env['account.move']._get_l10n_hr_fiscalization_number(invoice.name), |
| 117 |
}) |
| 118 |
actual_content, _dummy = self.env['account.edi.xml.ubl_hr'].with_context(lang='en_US')._export_invoice(invoice) |
| 119 |
with misc.file_open(f'addons/{self.test_module}/tests/test_files/test_invoice_exemption_k.xml', 'rb') as file: |
| 120 |
expected_content = file.read() |
| 121 |
self.assertXmlTreeEqual( |
| 122 |
self.get_xml_tree_from_string(actual_content), |
| 123 |
self.get_xml_tree_from_string(expected_content), |
| 124 |
) |
| 125 |
|
| 126 |
def test_export_invoice_with_exemption_e(self): |
| 127 |
""" |
| 128 |
Test the content of a generated invoice with HR:E exemption in Croation UBL format. |
| 129 |
""" |
| 130 |
self.setup_partner_as_hr(self.env.company.partner_id) |
| 131 |
self.setup_partner_as_hr_alt(self.partner_a) |
| 132 |
tax = self.env['account.chart.template'].ref('VAT_S_other_exempt_O') |
| 133 |
|
| 134 |
invoice = self.env['account.move'].create({ |
| 135 |
'move_type': 'out_invoice', |
| 136 |
'partner_id': self.partner_a.id, |
| 137 |
'invoice_date': '2025-01-01', |
| 138 |
'invoice_line_ids': [ |
| 139 |
Command.create({ |
| 140 |
'product_id': self.product_a.id, |
| 141 |
'price_unit': 100.0, |
| 142 |
'tax_ids': [Command.set(tax.ids)], |
| 143 |
}), |
| 144 |
], |
| 145 |
}) |
| 146 |
invoice.action_post() |
| 147 |
invoice.l10n_hr_edi_addendum_id = self.env['l10n_hr_edi.addendum'].create({ |
| 148 |
'move_id': invoice.id, |
| 149 |
'invoice_sending_time': '2025-01-02', |
| 150 |
'fiscalization_number': self.env['account.move']._get_l10n_hr_fiscalization_number(invoice.name), |
| 151 |
}) |
| 152 |
actual_content, _dummy = self.env['account.edi.xml.ubl_hr'].with_context(lang='en_US')._export_invoice(invoice) |
| 153 |
with misc.file_open(f'addons/{self.test_module}/tests/test_files/test_invoice_exemption_e.xml', 'rb') as file: |
| 154 |
expected_content = file.read() |
| 155 |
self.assertXmlTreeEqual( |
| 156 |
self.get_xml_tree_from_string(actual_content), |
| 157 |
self.get_xml_tree_from_string(expected_content), |
| 158 |
) |
| 159 |
|
| 160 |
def test_export_invoice_with_refund(self): |
| 161 |
""" |
| 162 |
Test content of a generated credit note in Croation UBL format. |
| 163 |
""" |
| 164 |
self.setup_partner_as_hr(self.env.company.partner_id) |
| 165 |
self.setup_partner_as_hr_alt(self.partner_a) |
| 166 |
tax = self.env['account.chart.template'].ref('VAT_S_IN_ROC_25') |
| 167 |
|
| 168 |
invoice = self.env['account.move'].create({ |
| 169 |
'move_type': 'out_refund', |
| 170 |
'partner_id': self.partner_a.id, |
| 171 |
'invoice_date': '2025-01-01', |
| 172 |
'l10n_hr_process_type': 'P9', |
| 173 |
'invoice_line_ids': [ |
| 174 |
Command.create({ |
| 175 |
'product_id': self.product_a.id, |
| 176 |
'price_unit': 100.0, |
| 177 |
'tax_ids': [Command.set(tax.ids)], |
| 178 |
}), |
| 179 |
], |
| 180 |
}) |
| 181 |
invoice.action_post() |
| 182 |
invoice.l10n_hr_edi_addendum_id = self.env['l10n_hr_edi.addendum'].create({ |
| 183 |
'move_id': invoice.id, |
| 184 |
'invoice_sending_time': '2025-01-02', |
| 185 |
'fiscalization_number': self.env['account.move']._get_l10n_hr_fiscalization_number(invoice.name), |
| 186 |
}) |
| 187 |
actual_content, _dummy = self.env['account.edi.xml.ubl_hr'].with_context(lang='en_US')._export_invoice(invoice) |
| 188 |
with misc.file_open(f'addons/{self.test_module}/tests/test_files/test_invoice_refund.xml', 'rb') as file: |
| 189 |
expected_content = file.read() |
| 190 |
self.assertXmlTreeEqual( |
| 191 |
self.get_xml_tree_from_string(actual_content), |
| 192 |
self.get_xml_tree_from_string(expected_content), |
| 193 |
) |