odex30_standard/exp_payroll_custom/tests/test_employee_reward.py

134 lines
4.5 KiB
Python

# -*- coding: utf-8 -*-
from odoo.tests.common import TransactionCase
from odoo.exceptions import UserError
from odoo.tests import tagged
from datetime import date
@tagged('post_install', '-at_install')
class TestEmployeeReward(TransactionCase):
def setUp(self):
super(TestEmployeeReward, self).setUp()
self.employee = self.env['hr.employee'].create({
'name': 'Test Employee',
})
self.account_debit = self.env['account.account'].create({
'name': 'Debit Account',
'code': '100001',
'account_type': 'expense',
'reconcile': True,
})
self.account_credit = self.env['account.account'].create({
'name': 'Credit Account',
'code': '200001',
'account_type': 'liability_payable',
'reconcile': True,
})
self.journal = self.env['account.journal'].create({
'name': 'Reward Journal',
'type': 'general',
'code': 'REW',
'default_account_id': self.account_credit.id,
})
self.contract = self.env['hr.contract'].create({
'name': 'Contract for Test',
'employee_id': self.employee.id,
'wage': 5000.0,
'state': 'open',
})
def test_01_reward_workflow_and_calculation(self):
reward = self.env['hr.employee.reward'].create({
'allowance_reason': 'Excellent Performance',
'date': date.today(),
'reward_type': 'amount',
'amount': 1000.0,
'transfer_type': 'accounting',
'account_id': self.account_debit.id,
'journal_id': self.journal.id,
})
reward_line = self.env['lines.ids.reward'].create({
'employee_reward_id': reward.id,
'employee_id': self.employee.id,
'percentage': 50.0,
})
self.assertEqual(reward_line.amount, 500.0, "Amount calculation is wrong based on percentage")
reward.action_submit()
self.assertEqual(reward.state, 'submitted', "State should be submitted")
self.assertEqual(reward_line.reward_state, 'submitted', "Line state should match parent")
reward.action_hrm()
self.assertEqual(reward.state, 'hrm', "State should be hrm")
reward.action_done()
self.assertEqual(reward.state, 'done', "State should be done")
self.assertTrue(reward_line.move_id, "Journal Entry should be created")
self.assertEqual(reward_line.move_id.state, 'draft', "Move should be created in draft")
move_lines = reward_line.move_id.line_ids
debit_line = move_lines.filtered(lambda l: l.debit > 0)
credit_line = move_lines.filtered(lambda l: l.credit > 0)
self.assertEqual(debit_line.account_id, self.account_debit, "Debit account mismatch")
self.assertEqual(credit_line.account_id, self.account_credit, "Credit account mismatch")
self.assertEqual(debit_line.debit, 500.0, "Debit amount incorrect")
def test_02_constraint_reward_once_yearly(self):
reward_1 = self.env['hr.employee.reward'].create({
'allowance_reason': 'First Reward',
'date': date.today(),
'reward_type': 'amount',
'amount': 1000.0,
'reward_once': True,
'transfer_type': 'accounting',
'account_id': self.account_debit.id,
'journal_id': self.journal.id,
})
self.env['lines.ids.reward'].create({
'employee_reward_id': reward_1.id,
'employee_id': self.employee.id,
'percentage': 100.0,
})
reward_1.action_submit()
reward_1.action_hrm()
reward_1.action_done()
reward_2 = self.env['hr.employee.reward'].create({
'allowance_reason': 'Second Reward',
'date': date.today(),
'reward_type': 'amount',
'amount': 500.0,
'reward_once': True,
})
with self.assertRaises(UserError):
self.env['lines.ids.reward'].create({
'employee_reward_id': reward_2.id,
'employee_id': self.employee.id,
'percentage': 100.0,
})
def test_03_positive_amount_check(self):
reward = self.env['hr.employee.reward'].create({
'allowance_reason': 'Negative Test',
'date': date.today(),
'amount': 100.0,
})
with self.assertRaises(UserError):
reward.amount = -50.0
reward.chick_amount_positive()