159 lines
5.3 KiB
Python
159 lines
5.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
from odoo.tests.common import TransactionCase
|
|
from odoo.exceptions import ValidationError
|
|
from odoo.tests import tagged
|
|
from datetime import date
|
|
|
|
|
|
@tagged('post_install', '-at_install')
|
|
class TestCustodyReceiving(TransactionCase):
|
|
|
|
def setUp(self):
|
|
super(TestCustodyReceiving, self).setUp()
|
|
|
|
self.employee = self.env['hr.employee'].create({
|
|
'name': 'Test Employee for Custody',
|
|
'emp_no': 'EMP001',
|
|
})
|
|
|
|
self.deduction_category = self.env['hr.salary.rule.category'].create({
|
|
'name': 'Deduction',
|
|
'code': 'DED',
|
|
'rule_type': 'deduction',
|
|
})
|
|
|
|
self.salary_rule = self.env['hr.salary.rule'].create({
|
|
'name': 'Custody Deduction Rule',
|
|
'sequence': 1,
|
|
'code': 'CUST_DED',
|
|
'category_id': self.deduction_category.id,
|
|
'condition_select': 'none',
|
|
'amount_select': 'fix',
|
|
'amount_fix': 0.0,
|
|
})
|
|
|
|
self.contract = self.env['hr.contract'].create({
|
|
'name': 'Contract Test',
|
|
'employee_id': self.employee.id,
|
|
'wage': 5000.0,
|
|
'state': 'open',
|
|
})
|
|
|
|
self.custody_delivered = self.env['custom.employee.custody'].create({
|
|
'employee_id': self.employee.id,
|
|
'state': 'approve',
|
|
})
|
|
|
|
self.custody_line = self.env['employee.custody.line'].create({
|
|
'employee_custody_line': self.custody_delivered.id,
|
|
'name': 'Laptop Dell',
|
|
'serial': 'SN123456',
|
|
'quantity': 1.0,
|
|
'receiving_quantity': 0.0,
|
|
'amount': 0.0,
|
|
})
|
|
|
|
def test_01_custody_receiving_workflow_full_return(self):
|
|
|
|
receiving = self.env['hr.custody.receiving'].create({
|
|
'employee_id': self.employee.id,
|
|
'note': 'Returning Laptop',
|
|
})
|
|
|
|
|
|
receiving._get_custody_line_domain()
|
|
|
|
self.assertTrue(receiving.return_custody_line_ids, "Should fetch pending custody lines")
|
|
line = receiving.return_custody_line_ids[0]
|
|
self.assertEqual(line.custody_line_id, self.custody_line, "Should link to correct original line")
|
|
self.assertEqual(line.quantity, 1.0, "Should default to remaining quantity")
|
|
|
|
receiving.send()
|
|
self.assertEqual(receiving.state, 'submit')
|
|
|
|
receiving.dr_manager()
|
|
self.assertEqual(receiving.state, 'direct')
|
|
|
|
receiving.dr_hr_manager()
|
|
self.assertEqual(receiving.state, 'admin')
|
|
|
|
receiving.warehouse_keeper()
|
|
self.assertEqual(receiving.state, 'approve')
|
|
|
|
receiving.done()
|
|
self.assertEqual(receiving.state, 'done')
|
|
|
|
|
|
self.assertEqual(self.custody_line.receiving_quantity, 1.0, "Original line receiving qty should be updated")
|
|
|
|
self.assertEqual(self.custody_delivered.state, 'done', "Original custody should be done as all items returned")
|
|
|
|
def test_02_custody_receiving_with_deduction(self):
|
|
|
|
receiving = self.env['hr.custody.receiving'].create({
|
|
'employee_id': self.employee.id,
|
|
'salary_rule_id': self.salary_rule.id,
|
|
})
|
|
receiving._get_custody_line_domain()
|
|
|
|
line = receiving.return_custody_line_ids[0]
|
|
line.deduction_amount = 500.0
|
|
|
|
receiving.compute_deduction_amount()
|
|
self.assertEqual(receiving.deduction_amount, 500.0)
|
|
self.assertTrue(receiving.salary_rule_flag)
|
|
|
|
receiving.state = 'approve'
|
|
receiving.done()
|
|
|
|
self.assertTrue(receiving.advantage_line_id, "Should create advantage line")
|
|
self.assertEqual(receiving.advantage_line_id.amount, 500.0, "Advantage amount mismatch")
|
|
self.assertEqual(receiving.advantage_line_id.contract_advantage_id, self.contract)
|
|
|
|
def test_03_validation_over_quantity(self):
|
|
|
|
receiving = self.env['hr.custody.receiving'].create({
|
|
'employee_id': self.employee.id,
|
|
})
|
|
receiving._get_custody_line_domain()
|
|
|
|
line = receiving.return_custody_line_ids[0]
|
|
line.quantity = 2.0
|
|
|
|
receiving.state = 'approve'
|
|
|
|
with self.assertRaises(ValidationError):
|
|
receiving.done()
|
|
|
|
def test_04_reset_to_draft(self):
|
|
|
|
receiving = self.env['hr.custody.receiving'].create({
|
|
'employee_id': self.employee.id,
|
|
'salary_rule_id': self.salary_rule.id,
|
|
})
|
|
receiving._get_custody_line_domain()
|
|
|
|
receiving.return_custody_line_ids[0].deduction_amount = 100.0
|
|
receiving.compute_deduction_amount()
|
|
receiving.state = 'approve'
|
|
receiving.done()
|
|
|
|
self.assertEqual(receiving.state, 'done')
|
|
self.assertTrue(receiving.advantage_line_id)
|
|
|
|
receiving.set_to_draft()
|
|
|
|
self.assertEqual(receiving.state, 'draft')
|
|
self.assertFalse(receiving.advantage_line_id.exists(), "Advantage line should be deleted")
|
|
self.assertEqual(self.custody_line.receiving_quantity, 0.0, "Original qty should be reverted")
|
|
self.assertEqual(self.custody_delivered.state, 'approve')
|
|
|
|
def test_05_unlink_protection(self):
|
|
|
|
receiving = self.env['hr.custody.receiving'].create({
|
|
'employee_id': self.employee.id,
|
|
})
|
|
receiving.send()
|
|
|
|
with self.assertRaises(ValidationError):
|
|
receiving.unlink() |