res_company.py 979 B

1234567891011121314151617181920212223242526272829303132
  1. # -*- coding: utf-8 -*-
  2. # Part of BiztechCS. See LICENSE file for full copyright and licensing details.
  3. import openerp
  4. import urlparse
  5. import werkzeug
  6. from openerp import api, fields, models
  7. class res_company(models.Model):
  8. """override company to add google map api"""
  9. _inherit = "res.company"
  10. google_api_key = fields.Char(string="Google Map API Key")
  11. def urlplus(url, params):
  12. return werkzeug.Href(url)(params or None)
  13. class website(models.Model):
  14. _inherit = 'website'
  15. def google_map_src(self, zoom=8):
  16. user = self.env.user
  17. partner = user.partner_id
  18. params = {
  19. 'key': user.company_id and user.company_id.google_api_key or "",
  20. 'q': '%s,%s, %s %s, %s' % (user.company_id.name or '', partner.street or '', partner.city or '', partner.zip or '', partner.country_id and partner.country_id.name_get()[0][1] or ''),
  21. }
  22. return urlplus('https://www.google.com/maps/embed/v1/place', params)