# -*- 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 ReportEbusinessContacts(models.TransientModel):
    _name = "report.ebusiness.contacts"

    ebusiness_type_id = fields.Many2one('ecom.ebusiness.type', 'Ebusiness type')
    island_id = fields.Many2one('ecom.location', string='Island id')
    county_id = fields.Many2one('ecom.location', string='County id')

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

    @api.multi
    def get_ebusiness_details(self, ebusiness_type_id,island_id=False,county_id=False):
        search_item = []
        if ebusiness_type_id:
            search_item.append(('ebusiness_type_id','=',ebusiness_type_id))
        if island_id:
            search_item.append(('island_id','=',island_id))
        if county_id:
            search_item.append(('county_id','=',county_id))
        if ebusiness_type_id:
            ebusiness = self.env['view.ebusiness.reports'].search(search_item)
        return ebusiness

    @api.multi
    def get_ebusiness_contacts(self,field=''):
        email,phone,mobile = '','',''
        enterprise_id = self.env['res.users'].browse([self.env.uid])[0].enterprise_id
        ebusiness_id = enterprise_id.ebusiness_id
        for contact in ebusiness_id.contacts_line:
            if contact.default_contact:
                email = contact.email
                phone = contact.phone
                mobile = contact.mobile
        if field == 'email':
            return email
        elif field == 'phone':
            return phone
        elif field == 'mobile':
            return mobile
