fix: revert removal of gratuity payment via salary slip (#29589)
This commit is contained in:
parent
fe37103dcb
commit
961467c389
@ -3,6 +3,14 @@
|
|||||||
|
|
||||||
frappe.ui.form.on('Gratuity', {
|
frappe.ui.form.on('Gratuity', {
|
||||||
setup: function (frm) {
|
setup: function (frm) {
|
||||||
|
frm.set_query("salary_component", function () {
|
||||||
|
return {
|
||||||
|
filters: {
|
||||||
|
type: "Earning"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
frm.set_query("expense_account", function () {
|
frm.set_query("expense_account", function () {
|
||||||
return {
|
return {
|
||||||
filters: {
|
filters: {
|
||||||
@ -24,7 +32,7 @@ frappe.ui.form.on('Gratuity', {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
refresh: function (frm) {
|
refresh: function (frm) {
|
||||||
if (frm.doc.docstatus == 1 && frm.doc.status == "Unpaid") {
|
if (frm.doc.docstatus == 1 && !frm.doc.pay_via_salary_slip && frm.doc.status == "Unpaid") {
|
||||||
frm.add_custom_button(__("Create Payment Entry"), function () {
|
frm.add_custom_button(__("Create Payment Entry"), function () {
|
||||||
return frappe.call({
|
return frappe.call({
|
||||||
method: 'erpnext.accounts.doctype.payment_entry.payment_entry.get_payment_entry',
|
method: 'erpnext.accounts.doctype.payment_entry.payment_entry.get_payment_entry',
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"actions": [],
|
"actions": [],
|
||||||
"autoname": "HR-GRA-PAY-.#####",
|
"autoname": "HR-GRA-PAY-.#####",
|
||||||
"creation": "2020-08-05 20:52:13.024683",
|
"creation": "2022-01-27 16:24:28.200061",
|
||||||
"doctype": "DocType",
|
"doctype": "DocType",
|
||||||
"editable_grid": 1,
|
"editable_grid": 1,
|
||||||
"engine": "InnoDB",
|
"engine": "InnoDB",
|
||||||
@ -16,6 +16,9 @@
|
|||||||
"company",
|
"company",
|
||||||
"gratuity_rule",
|
"gratuity_rule",
|
||||||
"section_break_5",
|
"section_break_5",
|
||||||
|
"pay_via_salary_slip",
|
||||||
|
"payroll_date",
|
||||||
|
"salary_component",
|
||||||
"payable_account",
|
"payable_account",
|
||||||
"expense_account",
|
"expense_account",
|
||||||
"mode_of_payment",
|
"mode_of_payment",
|
||||||
@ -78,18 +81,20 @@
|
|||||||
"reqd": 1
|
"reqd": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"depends_on": "eval: !doc.pay_via_salary_slip",
|
||||||
"fieldname": "expense_account",
|
"fieldname": "expense_account",
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"label": "Expense Account",
|
"label": "Expense Account",
|
||||||
"options": "Account",
|
"mandatory_depends_on": "eval: !doc.pay_via_salary_slip",
|
||||||
"reqd": 1
|
"options": "Account"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"depends_on": "eval: !doc.pay_via_salary_slip",
|
||||||
"fieldname": "mode_of_payment",
|
"fieldname": "mode_of_payment",
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"label": "Mode of Payment",
|
"label": "Mode of Payment",
|
||||||
"options": "Mode of Payment",
|
"mandatory_depends_on": "eval: !doc.pay_via_salary_slip",
|
||||||
"reqd": 1
|
"options": "Mode of Payment"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "gratuity_rule",
|
"fieldname": "gratuity_rule",
|
||||||
@ -151,23 +156,45 @@
|
|||||||
"read_only": 1
|
"read_only": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"depends_on": "eval: !doc.pay_via_salary_slip",
|
||||||
"fieldname": "payable_account",
|
"fieldname": "payable_account",
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"label": "Payable Account",
|
"label": "Payable Account",
|
||||||
"options": "Account",
|
"mandatory_depends_on": "eval: !doc.pay_via_salary_slip",
|
||||||
"reqd": 1
|
"options": "Account"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "cost_center",
|
"fieldname": "cost_center",
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"label": "Cost Center",
|
"label": "Cost Center",
|
||||||
"options": "Cost Center"
|
"options": "Cost Center"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"default": "1",
|
||||||
|
"fieldname": "pay_via_salary_slip",
|
||||||
|
"fieldtype": "Check",
|
||||||
|
"label": "Pay via Salary Slip"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"depends_on": "pay_via_salary_slip",
|
||||||
|
"fieldname": "payroll_date",
|
||||||
|
"fieldtype": "Date",
|
||||||
|
"label": "Payroll Date",
|
||||||
|
"mandatory_depends_on": "pay_via_salary_slip"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"depends_on": "pay_via_salary_slip",
|
||||||
|
"fieldname": "salary_component",
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"label": "Salary Component",
|
||||||
|
"mandatory_depends_on": "pay_via_salary_slip",
|
||||||
|
"options": "Salary Component"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"is_submittable": 1,
|
"is_submittable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2022-01-19 12:54:37.306145",
|
"modified": "2022-02-02 14:00:45.536152",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Payroll",
|
"module": "Payroll",
|
||||||
"name": "Gratuity",
|
"name": "Gratuity",
|
||||||
|
@ -21,7 +21,10 @@ class Gratuity(AccountsController):
|
|||||||
self.status = "Unpaid"
|
self.status = "Unpaid"
|
||||||
|
|
||||||
def on_submit(self):
|
def on_submit(self):
|
||||||
self.create_gl_entries()
|
if self.pay_via_salary_slip:
|
||||||
|
self.create_additional_salary()
|
||||||
|
else:
|
||||||
|
self.create_gl_entries()
|
||||||
|
|
||||||
def on_cancel(self):
|
def on_cancel(self):
|
||||||
self.ignore_linked_doctypes = ['GL Entry']
|
self.ignore_linked_doctypes = ['GL Entry']
|
||||||
@ -64,6 +67,19 @@ class Gratuity(AccountsController):
|
|||||||
|
|
||||||
return gl_entry
|
return gl_entry
|
||||||
|
|
||||||
|
def create_additional_salary(self):
|
||||||
|
if self.pay_via_salary_slip:
|
||||||
|
additional_salary = frappe.new_doc('Additional Salary')
|
||||||
|
additional_salary.employee = self.employee
|
||||||
|
additional_salary.salary_component = self.salary_component
|
||||||
|
additional_salary.overwrite_salary_structure_amount = 0
|
||||||
|
additional_salary.amount = self.amount
|
||||||
|
additional_salary.payroll_date = self.payroll_date
|
||||||
|
additional_salary.company = self.company
|
||||||
|
additional_salary.ref_doctype = self.doctype
|
||||||
|
additional_salary.ref_docname = self.name
|
||||||
|
additional_salary.submit()
|
||||||
|
|
||||||
def set_total_advance_paid(self):
|
def set_total_advance_paid(self):
|
||||||
paid_amount = frappe.db.sql("""
|
paid_amount = frappe.db.sql("""
|
||||||
select ifnull(sum(debit_in_account_currency), 0) as paid_amount
|
select ifnull(sum(debit_in_account_currency), 0) as paid_amount
|
||||||
|
@ -10,7 +10,7 @@ def get_data():
|
|||||||
'transactions': [
|
'transactions': [
|
||||||
{
|
{
|
||||||
'label': _('Payment'),
|
'label': _('Payment'),
|
||||||
'items': ['Payment Entry']
|
'items': ['Payment Entry', 'Additional Salary']
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -18,27 +18,25 @@ from erpnext.regional.united_arab_emirates.setup import create_gratuity_rule
|
|||||||
|
|
||||||
test_dependencies = ["Salary Component", "Salary Slip", "Account"]
|
test_dependencies = ["Salary Component", "Salary Slip", "Account"]
|
||||||
class TestGratuity(unittest.TestCase):
|
class TestGratuity(unittest.TestCase):
|
||||||
@classmethod
|
def setUp(self):
|
||||||
def setUpClass(cls):
|
frappe.db.delete("Gratuity")
|
||||||
|
frappe.db.delete("Additional Salary", {"ref_doctype": "Gratuity"})
|
||||||
|
|
||||||
make_earning_salary_component(setup=True, test_tax=True, company_list=['_Test Company'])
|
make_earning_salary_component(setup=True, test_tax=True, company_list=['_Test Company'])
|
||||||
make_deduction_salary_component(setup=True, test_tax=True, company_list=['_Test Company'])
|
make_deduction_salary_component(setup=True, test_tax=True, company_list=['_Test Company'])
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
frappe.db.sql("DELETE FROM `tabGratuity`")
|
|
||||||
|
|
||||||
def test_get_last_salary_slip_should_return_none_for_new_employee(self):
|
def test_get_last_salary_slip_should_return_none_for_new_employee(self):
|
||||||
new_employee = make_employee("new_employee@salary.com", company='_Test Company')
|
new_employee = make_employee("new_employee@salary.com", company='_Test Company')
|
||||||
salary_slip = get_last_salary_slip(new_employee)
|
salary_slip = get_last_salary_slip(new_employee)
|
||||||
assert salary_slip is None
|
assert salary_slip is None
|
||||||
|
|
||||||
def test_check_gratuity_amount_based_on_current_slab(self):
|
def test_check_gratuity_amount_based_on_current_slab_and_additional_salary_creation(self):
|
||||||
employee, sal_slip = create_employee_and_get_last_salary_slip()
|
employee, sal_slip = create_employee_and_get_last_salary_slip()
|
||||||
|
|
||||||
rule = get_gratuity_rule("Rule Under Unlimited Contract on termination (UAE)")
|
rule = get_gratuity_rule("Rule Under Unlimited Contract on termination (UAE)")
|
||||||
|
gratuity = create_gratuity(pay_via_salary_slip=1, employee=employee, rule=rule.name)
|
||||||
|
|
||||||
gratuity = create_gratuity(employee=employee, rule=rule.name)
|
# work experience calculation
|
||||||
|
|
||||||
#work experience calculation
|
|
||||||
date_of_joining, relieving_date = frappe.db.get_value('Employee', employee, ['date_of_joining', 'relieving_date'])
|
date_of_joining, relieving_date = frappe.db.get_value('Employee', employee, ['date_of_joining', 'relieving_date'])
|
||||||
employee_total_workings_days = (get_datetime(relieving_date) - get_datetime(date_of_joining)).days
|
employee_total_workings_days = (get_datetime(relieving_date) - get_datetime(date_of_joining)).days
|
||||||
|
|
||||||
@ -64,6 +62,9 @@ class TestGratuity(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertEqual(flt(gratuity_amount, 2), flt(gratuity.amount, 2))
|
self.assertEqual(flt(gratuity_amount, 2), flt(gratuity.amount, 2))
|
||||||
|
|
||||||
|
# additional salary creation (Pay via salary slip)
|
||||||
|
self.assertTrue(frappe.db.exists("Additional Salary", {"ref_docname": gratuity.name}))
|
||||||
|
|
||||||
def test_check_gratuity_amount_based_on_all_previous_slabs(self):
|
def test_check_gratuity_amount_based_on_all_previous_slabs(self):
|
||||||
employee, sal_slip = create_employee_and_get_last_salary_slip()
|
employee, sal_slip = create_employee_and_get_last_salary_slip()
|
||||||
rule = get_gratuity_rule("Rule Under Limited Contract (UAE)")
|
rule = get_gratuity_rule("Rule Under Limited Contract (UAE)")
|
||||||
@ -117,8 +118,8 @@ class TestGratuity(unittest.TestCase):
|
|||||||
self.assertEqual(flt(gratuity.paid_amount,2), flt(gratuity.amount, 2))
|
self.assertEqual(flt(gratuity.paid_amount,2), flt(gratuity.amount, 2))
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
frappe.db.sql("DELETE FROM `tabGratuity`")
|
frappe.db.rollback()
|
||||||
frappe.db.sql("DELETE FROM `tabAdditional Salary` WHERE ref_doctype = 'Gratuity'")
|
|
||||||
|
|
||||||
def get_gratuity_rule(name):
|
def get_gratuity_rule(name):
|
||||||
rule = frappe.db.exists("Gratuity Rule", name)
|
rule = frappe.db.exists("Gratuity Rule", name)
|
||||||
@ -141,9 +142,14 @@ def create_gratuity(**args):
|
|||||||
gratuity.employee = args.employee
|
gratuity.employee = args.employee
|
||||||
gratuity.posting_date = getdate()
|
gratuity.posting_date = getdate()
|
||||||
gratuity.gratuity_rule = args.rule or "Rule Under Limited Contract (UAE)"
|
gratuity.gratuity_rule = args.rule or "Rule Under Limited Contract (UAE)"
|
||||||
gratuity.expense_account = args.expense_account or 'Payment Account - _TC'
|
gratuity.pay_via_salary_slip = args.pay_via_salary_slip or 0
|
||||||
gratuity.payable_account = args.payable_account or get_payable_account("_Test Company")
|
if gratuity.pay_via_salary_slip:
|
||||||
gratuity.mode_of_payment = args.mode_of_payment or 'Cash'
|
gratuity.payroll_date = getdate()
|
||||||
|
gratuity.salary_component = "Performance Bonus"
|
||||||
|
else:
|
||||||
|
gratuity.expense_account = args.expense_account or 'Payment Account - _TC'
|
||||||
|
gratuity.payable_account = args.payable_account or get_payable_account("_Test Company")
|
||||||
|
gratuity.mode_of_payment = args.mode_of_payment or 'Cash'
|
||||||
|
|
||||||
gratuity.save()
|
gratuity.save()
|
||||||
gratuity.submit()
|
gratuity.submit()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user