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.

65 lines
2.2 KiB

  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # Partner Address on Map module for OpenERP
  5. # Copyright (C) 2015 Akretion (http://www.akretion.com/)
  6. # @author: Alexis de Lattre <alexis.delattre@akretion.com>
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU Affero General Public License as
  10. # published by the Free Software Foundation, either version 3 of the
  11. # License, or (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU Affero General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Affero General Public License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. #
  21. ##############################################################################
  22. from openerp import models, fields, api, _
  23. from openerp.exceptions import Warning
  24. class MapUrl(models.Model):
  25. _name = 'map.url'
  26. _description = 'Map System'
  27. name = fields.Char(string='Map Provider', required=True)
  28. url = fields.Char(string='URL', required=True)
  29. class ResUsers(models.Model):
  30. _inherit = 'res.users'
  31. # begin with context_ to allow user to change it by himself
  32. context_map_url_id = fields.Many2one(
  33. 'map.url', string='Map Provider')
  34. # TODO: Add default
  35. class ResPartner(models.Model):
  36. _inherit = 'res.partner'
  37. @api.multi
  38. def open_map(self):
  39. if not self.env.user.context_map_url_id:
  40. raise Warning(_(
  41. 'Missing Map Provider: you should set it in your Preferences.'))
  42. url = self.env.user.context_map_url_id.url
  43. if self.street:
  44. url += self.street
  45. if self.city:
  46. url += ' ' + self.city
  47. if self.state_id:
  48. url += ' ' + self.state_id.name
  49. if self.country_id:
  50. url += ' ' + self.country_id.name
  51. return {
  52. 'type': 'ir.actions.act_url',
  53. 'url': url,
  54. 'targer': 'new',
  55. }