<commit_before># -*- coding: utf-8 -*-
from odoo.tests.common import TransactionCase
from odoo.exceptions import UserError, ValidationError
from datetime import datetime, timedelta


class TestStaff(TransactionCase):

    def test_get_image(self):
        '''拿到用户头像,职位的onchange'''
        user_lucy = self.env['res.users'].create({
            'name': 'Lucy',
            'login': '<EMAIL>',
        })
        staff_pro = self.env['staff'].create({
            'identification_id': 111111,
            'work_phone': 12345678901,
            'work_email': '<EMAIL>',
            'name': 'Lucy',
            'code': 'lucy',
            'type': 'member',
            'user_id': user_lucy.id,
            'job_id': self.env.ref('staff.staff_job_1').id})
        staff_pro.onchange_job_id()

    def test_staff_contract_over_date(self):
        '''测试：员工合同到期，发送邮件给员工 和 部门经理（如果存在）'''

        job = self.browse_ref('staff.ir_cron_module_remind_contract_over_date')
        job.interval_type = 'minutes'
        job.nextcall = (datetime.now() + timedelta(hours=8)
                        ).strftime('%Y-%m-%d %H:%M:%S')
        job.doall = True
        # not staff.contract_ids
        self.env['staff'].staff_contract_over_date()

        # has staff.contract_ids but no apartment manager
        staff_lily = self.env.ref('staff.lili')
        staff_lily.work_email = '<EMAIL>'
        staff_lily.contract_ids.create({'staff_id': staff_lily.id,
                                        'basic_wage': 123456,
                                        'over_date': datetime.now().strftime("%Y-%m-%d"),
                                        'job_id': self.env.ref('staff.staff_job_1').id})
        # has staff.contract_ids and apartment manager
        self.env.ref('staff.staff_1').work_email = '<EMAIL>'
        staff_lily.parent_id = self.env.ref('staff.staff_1').id
        self.env['staff'].staff_contract_over_date()

    def test_onchange_basic_wage(self):
        ''' 测试：选择基本工资时带出五险一金比例，计算出应交金额并填充 '''
        company = self.env['res.company']._company_default_get()
        company.endowment_ratio = 8
        # company.health_ratio = 2
        # company.unemployment_ratio = 0.5
        # company.housing_fund_ratio = 7
        # company.endowment_co_ratio = 20
        # company.health_co_ratio = 10
        # company.unemployment_co_ratio = 1
        # company.injury_ratio = 1
        # company.maternity_ratio = 0.5
        # company.housing_fund_co_ratio = 7

        lili_contract = self.env.ref('staff.contract_staff_lili')
        lili_contract.basic_wage = 13000
        lili_contract.onchange_basic_wage()


class TestStaffDepartment(TransactionCase):
    ''' 测试 部门 '''

    def test_check_parent_id(self):<commit_msg>[IMP] 添加 staff 办公邮箱测试数据<commit_after># -*- coding: utf-8 -*-
from odoo.tests.common import TransactionCase
from odoo.exceptions import UserError, ValidationError
from datetime import datetime, timedelta


class TestStaff(TransactionCase):

    def test_get_image(self):
        '''拿到用户头像,职位的onchange'''
        user_lucy = self.env['res.users'].create({
            'name': 'Lucy',
            'login': '<EMAIL>',
        })
        staff_pro = self.env['staff'].create({
            'identification_id': 111111,
            'work_phone': 12345678901,
            'work_email': '<EMAIL>',
            'name': 'Lucy',
            'code': 'lucy',
            'type': 'member',
            'user_id': user_lucy.id,
            'job_id': self.env.ref('staff.staff_job_1').id})
        staff_pro.onchange_job_id()

    def test_staff_contract_over_date(self):
        '''测试：员工合同到期，发送邮件给员工 和 部门经理（如果存在）'''

        job = self.browse_ref('staff.ir_cron_module_remind_contract_over_date')
        job.interval_type = 'minutes'
        job.nextcall = (datetime.now() + timedelta(hours=8)
                        ).strftime('%Y-%m-%d %H:%M:%S')
        job.doall = True
        # not staff.contract_ids
        self.env['staff'].staff_contract_over_date()

        # has staff.contract_ids but no apartment manager
        staff_lily = self.env.ref('staff.lili')
        staff_lily.work_email = '<EMAIL>'
        staff_lily.contract_ids.create({'staff_id': staff_lily.id,
                                        'basic_wage': 123456,
                                        'over_date': datetime.now().strftime("%Y-%m-%d"),
                                        'job_id': self.env.ref('staff.staff_job_1').id})
        # has staff.contract_ids and apartment manager
        self.env.ref('staff.staff_1').work_email = '<EMAIL>'
        staff_lily.parent_id = self.env.ref('staff.staff_1').id
        self.env['staff'].staff_contract_over_date()

    def test_onchange_basic_wage(self):
        ''' 测试：选择基本工资时带出五险一金比例，计算出应交金额并填充 '''
        company = self.env['res.company']._company_default_get()
        company.endowment_ratio = 8
        # company.health_ratio = 2
        # company.unemployment_ratio = 0.5
        # company.housing_fund_ratio = 7
        # company.endowment_co_ratio = 20
        # company.health_co_ratio = 10
        # company.unemployment_co_ratio = 1
        # company.injury_ratio = 1
        # company.maternity_ratio = 0.5
        # company.housing_fund_co_ratio = 7

        lili_contract = self.env.ref('staff.contract_staff_lili')
        lili_contract.basic_wage = 13000
        lili_contract.onchange_basic_wage()

    def test_check_work_email(self):
        ''' Test: check work email  '''
        staff_lili = self.env.ref('staff.lili')
        # 测试邮箱格式正确
        staff_lili.work_email = '<EMAIL>'
        # 测试邮箱格式不正确，报错
        with self.assertRaises(ValidationError):
            staff_lili.work_email = 'gooderp'


class TestStaffDepartment(TransactionCase):
    ''' 测试 部门 '''

    def test_check_parent_id(self):
{'fraction_non_alphanumeric': 0.12800970032911832, 'fraction_numerical': 0.016629135631387494, 'mean_word_length': 2.2975442604226157, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3363957', 'n_tokens_mistral': 2016, 'n_tokens_neox': 1960, 'n_words': 278}