Guest User

Untitled

a guest
May 10th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.29 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """Script to bootstrap an Odoo database (8.0)."""
  4. import odoorpc
  5.  
  6. # Odoo connection
  7. SUPER_PWD = 'admin'
  8. HOST = 'localhost'
  9. PORT = 8069
  10. DB = 'my_db'
  11. USER = 'admin'
  12. PWD = 'password'
  13. LANG = 'en_US'
  14. COMPANY = u"ABF OSIELL"
  15. TIMEZONE = u"Europe/Paris"
  16. MODULES_TO_INSTALL = [
  17. 'sale',
  18. 'purchase',
  19. 'account_accountant',
  20. 'l10n_fr',
  21. ]
  22.  
  23.  
  24. def get_session(login=True):
  25. odoo = odoorpc.ODOO(HOST, port=PORT)
  26. odoo.config['timeout'] = None
  27. if login:
  28. odoo.login(DB, USER, PWD)
  29. return odoo
  30.  
  31.  
  32. def create_database():
  33. odoo = get_session(login=False)
  34. if DB not in odoo.db.list():
  35. odoo.db.create(
  36. SUPER_PWD, DB, demo=False, lang=LANG, admin_password=PWD)
  37.  
  38.  
  39. def uninstall_modules():
  40. odoo = get_session()
  41. Module = odoo.env['ir.module.module']
  42. module_names = ['im_chat', 'im_livechat', 'im_odoo_support']
  43. for module_name in module_names:
  44. module_ids = Module.search(
  45. [('name', '=', module_name),
  46. ('state', 'in', ['installed', 'to upgrade',
  47. 'to remove', 'to install'])])
  48. if module_ids:
  49. Module.button_immediate_uninstall(module_ids)
  50.  
  51.  
  52. def update_company():
  53. odoo = get_session()
  54. company = odoo.env.user.company_id
  55. company.name = COMPANY
  56.  
  57.  
  58. def update_admin_user():
  59. odoo = get_session()
  60. admin = odoo.env.user
  61. group_technical_feature = odoo.env.ref('base.group_no_one')
  62. group_sale_manager = odoo.env.ref('base.group_sale_manager')
  63. if group_technical_feature not in admin.groups_id:
  64. admin.groups_id += group_technical_feature
  65. if group_sale_manager not in admin.groups_id:
  66. admin.groups_id += group_sale_manager
  67. if not admin.tz:
  68. admin.tz = TIMEZONE
  69.  
  70.  
  71. def install_modules():
  72. odoo = get_session()
  73. # Installation
  74. Module = odoo.env['ir.module.module']
  75. for module_name in MODULES_TO_INSTALL:
  76. module_ids = Module.search(
  77. [('name', '=', module_name),
  78. ('state', 'not in', ['installed', 'to upgrade'])])
  79. if module_ids:
  80. Module.button_immediate_install(module_ids)
  81.  
  82.  
  83. def configure_account():
  84. odoo = get_session()
  85. # account.installer
  86. Wizard = odoo.env['account.installer']
  87. config = Wizard.default_get(list(Wizard.fields_get()))
  88. config['charts'] = 'l10n_fr'
  89. wiz_id = Wizard.create(config)
  90. Wizard.action_next([wiz_id])
  91. # wizard.multi.charts.accounts
  92. Wizard = odoo.env['wizard.multi.charts.accounts']
  93. config = Wizard.default_get(list(Wizard.fields_get()))
  94. config['chart_template_id'] = odoo.env.ref(
  95. 'l10n_fr.l10n_fr_pcg_chart_template').id
  96. values = Wizard.onchange_chart_template_id(
  97. [], config['chart_template_id'])['value']
  98. config.update(values)
  99. config['sale_tax'] = odoo.env.ref('l10n_fr.tva_normale').id
  100. config['purchase_tax'] = odoo.env.ref('l10n_fr.tva_acq_normale').id
  101. config['code_digits'] = 8
  102. del config['bank_accounts_id']
  103. wiz_id = Wizard.create(config)
  104. try:
  105. Wizard.action_next([wiz_id])
  106. except odoorpc.error.RPCError:
  107. print "Accounting already configured"
  108.  
  109.  
  110. def main():
  111. create_database()
  112. uninstall_modules()
  113. update_company()
  114. update_admin_user()
  115. install_modules()
  116. configure_account()
  117.  
  118.  
  119. if __name__ == '__main__':
  120. main()
Add Comment
Please, Sign In to add comment