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

from odoo import models, fields, api
from odoo.exceptions import ValidationError
from odoo.tools.translate import _

class res_partner(models.Model):
    _inherit = "res.partner"
    
    nif = fields.Integer('NIF', size=10, required=False, help='Nº de Identificação Fiscal')
    bi = fields.Integer('BI', size=10, required=False, help='Nº de Bilhete de Identidade') 
    data_nascimento = fields.Date('Data Nascimento')
    ideia_negocio = fields.Text('Ideia de Negócio')
    sector_actividade = fields.Selection([('agropecuaria','Agropecuária')
	,('comercio','Comércio'),('industria','Indústria')
	,('servicos','Serviços'),('hotelaria','Hotelaria')
	,('hospitalar','Hospitalar/Clínica'),('restauracao','Restauração')
	,('transportes','Transportes'),('industria_naval','Indústria Naval')],'Sector de Actividade')

    @api.constrains('nif')
    def check_nif(self):
        if self.nif and len(str(self.nif).strip()) != 9:
            raise ValidationError(_("Invalid NIF!\n\nNIF must have 9 digits."))
        
        if self.nif != 0:    
            partners = self.search([('nif','=',self.nif)])
            if len(partners) > 1:
                raise ValidationError(_('NIF already exists!\n\nNIF must be unique.'))
