common.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. from datetime import datetime
  2. from pytz import timezone
  3. from odoo.fields import Command
  4. from odoo.tests import tagged
  5. from odoo.addons.account_edi.tests.common import AccountEdiTestCommon
  6. class TestEGEdiCommon(AccountEdiTestCommon):
  7. @classmethod
  8. def setUpClass(cls, chart_template_ref='l10n_eg.egypt_chart_template_standard', edi_format_ref='l10n_eg_edi_eta.edi_eg_eta'):
  9. super().setUpClass(chart_template_ref=chart_template_ref, edi_format_ref=edi_format_ref)
  10. cls.frozen_today = datetime(year=2022, month=3, day=15, hour=0, minute=0, second=0, tzinfo=timezone('utc'))
  11. cls.currency_aed_id = cls.env.ref('base.AED')
  12. cls.currency_aed_id.write({'active': True})
  13. cls.env['res.currency.rate'].search([]).unlink()
  14. cls.env['res.currency.rate'].create({'currency_id': cls.currency_aed_id.id,
  15. 'rate': 0.198117095128, 'name': '2022-03-15'})
  16. # Allow to see the full result of AssertionError.
  17. cls.maxDiff = None
  18. cls.company_data['company'].write({
  19. 'country_id': cls.env.ref('base.eg').id,
  20. 'l10n_eg_client_identifier': 'ahuh1pojnbakKK',
  21. 'l10n_eg_client_secret': '1ashiqwhejmasn197',
  22. 'vat': 'EG1103143170L',
  23. })
  24. # ==== Business ====
  25. cls.partner_a.write({
  26. 'vat': 'BE0477472701',
  27. 'country_id': cls.env.ref('base.eg').id,
  28. 'city': 'Iswan',
  29. 'state_id': cls.env.ref('base.state_eg_c').id,
  30. 'l10n_eg_building_no': '12',
  31. 'street': '12th dec. street',
  32. 'is_company': True,
  33. })
  34. cls.partner_b.write({
  35. 'vat': 'ESF35999705',
  36. 'country_id': cls.env.ref('base.us').id,
  37. 'city': 'New York City',
  38. 'state_id': cls.env.ref('base.state_us_27').id,
  39. 'l10n_eg_building_no': '12',
  40. 'street': '5th avenue street',
  41. 'is_company': True,
  42. })
  43. cls.partner_c = cls.env['res.partner'].create({
  44. 'name': 'عميل 1',
  45. 'vat': 'EG11231212',
  46. 'country_id': cls.env.ref('base.eg').id,
  47. 'city': 'Iswan',
  48. 'state_id': cls.env.ref('base.state_eg_c').id,
  49. 'l10n_eg_building_no': '12',
  50. 'street': '12th dec. street',
  51. 'is_company': True,
  52. })
  53. cls.product_a.write({'barcode': '1KGS1TEST', })
  54. cls.product_b.write({
  55. 'barcode': 'EG-EGS-TEST',
  56. 'uom_id': cls.env.ref('uom.product_uom_cm').id,
  57. })
  58. cls.company_branch = cls.env['res.partner'].create({
  59. 'name': 'branch partner',
  60. 'vat': '918KKL1',
  61. 'country_id': cls.env.ref('base.eg').id,
  62. 'city': 'Iswan',
  63. 'state_id': cls.env.ref('base.state_eg_c').id,
  64. 'l10n_eg_building_no': '10',
  65. 'street': '12th dec. street',
  66. 'is_company': True,
  67. })
  68. cls.company_data['default_journal_sale'].write({
  69. 'l10n_eg_branch_id': cls.company_branch.id,
  70. 'l10n_eg_branch_identifier': '0',
  71. 'l10n_eg_activity_type_id': cls.env.ref('l10n_eg_edi_eta.l10n_eg_activity_type_8121').id,
  72. })
  73. @classmethod
  74. def _get_tax_by_xml_id(cls, trailing_xml_id):
  75. return cls.env.ref(f'l10n_es.{cls.env.company.id}_account_tax_template_{trailing_xml_id}')
  76. @classmethod
  77. def create_invoice(cls, **kwargs):
  78. invoice = (
  79. cls.env['account.move']
  80. .with_context(edi_test_mode=True)
  81. .create({
  82. 'move_type': 'out_invoice',
  83. 'partner_id': cls.partner_a.id,
  84. 'invoice_date': '2022-03-15',
  85. 'date': '2022-03-15',
  86. **kwargs,
  87. 'invoice_line_ids': [Command.create({**line_vals, }) for line_vals in kwargs.get('invoice_line_ids', [])]
  88. })
  89. )
  90. # this fixes rounding issues in cache
  91. cls.env.invalidate_all()
  92. return invoice