Debian Codegraph @

addons/l10n_jo_edi/tests/test_jo_edi_invoice_codes.py

raw
1 from itertools import product
2
3 from odoo import Command
4 from odoo.tests import tagged
5 from odoo.addons.l10n_jo_edi.tests.jo_edi_common import JoEdiCommon
6
7
8 @tagged('post_install_l10n', 'post_install', '-at_install')
9 class TestJoEdiInvoiceCodes(JoEdiCommon):
10 @classmethod
11 def setUpClass(cls):
12 super().setUpClass()
13 cash_journal = cls.company_data['default_journal_cash']
14 bank_journal = cls.company_data['default_journal_bank']
15 cash_method = cls.env['account.payment.method'].sudo().create({
16 'name': 'Cash JO',
17 'code': 'l10n_jo_edi_cash',
18 'payment_type': 'inbound',
19 })
20 bank_method = cls.env['account.payment.method'].sudo().create({
21 'name': 'Bank JO',
22 'code': 'l10n_jo_edi_bank',
23 'payment_type': 'inbound',
24 })
25 cls.env['account.payment.method.line'].create({
26 'name': 'Cash',
27 'payment_method_id': cash_method.id,
28 'journal_id': cash_journal.id
29 })
30 cls.env['account.payment.method.line'].create({
31 'name': 'Bank',
32 'payment_method_id': bank_method.id,
33 'journal_id': bank_journal.id
34 })
35
36 def _get_next_invoice_details(self):
37 scope_types = ["local", "export", "development"]
38 payment_methods = ["l10n_jo_edi_cash", "l10n_jo_edi_receivable"]
39 company_types = ["income", "sales", "special"]
40
41 for t_idx, p_idx, c_idx in product(range(3), range(2), range(3)):
42 yield (
43 scope_types[t_idx],
44 payment_methods[p_idx],
45 company_types[c_idx],
46 f"{t_idx}{p_idx + 1}{c_idx + 1}"
47 )
48
49 def _get_xml_invoice_type(self, invoice):
50 generated_file = self.env['account.edi.xml.ubl_21.jo']._export_invoice(invoice)[0]
51 xml_tree = self.get_xml_tree_from_string(generated_file)
52 return xml_tree.find(".//{urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2}InvoiceTypeCode").get('name')
53
54 def test_jo_invoice_codes(self):
55 invoice_vals = {
56 'name': 'EIN/998833/0',
57 'invoice_line_ids': [Command.create({})]
58 }
59 invoice = self._l10n_jo_create_invoice(invoice_vals)
60
61 for scope_type, payment_method, company_type, expected_code in self._get_next_invoice_details():
62 with self.subTest(subtest_name=f"Invoice ({scope_type} - {payment_method} - {company_type}) should have code {expected_code}"):
63 invoice.l10n_jo_edi_invoice_type = scope_type
64 invoice.preferred_payment_method_line_id = self.env['account.payment.method.line'].search([('code', '=', payment_method)], limit=1)
65 self.company.l10n_jo_edi_taxpayer_type = company_type
66 self.assertEqual(self._get_xml_invoice_type(invoice), expected_code)