| 1 |
from odoo.tests import tagged |
| 2 |
from .test_xml_ubl_tr_common import TestUBLTRCommon |
| 3 |
from odoo.addons.account.tests.test_account_move_send import TestAccountMoveSendCommon |
| 4 |
import xml.etree.ElementTree as ET |
| 5 |
|
| 6 |
|
| 7 |
@tagged('post_install_l10n', 'post_install', '-at_install') |
| 8 |
class TestTRAccountMoveSend(TestAccountMoveSendCommon, TestUBLTRCommon): |
| 9 |
|
| 10 |
@classmethod |
| 11 |
@TestAccountMoveSendCommon.setup_country('tr') |
| 12 |
def setUpClass(cls): |
| 13 |
super().setUpClass() |
| 14 |
# ==== Partners ==== |
| 15 |
cls.partner_tr = cls.env['res.partner'].create({ |
| 16 |
'name': 'partner_tr', |
| 17 |
'invoice_edi_format': 'ubl_tr', |
| 18 |
'l10n_tr_nilvera_customer_status': 'earchive', |
| 19 |
}) |
| 20 |
|
| 21 |
def test_invoice_names_valid_for_nilvera(self): |
| 22 |
valid_names = [ |
| 23 |
'INV-2025-00001', |
| 24 |
'R01/2025/00001', |
| 25 |
'123/2025/00001', |
| 26 |
'res.2025.00001', |
| 27 |
'RES2025/00001', |
| 28 |
] |
| 29 |
invoices = self.env['account.move'] |
| 30 |
for name in valid_names: |
| 31 |
invoice = self.init_invoice('out_invoice', invoice_date='2025-11-28', amounts=[1000]) |
| 32 |
invoice.name = name |
| 33 |
invoice.action_post() |
| 34 |
invoices |= invoice |
| 35 |
|
| 36 |
wizard = self.create_send_and_print(invoices) |
| 37 |
self.assertNotIn('tr_moves_with_invalid_name', wizard.alerts) |
| 38 |
|
| 39 |
def test_invoice_names_invalid_for_nilvera(self): |
| 40 |
invalid_names = [ |
| 41 |
'INV/2025/0', |
| 42 |
'INV/25/1012', |
| 43 |
'RESXYZ00001', |
| 44 |
'res2025ABCDE', |
| 45 |
'RES-XYZ-00001', |
| 46 |
'INVOICE/2025/00010', |
| 47 |
] |
| 48 |
for name in invalid_names: |
| 49 |
invoice = self.init_invoice('out_invoice', invoice_date='2025-11-28', amounts=[1000]) |
| 50 |
invoice.name = name |
| 51 |
invoice.action_post() |
| 52 |
|
| 53 |
wizard = self.create_send_and_print(invoice) |
| 54 |
self.assertIn('tr_moves_with_invalid_name', wizard.alerts) |
| 55 |
|
| 56 |
def test_no_attachment_on_ubl_xml_for_ubl_tr(self): |
| 57 |
# Setup invoice |
| 58 |
invoice = self.init_invoice( |
| 59 |
move_type='out_invoice', |
| 60 |
partner=self.partner_tr, |
| 61 |
invoice_date='2025-11-28', |
| 62 |
amounts=[1000], |
| 63 |
taxes=self.tax_sale_a, |
| 64 |
post=True, |
| 65 |
) |
| 66 |
|
| 67 |
# Execute send |
| 68 |
wizard = self.create_send_and_print(invoice, True) |
| 69 |
wizard.sending_methods = False |
| 70 |
wizard.extra_edis = False |
| 71 |
wizard.alerts = False |
| 72 |
wizard.action_send_and_print() |
| 73 |
|
| 74 |
xml_data = invoice.ubl_cii_xml_id.raw |
| 75 |
self.assertIsNotNone(xml_data, "XML data should exist") |
| 76 |
|
| 77 |
xml_tree = ET.fromstring(xml_data.decode('utf-8')) |
| 78 |
|
| 79 |
ns = {'cac': 'urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2'} |
| 80 |
|
| 81 |
# Main assertion - no attachments should exist |
| 82 |
attachments = xml_tree.findall('.//cac:AdditionalDocumentReference/cac:Attachment', ns) |
| 83 |
self.assertFalse( |
| 84 |
attachments, |
| 85 |
f"Found {len(attachments)} unexpected Attachment node(s) in UBL TR XML" |
| 86 |
) |
| 87 |
|
| 88 |
def test_send_email_with_recipient_bank(self): |
| 89 |
""" |
| 90 |
invoice xml generation should work when company has bank account with bank information |
| 91 |
in order to send email with invoice xml to recipient's bank |
| 92 |
""" |
| 93 |
bank = self.env['res.bank'].create({ |
| 94 |
'name': 'Test Bank', |
| 95 |
'bic': 'TESTTRISXXX', |
| 96 |
}) |
| 97 |
self.company_data['company'].bank_ids.bank_id = bank.id |
| 98 |
|
| 99 |
self.assertTrue(self._generate_invoice_xml(self.einvoice_partner), "XML generation failed") |