test_edi_web_services.py 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # -*- coding: utf-8 -*-
  2. from datetime import datetime
  3. from odoo.tests import tagged
  4. from odoo import fields
  5. from .common import TestEsEdiCommon
  6. @tagged('external_l10n', 'post_install', '-at_install', '-standard', 'external')
  7. class TestEdiWebServices(TestEsEdiCommon):
  8. @classmethod
  9. def setUpClass(cls, chart_template_ref='l10n_es.account_chart_template_full', edi_format_ref='l10n_es_edi_sii.edi_es_sii'):
  10. super().setUpClass(chart_template_ref=chart_template_ref, edi_format_ref=edi_format_ref)
  11. # Invoice name are tracked by the web-services so this constant tries to get a new unique invoice name at each
  12. # execution.
  13. cls.today = datetime.now()
  14. cls.time_name = cls.today.strftime('%H%M%S')
  15. cls.out_invoice = cls.env['account.move'].create({
  16. 'name': f'INV{cls.time_name}',
  17. 'move_type': 'out_invoice',
  18. 'partner_id': cls.partner_a.id,
  19. 'invoice_line_ids': [(0, 0, {
  20. 'product_id': cls.product_a.id,
  21. 'price_unit': 1000.0,
  22. 'quantity': 5,
  23. 'discount': 20.0,
  24. 'tax_ids': [(6, 0, cls._get_tax_by_xml_id('s_iva21b').ids)],
  25. })],
  26. })
  27. cls.out_invoice.action_post()
  28. cls.in_invoice = cls.env['account.move'].create({
  29. 'name': f'BILL{cls.time_name}',
  30. 'ref': f'REFBILL{cls.time_name}',
  31. 'move_type': 'in_invoice',
  32. 'partner_id': cls.partner_a.id,
  33. 'invoice_date': fields.Date.to_string(cls.today.date()),
  34. 'invoice_line_ids': [(0, 0, {
  35. 'product_id': cls.product_a.id,
  36. 'price_unit': 1000.0,
  37. 'quantity': 5,
  38. 'discount': 20.0,
  39. 'tax_ids': [(6, 0, cls._get_tax_by_xml_id('p_iva10_bc').ids)],
  40. })],
  41. })
  42. cls.in_invoice.action_post()
  43. cls.moves = cls.out_invoice + cls.in_invoice
  44. def test_edi_aeat(self):
  45. self.env.company.l10n_es_edi_tax_agency = 'aeat'
  46. self.moves.action_process_edi_web_services(with_commit=False)
  47. generated_files = self._process_documents_web_services(self.moves, {'es_sii'})
  48. self.assertTrue(generated_files)
  49. self.assertRecordValues(self.out_invoice, [{'edi_state': 'sent'}])
  50. self.assertRecordValues(self.in_invoice, [{'edi_state': 'sent'}])
  51. def test_edi_gipuzkoa(self):
  52. self.env.company.l10n_es_edi_tax_agency = 'gipuzkoa'
  53. self.moves.action_process_edi_web_services(with_commit=False)
  54. generated_files = self._process_documents_web_services(self.moves, {'es_sii'})
  55. self.assertTrue(generated_files)
  56. self.assertRecordValues(self.out_invoice, [{'edi_state': 'sent'}])
  57. self.assertRecordValues(self.in_invoice, [{'edi_state': 'sent'}])
  58. def test_edi_bizkaia(self):
  59. self.env.company.l10n_es_edi_tax_agency = 'bizkaia'
  60. self.moves.action_process_edi_web_services(with_commit=False)
  61. generated_files = self._process_documents_web_services(self.moves, {'es_sii'})
  62. self.assertTrue(generated_files)
  63. self.assertRecordValues(self.out_invoice, [{'edi_state': 'sent'}])
  64. self.assertRecordValues(self.in_invoice, [{'edi_state': 'sent'}])