Debian Codegraph @

addons/l10n_rs_edi/tests/test_xml_ubl_rs.py

raw
1 from odoo import Command
2 from odoo.addons.l10n_account_edi_ubl_cii_tests.tests.common import TestUBLCommon
3 from odoo.tests import tagged
4 from odoo.tools import misc
5
6
7 @tagged('post_install_l10n', 'post_install', '-at_install')
8 class TestUBLRS(TestUBLCommon):
9
10 @classmethod
11 @TestUBLCommon.setup_country('rs')
12 def setUpClass(cls):
13 super().setUpClass()
14 cls.company_data['company'].write({
15 'country_id': cls.env.ref('base.rs').id,
16 'currency_id': cls.env.ref('base.RSD').id,
17 'name': 'Test RS Company',
18 'city': 'Niš',
19 'zip': '12000',
20 'vat': 'RS101134702',
21 'phone': '+381 23 456 78 91',
22 'street': 'Nikole Pašića 30a',
23 })
24 cls.company_data['company'].partner_id.l10n_rs_edi_registration_number = '87654321'
25
26 cls.env['res.partner.bank'].create({
27 'acc_type': 'iban',
28 'partner_id': cls.company_data['company'].partner_id.id,
29 'acc_number': 'RS1234123456123456123456',
30 })
31
32 cls.partner_a = cls.env['res.partner'].create({
33 'country_id': cls.env.ref('base.rs').id,
34 'name': 'Serbian Customer',
35 'city': 'Belgrade',
36 'street': 'Balkanska ulica, 21',
37 'zip': '101801',
38 'phone': '+381 98 765 43 21',
39 'vat': 'RS111032440',
40 'bank_ids': [Command.create({'acc_number': 'RS1234567891234567892345'})],
41 'l10n_rs_edi_registration_number': '12345678',
42 })
43
44 def create_invoice(self, move_type, **invoice_kwargs):
45 return self._generate_move(
46 self.env.company.partner_id,
47 self.partner_a,
48 send=False,
49 move_type=move_type,
50 currency_id=self.env.company.currency_id.id,
51 delivery_date='2025-01-15',
52 invoice_line_ids=[
53 {
54 'product_id': self.product_a.id,
55 'price_unit': 500.0,
56 'tax_ids': [Command.set(self.company_data['default_tax_sale'].ids)],
57 },
58 {
59 'product_id': self.product_b.id,
60 'price_unit': 1000.0,
61 'tax_ids': [Command.set(self.company_data['default_tax_sale'].ids)],
62 },
63 ],
64 **invoice_kwargs,
65 )
66
67 def _read_xml_test_file(self, file_name):
68 with misc.file_open(f'{self.test_module}/tests/test_files/{file_name}.xml', 'rb') as file:
69 xml_file = file.read()
70 return xml_file
71
72 def test_export_invoice(self):
73 invoice = self.create_invoice("out_invoice")
74 invoice_xml, _ = self.env['account.edi.xml.ubl.rs']._export_invoice(invoice)
75 expected_xml = self._read_xml_test_file('export_invoice')
76 self.assertXmlTreeEqual(
77 self.get_xml_tree_from_string(invoice_xml),
78 self.get_xml_tree_from_string(expected_xml)
79 )
80
81 def test_export_credit_note(self):
82 refund = self.create_invoice("out_refund")
83 refund_xml, _ = self.env['account.edi.xml.ubl.rs']._export_invoice(refund)
84 expected_xml = self._read_xml_test_file('export_credit_note')
85 self.assertXmlTreeEqual(
86 self.get_xml_tree_from_string(refund_xml),
87 self.get_xml_tree_from_string(expected_xml)
88 )