__init__.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from . import models
  4. from odoo import api, SUPERUSER_ID
  5. def _l10n_es_edi_post_init(cr, registry):
  6. env = api.Environment(cr, SUPERUSER_ID, {})
  7. companies = env['res.company'].search([('partner_id.country_id.code', '=', 'ES')])
  8. all_chart_templates = companies.chart_template_id
  9. current_chart_template = all_chart_templates
  10. while current_chart_template.parent_id:
  11. all_chart_templates |= current_chart_template.parent_id
  12. current_chart_template = current_chart_template.parent_id
  13. if all_chart_templates:
  14. tax_templates = env['account.tax.template'].search([
  15. ('chart_template_id', 'in', all_chart_templates.ids),
  16. '|', '|', '|',
  17. ('l10n_es_type', '!=', False),
  18. ('l10n_es_exempt_reason', '!=', False),
  19. ('tax_scope', '!=', False),
  20. ('l10n_es_bien_inversion', '!=', False),
  21. ])
  22. xml_ids = tax_templates.get_external_id()
  23. for company in companies:
  24. for tax_template in tax_templates:
  25. module, xml_id = xml_ids.get(tax_template.id).split('.')
  26. tax = env.ref('%s.%s_%s' % (module, company.id, xml_id), raise_if_not_found=False)
  27. if tax:
  28. tax.write({
  29. 'l10n_es_exempt_reason': tax_template.l10n_es_exempt_reason,
  30. 'tax_scope': tax_template.tax_scope,
  31. 'l10n_es_type': tax_template.l10n_es_type,
  32. 'l10n_es_bien_inversion': tax_template.l10n_es_bien_inversion,
  33. })