__init__.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from . import controllers
  4. from . import models
  5. from . import demo
  6. from . import wizard
  7. from . import report
  8. from . import populate
  9. from . import tools
  10. from odoo import api, SUPERUSER_ID
  11. SYSCOHADA_LIST = ['BJ', 'BF', 'CM', 'CF', 'KM', 'CG', 'CI', 'GA', 'GN', 'GW', 'GQ', 'ML', 'NE', 'CD', 'SN', 'TD', 'TG']
  12. def _set_fiscal_country(env):
  13. """ Sets the fiscal country on existing companies when installing the module.
  14. That field is an editable computed field. It doesn't automatically get computed
  15. on existing records by the ORM when installing the module, so doing that by hand
  16. ensures existing records will get a value for it if needed.
  17. """
  18. env['res.company'].search([]).compute_account_tax_fiscal_country()
  19. def _auto_install_l10n(env):
  20. #check the country of the main company (only) and eventually load some module needed in that country
  21. country_code = env.company.country_id.code
  22. if country_code:
  23. #auto install localization module(s) if available
  24. to_install_l10n = env['ir.module.module'].search_count([
  25. ('category_id', '=', env.ref('base.module_category_accounting_localizations_account_charts').id),
  26. ('state', '=', 'to install'),
  27. ])
  28. module_list = []
  29. if to_install_l10n:
  30. # We don't install a CoA if one was passed in the command line
  31. # or has been selected to install
  32. pass
  33. elif country_code in SYSCOHADA_LIST:
  34. #countries using OHADA Chart of Accounts
  35. module_list.append('l10n_syscohada')
  36. elif country_code == 'GB':
  37. module_list.append('l10n_uk')
  38. elif country_code == 'DE':
  39. module_list.append('l10n_de_skr03')
  40. module_list.append('l10n_de_skr04')
  41. else:
  42. if env['ir.module.module'].search([('name', '=', 'l10n_' + country_code.lower())]):
  43. module_list.append('l10n_' + country_code.lower())
  44. else:
  45. module_list.append('l10n_generic_coa')
  46. if country_code in SYSCOHADA_LIST + [
  47. 'AT', 'BE', 'CA', 'CO', 'DE', 'EC', 'ES', 'ET', 'FR', 'GR', 'IT', 'LU', 'MX', 'NL', 'NO',
  48. 'PL', 'PT', 'RO', 'SI', 'TR', 'GB', 'VE', 'VN'
  49. ]:
  50. module_list.append('base_vat')
  51. if country_code == 'uk':
  52. module_list.append('account_bacs')
  53. module_ids = env['ir.module.module'].search([('name', 'in', module_list), ('state', '=', 'uninstalled')])
  54. if module_ids:
  55. module_ids.sudo().button_install()
  56. def _account_post_init(cr, registry):
  57. env = api.Environment(cr, SUPERUSER_ID, {})
  58. _auto_install_l10n(env)
  59. _set_fiscal_country(env)