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

from odoo import fields, models, api
from odoo.exceptions import ValidationError
#import xlrd
import base64
import logging
from datetime import datetime, timedelta

_logger = logging.getLogger(__name__)

class update_amenities_wizard(models.TransientModel):
    _name = "update.amenities.wizard"
    _description = "Update amenities"

    @api.multi
    def action_update_amenities(self):
        """Update amenities
        """
        parent_id_lmits=False
        parent_id=False
        enterprises = self.env['etourism.enterprise'].search([('ebusiness_type_code','=','ALO')])
        for enterprise in enterprises:
            self._cr.execute("""select etourism_amenities_id from etourism_amenities_etourism_enterprise_rel where etourism_enterprise_id=%s"""%(enterprise.id))
            result = self._cr.fetchall()
            if result:
                for res in result:
                    self.env['etourism.enterprise.amenity'].create({
                        'enterprise_id':enterprise.id,
                        'amenity_id':res[0],
                        'featured':True
                    })
        return self.env['warning'].info(title='Sucesso', message="As amenidades foram criadas com sucesso!!")
