# -*- coding: utf-8 -*-

import re

from odoo import api, fields, models, _
from odoo.addons.website.models.website import slug


class EnterpriseType(models.Model):
    _inherit = 'ecom.ebusiness.type'

    @api.multi
    def get_data_accommodation(self, island_code,data_field):
        if island_code and data_field:
            if data_field=='num_enterprises':
                query = """select count(*) as count from etourism_enterprise where ebusiness_type_code='ALO' and island_code='%s' and enterprise_type_id=%s and is_legal is true"""%(island_code,self.id)
            elif data_field=='num_rooms':
                query = """select sum(number_rooms) as count from etourism_enterprise where ebusiness_type_code='ALO' and island_code='%s' and enterprise_type_id=%s and is_legal is true"""%(island_code,self.id)
            elif data_field=='num_beds':
                query = """select sum(number_beds) as count from etourism_enterprise where ebusiness_type_code='ALO' and island_code='%s' and enterprise_type_id=%s and is_legal is true"""%(island_code,self.id)
				
            self._cr.execute(query)
            result = self._cr.fetchone()
            if result:
                return result[0]
        return None

