# -*- coding: utf-8 -*-
##############################################################################
#
#    Odoo, Open Source Management Solution
#    Copyright (C) 2016-TODAY Prime Consulting SA, Cape Verde (<http://prime.cv>).
#
##############################################################################
import time
from datetime import datetime, timedelta

from odoo import models, fields, api


class ReportGuestBySex(models.TransientModel):
    _name = "report.guests.by.age.group"

    enterprise_id = fields.Many2one('etourism.enterprise', 'Enterprise',required=True)
    start_date = fields.Date('Start date')
    end_date = fields.Date('End date')

    @api.model
    def default_get(self, fields):
        res = super(ReportGuestBySex, self).default_get(fields)
        if self.env.uid:
            enterprise_id = self.env['res.users'].browse([self.env.uid])[0].enterprise_id
            if enterprise_id:
                res.update({'enterprise_id': enterprise_id.id})
        return res

    @api.multi
    def action_print_report(self):
        return self.env['report'].get_action(self, 'etourism_reports.report_guests_by_age_group') 

    @api.multi
    def get_guests_info(self, enterprise_id,start_date,end_date,min,max):
        result = 0
        if enterprise_id and start_date and end_date and min and max:
            domain = [('enterprise_id','=',enterprise_id),('age', '>', int(min)),('age', '<=', int(max)),('checkin', '>=', start_date),('checkin', '<=', end_date)]
            print "DOMAIN::::::::::::::::::::::::::::::::::::::::: ",domain
            print "IF::::::::::::::::::::::::::::::::::::::::::::::"
            result = self.env['view.guests.reports'].search_count(domain)
            print "RESULT::::::::::::::::::::::::::::::::::::::::::::::::: ",result
        return result

