res_partner.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # -*- coding: utf-8 -*-
  2. ######################################################################################################
  3. #
  4. # Copyright (C) B.H.C. sprl - All Rights Reserved, http://www.bhc.be
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU Lesser General Public License as
  8. # published by the Free Software Foundation, either version 3 of the
  9. # License, or (at your option) any later version.
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
  14. # including but not limited to the implied warranties
  15. # of merchantability and/or fitness for a particular purpose
  16. #
  17. # You should have received a copy of the GNU Lesser General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>
  19. ######################################################################################################
  20. from openerp.tools.translate import _
  21. from openerp import api, fields, tools, exceptions, models, _
  22. class ResPartner(models.Model):
  23. _inherit = "res.partner"
  24. @api.multi
  25. def open_map(self):
  26. for partner in self:
  27. url = "http://maps.google.com/maps?oi=map&q="
  28. if partner.street:
  29. url += partner.street.replace(' ', '+')
  30. if partner.city:
  31. url += '+'+partner.city.replace(' ', '+')
  32. if partner.state_id:
  33. url += '+'+partner.state_id.name.replace(' ', '+')
  34. if partner.country_id:
  35. url += '+'+partner.country_id.name.replace(' ', '+')
  36. if partner.zip:
  37. url += '+'+partner.zip.replace(' ', '+')
  38. return {
  39. 'type': 'ir.actions.act_url',
  40. 'target': 'new',
  41. 'url': url
  42. }