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.

37 lines
1.3 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. import logging
  5. from odoo import SUPERUSER_ID, api
  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. {
  19. "context_map_website_id": user_model._default_map_website().id,
  20. "context_route_map_website_id": (
  21. user_model._default_route_map_website().id
  22. ),
  23. }
  24. )
  25. # Update the starting partner this way that is faster
  26. cr.execute(
  27. """
  28. UPDATE res_users
  29. SET context_route_start_partner_id = partner_id
  30. WHERE context_route_start_partner_id IS NULL;
  31. """
  32. )