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.

66 lines
2.2 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. import logging
  6. from odoo import api, fields, models
  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)], limit=1
  14. )
  15. @api.model
  16. def _default_route_map_website(self):
  17. return self.env["map.website"].search(
  18. [
  19. "|",
  20. ("route_address_url", "!=", False),
  21. ("route_lat_lon_url", "!=", False),
  22. ],
  23. limit=1,
  24. )
  25. # begin with context_ to allow user to change it by himself
  26. context_map_website_id = fields.Many2one(
  27. "map.website",
  28. string="Map Website",
  29. default=lambda self: self._default_map_website(),
  30. domain=["|", ("address_url", "!=", False), ("lat_lon_url", "!=", False)],
  31. )
  32. # We want to give the possibility to the user to have one map provider for
  33. # regular maps and another one for routing
  34. context_route_map_website_id = fields.Many2one(
  35. "map.website",
  36. string="Route Map Website",
  37. domain=[
  38. "|",
  39. ("route_address_url", "!=", False),
  40. ("route_lat_lon_url", "!=", False),
  41. ],
  42. default=lambda self: self._default_route_map_website(),
  43. help="Map provided used when you click on the car icon on the partner "
  44. "form to display an itinerary.",
  45. )
  46. context_route_start_partner_id = fields.Many2one(
  47. "res.partner", string="Start Address for Route Map"
  48. )
  49. @api.model
  50. def create(self, vals):
  51. """On creation, if no starting partner is provided, assign the current
  52. created one.
  53. """
  54. user = super(ResUsers, self).create(vals)
  55. if not vals.get("context_route_start_partner_id"):
  56. user.write({"context_route_start_partner_id": user.partner_id.id})
  57. return user