feat(minor): fetch default salary structure and base from Employee Grade in Salary Structure Assignment (#30918)
This commit is contained in:
parent
c05144fb60
commit
7f1024f8aa
@ -8,7 +8,9 @@
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"default_salary_structure"
|
||||
"default_salary_structure",
|
||||
"currency",
|
||||
"default_base_pay"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
@ -16,14 +18,31 @@
|
||||
"fieldtype": "Link",
|
||||
"label": "Default Salary Structure",
|
||||
"options": "Salary Structure"
|
||||
},
|
||||
{
|
||||
"depends_on": "default_salary_structure",
|
||||
"fieldname": "default_base_pay",
|
||||
"fieldtype": "Currency",
|
||||
"label": "Default Base Pay",
|
||||
"options": "currency"
|
||||
},
|
||||
{
|
||||
"fetch_from": "default_salary_structure.currency",
|
||||
"fieldname": "currency",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 1,
|
||||
"label": "Currency",
|
||||
"options": "Currency",
|
||||
"read_only": 1
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2020-08-26 13:12:07.815330",
|
||||
"modified": "2022-05-06 15:42:10.395508",
|
||||
"modified_by": "Administrator",
|
||||
"module": "HR",
|
||||
"name": "Employee Grade",
|
||||
"naming_rule": "Set by user",
|
||||
"owner": "Administrator",
|
||||
"permissions": [
|
||||
{
|
||||
@ -65,5 +84,6 @@
|
||||
],
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"states": [],
|
||||
"track_changes": 1
|
||||
}
|
@ -164,6 +164,15 @@ frappe.ui.form.on('Salary Structure', {
|
||||
primary_action_label: __('Assign')
|
||||
});
|
||||
|
||||
d.fields_dict.grade.df.onchange = function() {
|
||||
const grade = d.fields_dict.grade.value;
|
||||
if (grade) {
|
||||
frappe.db.get_value('Employee Grade', grade, 'default_base_pay')
|
||||
.then(({ message }) => {
|
||||
d.set_value('base', message.default_base_pay);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
d.show();
|
||||
},
|
||||
|
@ -4,6 +4,7 @@
|
||||
import unittest
|
||||
|
||||
import frappe
|
||||
from frappe.tests.utils import FrappeTestCase
|
||||
from frappe.utils import add_years, date_diff, get_first_day, nowdate
|
||||
from frappe.utils.make_random import get_random
|
||||
|
||||
@ -23,7 +24,7 @@ from erpnext.payroll.doctype.salary_structure.salary_structure import make_salar
|
||||
test_dependencies = ["Fiscal Year"]
|
||||
|
||||
|
||||
class TestSalaryStructure(unittest.TestCase):
|
||||
class TestSalaryStructure(FrappeTestCase):
|
||||
def setUp(self):
|
||||
for dt in ["Salary Slip", "Salary Structure", "Salary Structure Assignment"]:
|
||||
frappe.db.sql("delete from `tab%s`" % dt)
|
||||
@ -132,6 +133,23 @@ class TestSalaryStructure(unittest.TestCase):
|
||||
self.assertEqual(salary_structure_assignment.base, 5000)
|
||||
self.assertEqual(salary_structure_assignment.variable, 200)
|
||||
|
||||
def test_employee_grade_defaults(self):
|
||||
salary_structure = make_salary_structure(
|
||||
"Salary Structure - Lead", "Monthly", currency="INR", company="_Test Company"
|
||||
)
|
||||
create_employee_grade("Lead", salary_structure.name)
|
||||
employee = make_employee("test_employee_grade@salary.com", company="_Test Company", grade="Lead")
|
||||
|
||||
# structure assignment should have the default salary structure and base pay
|
||||
salary_structure.assign_salary_structure(employee=employee, from_date=nowdate())
|
||||
structure, base = frappe.db.get_value(
|
||||
"Salary Structure Assignment",
|
||||
{"employee": employee, "salary_structure": salary_structure.name, "from_date": nowdate()},
|
||||
["salary_structure", "base"],
|
||||
)
|
||||
self.assertEqual(structure, salary_structure.name)
|
||||
self.assertEqual(base, 50000)
|
||||
|
||||
def test_multi_currency_salary_structure(self):
|
||||
make_employee("test_muti_currency_employee@salary.com")
|
||||
sal_struct = make_salary_structure("Salary Structure Multi Currency", "Monthly", currency="USD")
|
||||
@ -251,3 +269,15 @@ def get_payable_account(company=None):
|
||||
if not company:
|
||||
company = erpnext.get_default_company()
|
||||
return frappe.db.get_value("Company", company, "default_payroll_payable_account")
|
||||
|
||||
|
||||
def create_employee_grade(grade, default_structure=None):
|
||||
if not frappe.db.exists("Employee Grade", grade):
|
||||
frappe.get_doc(
|
||||
{
|
||||
"doctype": "Employee Grade",
|
||||
"__newname": grade,
|
||||
"default_salary_structure": default_structure,
|
||||
"default_base_pay": 50000,
|
||||
}
|
||||
).insert()
|
||||
|
@ -10,6 +10,7 @@
|
||||
"employee",
|
||||
"employee_name",
|
||||
"department",
|
||||
"grade",
|
||||
"company",
|
||||
"payroll_payable_account",
|
||||
"column_break_6",
|
||||
@ -67,6 +68,8 @@
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"fetch_from": "grade.default_salary_structure",
|
||||
"fetch_if_empty": 1,
|
||||
"fieldname": "salary_structure",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
@ -96,6 +99,8 @@
|
||||
"label": "Base & Variable"
|
||||
},
|
||||
{
|
||||
"fetch_from": "grade.default_base_pay",
|
||||
"fetch_if_empty": 1,
|
||||
"fieldname": "base",
|
||||
"fieldtype": "Currency",
|
||||
"label": "Base",
|
||||
@ -158,11 +163,19 @@
|
||||
"fieldtype": "Table",
|
||||
"label": "Cost Centers",
|
||||
"options": "Employee Cost Center"
|
||||
},
|
||||
{
|
||||
"fetch_from": "employee.grade",
|
||||
"fieldname": "grade",
|
||||
"fieldtype": "Link",
|
||||
"label": "Grade",
|
||||
"options": "Employee Grade",
|
||||
"read_only": 1
|
||||
}
|
||||
],
|
||||
"is_submittable": 1,
|
||||
"links": [],
|
||||
"modified": "2022-01-19 12:43:54.439073",
|
||||
"modified": "2022-05-06 12:18:36.972336",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Payroll",
|
||||
"name": "Salary Structure Assignment",
|
||||
|
Loading…
x
Reference in New Issue
Block a user