test_edi_pa.py 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  2. import datetime
  3. from lxml import etree
  4. from odoo.addons.l10n_it_edi.tests.common import TestItEdi
  5. from odoo.exceptions import UserError
  6. from odoo.tests.common import tagged
  7. from odoo import tools
  8. @tagged('post_install_l10n', 'post_install', '-at_install')
  9. class TestItEdiPa(TestItEdi):
  10. @classmethod
  11. def setUpClass(cls):
  12. super().setUpClass()
  13. cls.Move = cls.env['account.move'].with_company(cls.company)
  14. journal_code = cls.company_data_2['default_journal_sale'].code
  15. cls.split_payment_tax = cls.env['account.tax'].with_company(cls.company).search([('name', '=', '22% SP')])
  16. cls.split_payment_line_data = {
  17. **cls.standard_line,
  18. 'tax_ids': [(6, 0, [cls.split_payment_tax.id])]
  19. }
  20. cls.pa_partner_invoice_data = {
  21. 'move_type': 'out_invoice',
  22. 'invoice_date': datetime.date(2022, 3, 24),
  23. 'invoice_date_due': datetime.date(2022, 3, 24),
  24. 'partner_id': cls.italian_partner_b.id,
  25. 'partner_bank_id': cls.test_bank.id,
  26. 'invoice_line_ids': [
  27. (0, 0, cls.split_payment_line_data),
  28. ],
  29. 'l10n_it_origin_document_type': 'purchase_order',
  30. 'l10n_it_origin_document_date': datetime.date(2022, 3, 23),
  31. 'l10n_it_origin_document_name': f"{journal_code}/2022/0001",
  32. 'l10n_it_cup': '0123456789',
  33. 'l10n_it_cig': '0987654321'
  34. }
  35. cls.pa_partner_invoice = cls.Move.create(cls.pa_partner_invoice_data)
  36. cls.pa_partner_invoice_2 = cls.Move.create({
  37. **cls.pa_partner_invoice_data,
  38. 'l10n_it_origin_document_type': False,
  39. })
  40. cls.pa_partner_invoice._post()
  41. cls.split_payment_invoice_content = cls._get_test_file_content('split_payment.xml')
  42. @classmethod
  43. def _get_test_file_content(cls, filename):
  44. """ Get the content of a test file inside this module """
  45. path = 'l10n_it_edi/tests/expected_xmls/' + filename
  46. with tools.file_open(path, mode='rb') as test_file:
  47. return test_file.read()
  48. def test_send_pa_partner(self):
  49. res = self.edi_format._l10n_it_post_invoices_step_1(self.pa_partner_invoice)
  50. self.assertEqual(res[self.pa_partner_invoice], {'attachment': self.pa_partner_invoice.l10n_it_edi_attachment_id, 'success': True})
  51. def test_send_pa_partner_missing_field(self):
  52. with self.assertRaises(UserError):
  53. self.pa_partner_invoice_2._post()
  54. def test_split_payment(self):
  55. """ ImportoTotaleDocumento must include VAT
  56. ImportoPagamento must be without VAT
  57. EsigibilitaIva of the Split payment tax must be 'S'
  58. The orgin_document fields must appear in the XML.
  59. Use reference validator: https://fex-app.com/servizi/inizia
  60. """
  61. invoice_etree = self._cleanup_etree(self.edi_format._l10n_it_edi_export_invoice_as_xml(self.pa_partner_invoice))
  62. expected_etree = etree.fromstring(self.split_payment_invoice_content)
  63. self.assertXmlTreeEqual(invoice_etree, expected_etree)