res_company.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  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.osv import orm
  7. from openerp.osv import osv, fields
  8. class res_company(osv.Model):
  9. """override company to add google map api"""
  10. _inherit = "res.company"
  11. _columns = {
  12. 'google_api_key': fields.char("Google Map API Key")
  13. }
  14. def urlplus(url, params):
  15. return werkzeug.Href(url)(params or None)
  16. class website(orm.Model):
  17. _inherit = 'website'
  18. def google_map_src(self, cr, uid, ids, zoom=8,context=None):
  19. user = self.browse(cr, openerp.SUPERUSER_ID, ids[0], context=context)
  20. partner = self.pool.get('res.partner').browse(cr, uid, user.company_id.partner_id.id, context=context)
  21. params = {
  22. 'key':user.company_id and user.company_id.google_api_key or "",
  23. '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 ''),
  24. }
  25. print params
  26. return urlplus('https://www.google.com/maps/embed/v1/place' , params)