# -*- coding: utf-8 -*-
# Part of BiztechCS. See LICENSE file for full copyright and licensing details.

import openerp
import urlparse
import werkzeug
from openerp import api, fields, models


class res_company(models.Model):

    """override company to add google map api"""
    _inherit = "res.company"

    google_api_key = fields.Char(string="Google Map API Key")


def urlplus(url, params):
    return werkzeug.Href(url)(params or None)


class website(models.Model):
    _inherit = 'website'

    def google_map_src(self, zoom=8):
        user = self.env.user
        partner = user.partner_id
        params = {
            'key': user.company_id and user.company_id.google_api_key or "",
            '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 ''),
        }
        return urlplus('https://www.google.com/maps/embed/v1/place', params)
