You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
1.2 KiB

  1. # Copyright 2015 Alexis de Lattre <alexis.delattre@akretion.com>
  2. # Copyright 2016 Pedro M. Baeza <pedro.baeza@tecnativa.com>
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. from odoo import api, SUPERUSER_ID
  5. import logging
  6. logger = logging.getLogger(__name__)
  7. def set_default_map_settings(cr, registry):
  8. """Method called as post-install script
  9. The default method on the field can't be used, because it would be executed
  10. before loading map_website_data.xml, so it would not be able to set a
  11. value"""
  12. with api.Environment.manage():
  13. env = api.Environment(cr, SUPERUSER_ID, {})
  14. user_model = env['res.users']
  15. users = user_model.search([('context_map_website_id', '=', False)])
  16. logger.info('Updating user settings for maps...')
  17. users.write({
  18. 'context_map_website_id': user_model._default_map_website().id,
  19. 'context_route_map_website_id': (
  20. user_model._default_route_map_website().id),
  21. })
  22. # Update the starting partner this way that is faster
  23. cr.execute("""
  24. UPDATE res_users
  25. SET context_route_start_partner_id = partner_id
  26. WHERE context_route_start_partner_id IS NULL;
  27. """)