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.

52 lines
2.1 KiB

  1. # Copyright 2015 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
  2. # Copyright 2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
  3. # Copyright 2016 Pedro M. Baeza <pedro.baeza@tecnativa.com>
  4. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  5. from odoo import models, fields, api
  6. import logging
  7. logger = logging.getLogger(__name__)
  8. class ResUsers(models.Model):
  9. _inherit = 'res.users'
  10. @api.model
  11. def _default_map_website(self):
  12. return self.env['map.website'].search([
  13. '|', ('address_url', '!=', False), ('lat_lon_url', '!=', False)],
  14. limit=1)
  15. @api.model
  16. def _default_route_map_website(self):
  17. return self.env['map.website'].search([
  18. '|', ('route_address_url', '!=', False),
  19. ('route_lat_lon_url', '!=', False)], limit=1)
  20. # begin with context_ to allow user to change it by himself
  21. context_map_website_id = fields.Many2one(
  22. 'map.website', string='Map Website', default=_default_map_website,
  23. domain=['|', ('address_url', '!=', False),
  24. ('lat_lon_url', '!=', False)])
  25. # We want to give the possibility to the user to have one map provider for
  26. # regular maps and another one for routing
  27. context_route_map_website_id = fields.Many2one(
  28. 'map.website', string='Route Map Website',
  29. domain=['|', ('route_address_url', '!=', False),
  30. ('route_lat_lon_url', '!=', False)],
  31. default=_default_route_map_website,
  32. help="Map provided used when you click on the car icon on the partner "
  33. "form to display an itinerary.")
  34. context_route_start_partner_id = fields.Many2one(
  35. 'res.partner', string='Start Address for Route Map')
  36. @api.model
  37. def create(self, vals):
  38. """On creation, if no starting partner is provided, assign the current
  39. created one.
  40. """
  41. user = super(ResUsers, self).create(vals)
  42. if not vals.get('context_route_start_partner_id'):
  43. user.context_route_start_partner_id = user.partner_id.id
  44. return user