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

from odoo.osv import expression
from odoo.tools.float_utils import float_round as round
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT
from odoo.exceptions import UserError, ValidationError
from odoo import api, fields, models, _

class ResCompany(models.Model):
    _inherit = 'res.company'
		
    #Location
    location_country_id = fields.Many2one('ecom.location', 'Country', track_visibility='onchange',index=True)
    island_id = fields.Many2one('ecom.location', 'Island', track_visibility='onchange',index=True)
    county_id = fields.Many2one('ecom.location', 'County', track_visibility='onchange',index=True)
    parish_id = fields.Many2one('ecom.location', 'Parish', track_visibility='onchange',index=True)
    local_id = fields.Many2one('ecom.location', 'Local', track_visibility='onchange',index=True)
    neighborhood_id = fields.Many2one('ecom.location', 'Neighborhood', track_visibility='onchange',index=True)
    #
    state = fields.Selection([('draft', 'New'),
                              ('conceived', 'Conceived'),
                              ('approved', 'Approved'),
                              ('mounted', 'Mounted'),
                              ('inserted', 'Inserted'),('online', 'Online'),('cancel', 'Cancelled')], 'State', default='draft', track_visibility='onchange',translate=False,index=True)
    company_type_id = fields.Many2one('ecom.ebusiness.type', 'Company type',index=True)
    customer_id = fields.Many2one('ecom.customer', 'Customer',index=True)
    one_page = fields.Boolean('One Page', default=False)
    has_site = fields.Boolean('Has site', default=False)
    site = fields.Char(string='Site')
    date_online = fields.Date(string='Date Online')
    #Safepay tab
    pos_id = fields.Char(string='ID Terminal 24')
    posautcode = fields.Char(string='POS Auth code')
    url_sisp = fields.Char(string='SISP URL')
    business_registration = fields.Char(string='Business Registration')
    #Contracts tab
    contract_ebusiness_ids = fields.Many2many('ecom.contract', 'res_company_contract_rel', 'company_id', 'contract_id', string='Contracts', copy=False)
    #System
    api_key = fields.Char(string='API Key')
    captcha_key = fields.Char(string='Captcha Key')

    _sql_constraints = [
        ('pos_id_uniq', 'unique (pos_id)', 'The pos_id of the ebusiness must be unique per ebusiness !'),
        ('posautcode', 'unique (posautcode)', 'The posautcode of the ebusiness must be unique per ebusiness !')
    ]
