mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-26 16:34:46 +00:00
style: Broken into smaller function
This commit is contained in:
@@ -2,8 +2,7 @@
|
|||||||
# License: GNU General Public License v3. See license.txt
|
# License: GNU General Public License v3. See license.txt
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
import frappe
|
||||||
import erpnext, frappe
|
|
||||||
|
|
||||||
def execute():
|
def execute():
|
||||||
frappe.reload_doc('payroll', 'doctype', 'gratuity_rule')
|
frappe.reload_doc('payroll', 'doctype', 'gratuity_rule')
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ class Gratuity(Document):
|
|||||||
self.status = "Paid"
|
self.status = "Paid"
|
||||||
|
|
||||||
def on_submit(self):
|
def on_submit(self):
|
||||||
create_additional_salary()
|
self.create_additional_salary()
|
||||||
|
|
||||||
def create_additional_salary(self):
|
def create_additional_salary(self):
|
||||||
if self.pay_via_salary_slip:
|
if self.pay_via_salary_slip:
|
||||||
@@ -194,6 +194,3 @@ def get_last_salary_slip(employee):
|
|||||||
},
|
},
|
||||||
order_by = "start_date desc")[0].name
|
order_by = "start_date desc")[0].name
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ frappe.ui.form.on('Gratuity Rule Slab', {
|
|||||||
Wrong order may lead to Wrong Calculation
|
Wrong order may lead to Wrong Calculation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
gratuity_rule_slabs_add(frm, cdt, cdn) {
|
gratuity_rule_slabs_add(frm, cdt, cdn) {
|
||||||
let row = locals[cdt][cdn];
|
let row = locals[cdt][cdn];
|
||||||
let array_idx = row.idx - 1;
|
let array_idx = row.idx - 1;
|
||||||
|
|||||||
@@ -17,4 +17,17 @@ class GratuityRule(Document):
|
|||||||
if current_slab.to_year == 0 and current_slab.from_year == 0 and len(self.gratuity_rule_slabs) > 1:
|
if current_slab.to_year == 0 and current_slab.from_year == 0 and len(self.gratuity_rule_slabs) > 1:
|
||||||
frappe.throw(_("You can not define multiple slabs if you have a slab with no lower and upper limits."))
|
frappe.throw(_("You can not define multiple slabs if you have a slab with no lower and upper limits."))
|
||||||
|
|
||||||
|
def get_gratuity_rule(name, slabs, **args):
|
||||||
|
args = frappe._dict(args)
|
||||||
|
|
||||||
|
rule = frappe.new_doc("Gratuity Rule")
|
||||||
|
rule.name = name
|
||||||
|
rule.calculate_gratuity_amount_based_on = args.calculate_gratuity_amount_based_on or "Current Slab"
|
||||||
|
rule.work_experience_calculation_method = args.work_experience_calculation_method or "Take Exact Completed Years"
|
||||||
|
rule.minimum_year_for_gratuity = 1
|
||||||
|
|
||||||
|
|
||||||
|
for slab in slabs:
|
||||||
|
slab = frappe._dict(slab)
|
||||||
|
rule.append("gratuity_rule_slabs", slab)
|
||||||
|
return rule
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import frappe, os, json
|
|||||||
from frappe.custom.doctype.custom_field.custom_field import create_custom_fields
|
from frappe.custom.doctype.custom_field.custom_field import create_custom_fields
|
||||||
from frappe.permissions import add_permission, update_permission_property
|
from frappe.permissions import add_permission, update_permission_property
|
||||||
from erpnext.setup.setup_wizard.operations.taxes_setup import create_sales_tax
|
from erpnext.setup.setup_wizard.operations.taxes_setup import create_sales_tax
|
||||||
|
from erpnext.payroll.doctype.gratuity_rule.gratuity_rule import get_gratuity_rule
|
||||||
|
|
||||||
def setup(company=None, patch=True):
|
def setup(company=None, patch=True):
|
||||||
make_custom_fields()
|
make_custom_fields()
|
||||||
@@ -161,104 +162,91 @@ def add_permissions():
|
|||||||
update_permission_property(doctype, role, 0, 'create', 1)
|
update_permission_property(doctype, role, 0, 'create', 1)
|
||||||
|
|
||||||
def create_gratuity_rule():
|
def create_gratuity_rule():
|
||||||
|
rule_1 = rule_2 = rule_3 = None
|
||||||
# Standard Gratuity Rules for UAE
|
|
||||||
|
|
||||||
# Rule Under Limited Contract
|
# Rule Under Limited Contract
|
||||||
|
slabs = get_slab_for_limited_contract()
|
||||||
if not frappe.db.exists("Gratuity Rule", "Rule Under Limited Contract (UAE)"):
|
if not frappe.db.exists("Gratuity Rule", "Rule Under Limited Contract (UAE)"):
|
||||||
rule_1 = frappe.new_doc("Gratuity Rule")
|
rule_1 = get_gratuity_rule("Rule Under Limited Contract (UAE)", slabs, calculate_gratuity_amount_based_on="Sum of all previous slabs")
|
||||||
rule_1.name = "Rule Under Limited Contract (UAE)"
|
|
||||||
rule_1.calculate_gratuity_amount_based_on = "Sum of all previous slabs"
|
|
||||||
rule_1.work_experience_calculation_method = "Take Exact Completed Years"
|
|
||||||
rule_1.minimum_year_for_gratuity = 1
|
|
||||||
|
|
||||||
rule_1.append("gratuity_rule_slabs", {
|
|
||||||
"from_year": 0,
|
|
||||||
"to_year":1,
|
|
||||||
"fraction_of_applicable_earnings": 0
|
|
||||||
})
|
|
||||||
|
|
||||||
rule_1.append("gratuity_rule_slabs", {
|
|
||||||
"from_year": 1,
|
|
||||||
"to_year":5,
|
|
||||||
"fraction_of_applicable_earnings": 21/30
|
|
||||||
})
|
|
||||||
|
|
||||||
rule_1.append("gratuity_rule_slabs", {
|
|
||||||
"from_year": 5,
|
|
||||||
"to_year":0,
|
|
||||||
"fraction_of_applicable_earnings": 1
|
|
||||||
})
|
|
||||||
|
|
||||||
# Rule Under Unlimited Contract on termination
|
# Rule Under Unlimited Contract on termination
|
||||||
|
slabs = get_slab_for_unlimited_contract_on_termination()
|
||||||
if not frappe.db.exists("Gratuity Rule", "Rule Under Unlimited Contract on termination (UAE)"):
|
if not frappe.db.exists("Gratuity Rule", "Rule Under Unlimited Contract on termination (UAE)"):
|
||||||
rule_2 = frappe.new_doc("Gratuity Rule")
|
rule_2 = get_gratuity_rule("Rule Under Unlimited Contract on termination (UAE)", slabs)
|
||||||
rule_2.name = "Rule Under Unlimited Contract on termination (UAE)"
|
|
||||||
rule_2.calculate_gratuity_amount_based_on = "Current Slab"
|
|
||||||
rule_2.work_experience_calculation_method = "Take Exact Completed Years"
|
|
||||||
rule_2.minimum_year_for_gratuity = 1
|
|
||||||
|
|
||||||
rule_2.append("gratuity_rule_slabs", {
|
# Rule Under Unlimited Contract on resignation
|
||||||
"from_year": 0,
|
slabs = get_slab_for_unlimited_contract_on_resignation()
|
||||||
"to_year":1,
|
|
||||||
"fraction_of_applicable_earnings": 0
|
|
||||||
})
|
|
||||||
|
|
||||||
rule_2.append("gratuity_rule_slabs", {
|
|
||||||
"from_year": 1,
|
|
||||||
"to_year":5,
|
|
||||||
"fraction_of_applicable_earnings": 21/30
|
|
||||||
})
|
|
||||||
|
|
||||||
rule_2.append("gratuity_rule_slabs", {
|
|
||||||
"from_year": 5,
|
|
||||||
"to_year":0,
|
|
||||||
"fraction_of_applicable_earnings": 1
|
|
||||||
})
|
|
||||||
|
|
||||||
# Rule Under Unlimited Contract
|
|
||||||
if not frappe.db.exists("Gratuity Rule", "Rule Under Unlimited Contract on resignation (UAE)"):
|
if not frappe.db.exists("Gratuity Rule", "Rule Under Unlimited Contract on resignation (UAE)"):
|
||||||
rule_3 = frappe.new_doc("Gratuity Rule")
|
rule_3 = get_gratuity_rule("Rule Under Unlimited Contract on resignation (UAE)", slabs)
|
||||||
rule_3.name = "Rule Under Unlimited Contract on resignation (UAE)"
|
|
||||||
rule_3.calculate_gratuity_amount_based_on = "Current Slab"
|
|
||||||
rule_3.work_experience_calculation_method = "Take Exact Completed Years"
|
|
||||||
rule_3.minimum_year_for_gratuity = 1
|
|
||||||
|
|
||||||
rule_3.append("gratuity_rule_slabs", {
|
#for applicable salary component user need to set this by its own
|
||||||
"from_year": 0,
|
if rule_1:
|
||||||
"to_year":1,
|
|
||||||
"fraction_of_applicable_earnings": 0
|
|
||||||
})
|
|
||||||
|
|
||||||
fraction_of_applicable_earnings = 1/3 * 21/30
|
|
||||||
rule_3.append("gratuity_rule_slabs", {
|
|
||||||
"from_year": 1,
|
|
||||||
"to_year":3,
|
|
||||||
"fraction_of_applicable_earnings": fraction_of_applicable_earnings
|
|
||||||
})
|
|
||||||
|
|
||||||
fraction_of_applicable_earnings = 2/3 * 21/30
|
|
||||||
rule_3.append("gratuity_rule_slabs", {
|
|
||||||
"from_year": 3,
|
|
||||||
"to_year":5,
|
|
||||||
"fraction_of_applicable_earnings": fraction_of_applicable_earnings
|
|
||||||
})
|
|
||||||
|
|
||||||
fraction_of_applicable_earnings = 21/30
|
|
||||||
rule_3.append("gratuity_rule_slabs", {
|
|
||||||
"from_year": 5,
|
|
||||||
"to_year":0,
|
|
||||||
"fraction_of_applicable_earnings": fraction_of_applicable_earnings
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
#for applicable salary component user need to set this by its own
|
|
||||||
rule_1.flags.ignore_mandatory = True
|
rule_1.flags.ignore_mandatory = True
|
||||||
rule_2.flags.ignore_mandatory = True
|
|
||||||
rule_3.flags.ignore_mandatory = True
|
|
||||||
|
|
||||||
rule_1.save()
|
rule_1.save()
|
||||||
|
if rule_2:
|
||||||
|
rule_2.flags.ignore_mandatory = True
|
||||||
rule_2.save()
|
rule_2.save()
|
||||||
|
if rule_3:
|
||||||
|
rule_3.flags.ignore_mandatory = True
|
||||||
rule_3.save()
|
rule_3.save()
|
||||||
|
|
||||||
|
|
||||||
|
def get_slab_for_limited_contract():
|
||||||
|
return [{
|
||||||
|
"from_year": 0,
|
||||||
|
"to_year":1,
|
||||||
|
"fraction_of_applicable_earnings": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"from_year": 1,
|
||||||
|
"to_year":5,
|
||||||
|
"fraction_of_applicable_earnings": 21/30
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"from_year": 5,
|
||||||
|
"to_year":0,
|
||||||
|
"fraction_of_applicable_earnings": 1
|
||||||
|
}]
|
||||||
|
|
||||||
|
def get_slab_for_unlimited_contract_on_termination():
|
||||||
|
return [{
|
||||||
|
"from_year": 0,
|
||||||
|
"to_year":1,
|
||||||
|
"fraction_of_applicable_earnings": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"from_year": 1,
|
||||||
|
"to_year":5,
|
||||||
|
"fraction_of_applicable_earnings": 21/30
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"from_year": 5,
|
||||||
|
"to_year":0,
|
||||||
|
"fraction_of_applicable_earnings": 1
|
||||||
|
}]
|
||||||
|
|
||||||
|
def get_slab_for_unlimited_contract_on_resignation():
|
||||||
|
fraction_1 = 1/3 * 21/30
|
||||||
|
fraction_2 = 2/3 * 21/30
|
||||||
|
fraction_3 = 21/30
|
||||||
|
|
||||||
|
return [{
|
||||||
|
"from_year": 0,
|
||||||
|
"to_year":1,
|
||||||
|
"fraction_of_applicable_earnings": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"from_year": 1,
|
||||||
|
"to_year":3,
|
||||||
|
"fraction_of_applicable_earnings": fraction_1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"from_year": 3,
|
||||||
|
"to_year":5,
|
||||||
|
"fraction_of_applicable_earnings": fraction_2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"from_year": 5,
|
||||||
|
"to_year":0,
|
||||||
|
"fraction_of_applicable_earnings": fraction_3
|
||||||
|
}]
|
||||||
|
|||||||
Reference in New Issue
Block a user