common.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # coding: utf-8
  2. import base64
  3. from pytz import timezone
  4. from datetime import datetime
  5. from odoo.tools import misc
  6. from odoo.addons.account_edi.tests.common import AccountEdiTestCommon
  7. class TestEsEdiCommon(AccountEdiTestCommon):
  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. cls.frozen_today = datetime(year=2019, month=1, day=1, hour=0, minute=0, second=0, tzinfo=timezone('utc'))
  12. # Allow to see the full result of AssertionError.
  13. cls.maxDiff = None
  14. # ==== Config ====
  15. cls.certificate = cls.env['l10n_es_edi.certificate'].create({
  16. 'content': base64.encodebytes(
  17. misc.file_open("l10n_es_edi_sii/demo/certificates/sello_entidad_act.p12", 'rb').read()),
  18. 'password': 'IZDesa2021',
  19. })
  20. cls.company_data['company'].write({
  21. 'country_id': cls.env.ref('base.es').id,
  22. 'state_id': cls.env.ref('base.state_es_z').id,
  23. 'l10n_es_edi_certificate_id': cls.certificate.id,
  24. 'vat': 'ES59962470K',
  25. 'l10n_es_edi_test_env': True,
  26. 'l10n_es_edi_tax_agency': 'bizkaia',
  27. })
  28. # To be sure it is put by default on purchase journals as well (tbai module)
  29. cls.company_data['default_journal_purchase'].write({
  30. 'edi_format_ids': [(6, 0, cls.edi_format.ids)],
  31. })
  32. # ==== Business ====
  33. cls.partner_a.write({
  34. 'vat': 'BE0477472701',
  35. 'country_id': cls.env.ref('base.be').id,
  36. })
  37. cls.partner_b.write({
  38. 'vat': 'ESF35999705',
  39. })
  40. cls.product_t = cls.env["product.product"].create(
  41. {"name": "Test product"})
  42. cls.partner_t = cls.env["res.partner"].create({"name": "Test partner", "vat": "ESF35999705"})
  43. @classmethod
  44. def _get_tax_by_xml_id(cls, trailing_xml_id):
  45. """ Helper to retrieve a tax easily.
  46. :param trailing_xml_id: The trailing tax's xml id.
  47. :return: An account.tax record
  48. """
  49. return cls.env.ref(f'l10n_es.{cls.env.company.id}_account_tax_template_{trailing_xml_id}')
  50. @classmethod
  51. def create_invoice(cls, **kwargs):
  52. return cls.env['account.move'].with_context(edi_test_mode=True).create({
  53. 'move_type': 'out_invoice',
  54. 'partner_id': cls.partner_a.id,
  55. 'invoice_date': '2019-01-01',
  56. 'date': '2019-01-01',
  57. **kwargs,
  58. 'invoice_line_ids': [(0, 0, {
  59. 'product_id': cls.product_a.id,
  60. 'price_unit': 1000.0,
  61. **line_vals,
  62. }) for line_vals in kwargs.get('invoice_line_ids', [])],
  63. })