from odoo.tests.common import TransactionCase from odoo import fields from odoo.tests.common import TransactionCase from odoo.exceptions import UserError class TestHrContractSalaryScale(TransactionCase): def setUp(self): super().setUp() self.employee = self.env['hr.employee'].create({ 'name': 'Test Employee', }) allow_cat = self.env['hr.salary.rule.category'].create({ 'name': 'Allowance', 'code': 'ALW', 'rule_type': 'allowance' }) ded_cat = self.env['hr.salary.rule.category'].create({ 'name': 'Deduction', 'code': 'DED', 'rule_type': 'deduction' }) self.structure = self.env['hr.payroll.structure'].create({ 'name': 'Scale Structure', 'type': 'scale', 'code': 'SCALE_TEST', 'parent_id': False, }) self.allow_rule = self.env['hr.salary.rule'].create({ 'name': 'Allowance Rule', 'code': 'ALLOW1', 'category_id': allow_cat.id, 'amount_select': 'fix', 'amount_fix': 1000, 'quantity': '1.0', 'condition_select': 'none' }) self.ded_rule = self.env['hr.salary.rule'].create({ 'name': 'Deduction Rule', 'code': 'DED1', 'category_id': ded_cat.id, 'amount_select': 'fix', 'amount_fix': 200, 'quantity': '1.0', 'condition_select': 'none' }) self.structure.rule_ids = [(6, 0, [self.allow_rule.id, self.ded_rule.id])] self.contract = self.env['hr.contract'].create({ 'name': 'Test Contract', 'employee_id': self.employee.id, 'salary_scale': self.structure.id, 'salary': 5000, }) def test_compute_function_basic(self): self.contract.compute_function() self.assertEqual(self.contract.total_allowance, 1000.0) def test_salary_group_constraint(self): group = self.env['hr.payroll.structure'].create({ 'name': 'Group A', 'gread_min': 3000, 'gread_max': 6000, 'code': 'SCALE_TEST' }) self.contract.salary_group = group.id self.contract.salary = 5000 def test_compute_move_type_one_by_one(self): self.structure.transfer_type = 'one_by_one' self.contract.salary_scale = self.structure.id self.contract.compute_move_type() self.assertTrue(self.contract.required_condition) def test_exception_amount_greater_than_rule(self): rule = self.allow_rule advantage = self.env['contract.advantage'].create({ 'contract_advantage_id': self.contract.id, 'benefits_discounts': rule.id, 'type': 'exception', 'amount': 2000, 'date_from': fields.Date.today(), })