<commit_before># -*- coding: utf-8 -*-
# (c) 2014 Kmee - <NAME> <<EMAIL>>
# (c) 2014 Kmee - <NAME> <<EMAIL>>
# (c) 2016 KMEE Informática - <NAME> <<EMAIL>>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from openerp import models, fields, api, _
from datetime import datetime
from openerp.tools import DEFAULT_SERVER_DATE_FORMAT
from openerp.exceptions import ValidationError


NATIONALITY_CODE = [
    ('10', '10 - Brasileiro'),
    ('20', '20 - Naturalizado Brasileiro'),
    ('21', '21 - Argentino'),
    ('22', '22 - Boliviano'),
    ('23', '23 - Chileno'),
    ('24', '24 - Paraguaio'),
    ('25', '25 - Uruguaio'),
    ('26', '26 - Venezuelano'),
    ('27', '27 - Colombiano'),
    ('28', '28 - Peruano'),
    ('29', '29 - Equatoriano'),
    ('30', u'30 - Alemão'),
    ('31', '31 - Belga'),
    ('32', u'32 - Britânico'),
    ('34', '34 - Canadense'),
    ('35', '35 - Espanhol'),
    ('36', '36 - Norte-americano'),
    ('37', u'37 - Francês'),
    ('38', u'38 - Suíço'),
    ('39', '39 - Italiano'),
    ('40', '40 - Haitiano'),
    ('41', u'41 - Japonês'),
    ('42', u'42 - Chines'),
    ('43', '43 - Coreano'),
    ('44', '44 - Russo'),
    ('45', u'45 - Português'),
    ('46', u'46 - Paquistanês'),
    ('47', '47 - Indiano'),
    ('48', '48 - Outros latino-americanos'),
    ('49', u'49 - Outros asiáticos'),
    ('50', u'50 - Bengalês'),
    ('51', '51 - Outros Europeus'),
    ('60', '60 - Angolano'),
    ('61', u'61 - Congolês'),
    ('62', '62 - Sul-africano'),
    ('63', u'63 - Ganês'),
    ('64', u'64 - Senegalês'),
    ('70', '70 - Outros Africanos'),
    ('80', '80 - Outros')
]


class HrEmployee(models.Model):
    _inherit = 'hr.employee'

    def _default_country(self):
        return self.env['res.country'].search([('code', '=', 'BR')])

    @api.constrains('dependent_ids')
    def _check_dependents(self):
        self._check_dob()
        self._check_dependent_type()

    def _check_dob(self):
        for dependent in self.dependent_ids:
            if datetime.strptime(
                    dependent.dependent_dob, DEFAULT_SERVER_DATE_FORMAT
                    ).date() > datetime.now().date():
                raise ValidationError(_(u'Data de nascimento do '
                                        u'dependente %s inválida'
                                        % dependent.dependent_name))

    def _check_dependent_type(self):
        seen = set()
        restrictions = (
            self.env.ref('l10n_br_hr.l10n_br_dependent_1'),
            self.env.ref('l10n_br_hr.l10n_br_dependent_9_1'),
            self.env.ref('l10n_br_hr.l10n_br_dependent_9_2')
        )
        for dependent in self.dependent_ids:
            dep_type = dependent.dependent_type_id
            if dep_type not in seen and dep_type in restrictions:
                seen.add(dep_type)
            elif dep_type in seen and dep_type in restrictions:
                raise ValidationError(
                    _(u'Já existe um dependente com o mesmo grau '
                      u'de parentesco de %s'
                      % dependent.dependent_name))

    @api.constrains('pis_pasep')
    def _validate_pis_pasep(self):
        employee = self
        if not employee.pis_pasep:
            return True
        digits = []
        for c in employee.pis_pasep:
            if c == '.' or c == ' ' or c == '\t':
                continue
            if c == '-':
                if len(digits) != 10:
                    raise ValidationError(_(u'PIS/PASEP inválido'))
                continue
            if c.isdigit():
                digits.append(int(c))
                continue
            raise ValidationError(_(u'PIS/PASEP inválido'))
        if len(digits) != 11:
            raise ValidationError(_(u'PIS/PASEP inválido'))
        height = [int(x) for x in "3298765432"]
        total = 0
        for i in range(10):
            total += digits[i] * height[i]
        rest = total % 11
        if rest != 0:
            rest = 11 - rest
        if not rest == digits[10]:
            raise ValidationError(_(u'PIS/PASEP inválido'))

    check_cpf = fields.Boolean('Verificar CPF', default=True)<commit_msg>Move PIS/PASEP validation to l10n_br_base<commit_after># -*- coding: utf-8 -*-
# (c) 2014 Kmee - <NAME> <<EMAIL>>
# (c) 2014 Kmee - <NAME> <<EMAIL>>
# (c) 2016 KMEE Informática - <NAME> <<EMAIL>>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from openerp import models, fields, api, _
from datetime import datetime
from openerp.tools import DEFAULT_SERVER_DATE_FORMAT
from openerp.addons.l10n_br_base.tools import fiscal
from openerp.exceptions import ValidationError


NATIONALITY_CODE = [
    ('10', '10 - Brasileiro'),
    ('20', '20 - Naturalizado Brasileiro'),
    ('21', '21 - Argentino'),
    ('22', '22 - Boliviano'),
    ('23', '23 - Chileno'),
    ('24', '24 - Paraguaio'),
    ('25', '25 - Uruguaio'),
    ('26', '26 - Venezuelano'),
    ('27', '27 - Colombiano'),
    ('28', '28 - Peruano'),
    ('29', '29 - Equatoriano'),
    ('30', u'30 - Alemão'),
    ('31', '31 - Belga'),
    ('32', u'32 - Britânico'),
    ('34', '34 - Canadense'),
    ('35', '35 - Espanhol'),
    ('36', '36 - Norte-americano'),
    ('37', u'37 - Francês'),
    ('38', u'38 - Suíço'),
    ('39', '39 - Italiano'),
    ('40', '40 - Haitiano'),
    ('41', u'41 - Japonês'),
    ('42', u'42 - Chines'),
    ('43', '43 - Coreano'),
    ('44', '44 - Russo'),
    ('45', u'45 - Português'),
    ('46', u'46 - Paquistanês'),
    ('47', '47 - Indiano'),
    ('48', '48 - Outros latino-americanos'),
    ('49', u'49 - Outros asiáticos'),
    ('50', u'50 - Bengalês'),
    ('51', '51 - Outros Europeus'),
    ('60', '60 - Angolano'),
    ('61', u'61 - Congolês'),
    ('62', '62 - Sul-africano'),
    ('63', u'63 - Ganês'),
    ('64', u'64 - Senegalês'),
    ('70', '70 - Outros Africanos'),
    ('80', '80 - Outros')
]


class HrEmployee(models.Model):
    _inherit = 'hr.employee'

    def _default_country(self):
        return self.env['res.country'].search([('code', '=', 'BR')])

    @api.constrains('dependent_ids')
    def _check_dependents(self):
        self._check_dob()
        self._check_dependent_type()

    def _check_dob(self):
        for dependent in self.dependent_ids:
            if datetime.strptime(
                    dependent.dependent_dob, DEFAULT_SERVER_DATE_FORMAT
                    ).date() > datetime.now().date():
                raise ValidationError(_(u'Data de nascimento do '
                                        u'dependente %s inválida'
                                        % dependent.dependent_name))

    def _check_dependent_type(self):
        seen = set()
        restrictions = (
            self.env.ref('l10n_br_hr.l10n_br_dependent_1'),
            self.env.ref('l10n_br_hr.l10n_br_dependent_9_1'),
            self.env.ref('l10n_br_hr.l10n_br_dependent_9_2')
        )
        for dependent in self.dependent_ids:
            dep_type = dependent.dependent_type_id
            if dep_type not in seen and dep_type in restrictions:
                seen.add(dep_type)
            elif dep_type in seen and dep_type in restrictions:
                raise ValidationError(
                    _(u'Já existe um dependente com o mesmo grau '
                      u'de parentesco de %s'
                      % dependent.dependent_name))

    @api.constrains('pis_pasep')
    def _validate_pis_pasep(self):
        employee = self
        if not employee.pis_pasep:
            return True
        elif fiscal.validate_pis_pasep(self.pis_pasep):
            return True
        else:
            raise ValidationError(_(u'PIS/PASEP inválido'))

    check_cpf = fields.Boolean('Verificar CPF', default=True)
{'fraction_non_alphanumeric': 0.16275754827005312, 'fraction_numerical': 0.05261111831022418, 'mean_word_length': 2.095868431608504, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3928255', 'n_tokens_mistral': 2840, 'n_tokens_neox': 2563, 'n_words': 601}