Fix: Changes Requested, Sider, codacy, Transalation

This commit is contained in:
Anurag Mishra 2020-10-27 14:42:55 +05:30
parent 493eea19e8
commit 4d6c3c9449
7 changed files with 103 additions and 69 deletions

View File

@ -9,10 +9,9 @@ def execute():
frappe.reload_doc('payroll', 'doctype', 'gratuity_rule') frappe.reload_doc('payroll', 'doctype', 'gratuity_rule')
frappe.reload_doc('payroll', 'doctype', 'gratuity_rule_slab') frappe.reload_doc('payroll', 'doctype', 'gratuity_rule_slab')
frappe.reload_doc('payroll', 'doctype', 'gratuity_applicable_component') frappe.reload_doc('payroll', 'doctype', 'gratuity_applicable_component')
region = erpnext.get_region() if frappe.db.exists("company", {"country": "India"}):
if region == "India":
from erpnext.regional.india.setup import create_gratuity_rule from erpnext.regional.india.setup import create_gratuity_rule
create_gratuity_rule() create_gratuity_rule()
elif region == "United Arab Emirates": if frappe.db.exists("company", {"country": "United Arab Emirates"}):
from erpnext.regional.united_arab_emirates.setup import create_gratuity_rule from erpnext.regional.united_arab_emirates.setup import create_gratuity_rule
create_gratuity_rule() create_gratuity_rule()

View File

@ -2,24 +2,7 @@
// For license information, please see license.txt // For license information, please see license.txt
frappe.ui.form.on('Gratuity', { frappe.ui.form.on('Gratuity', {
refresh: function(frm){ setup: function(frm){
if(frm.doc.docstatus === 1 && frm.doc.pay_via_salary_slip === 0 && frm.doc.status === "Unpaid") {
frm.add_custom_button(__("Make Payment Entry"), function() {
return frappe.call({
method: 'erpnext.accounts.doctype.payment_entry.payment_entry.get_payment_entry',
args: {
"dt": cur_frm.doc.doctype,
"dn": cur_frm.doc.name
},
callback: function(r) {
var doclist = frappe.model.sync(r.message);
frappe.set_route("Form", doclist[0].doctype, doclist[0].name);
}
});
});
}
},
onload: function(frm){
frm.set_query('salary_component', function() { frm.set_query('salary_component', function() {
return { return {
filters: { filters: {
@ -30,13 +13,30 @@ frappe.ui.form.on('Gratuity', {
frm.set_query("expense_account", function() { frm.set_query("expense_account", function() {
return { return {
filters: { filters: {
"root_type": "Asset", "root_type": "Expense",
"is_group": 0, "is_group": 0,
"company": frm.doc.company "company": frm.doc.company
} }
}; };
}); });
}, },
refresh: function(frm){
if(frm.doc.docstatus === 1 && frm.doc.pay_via_salary_slip === 0 && frm.doc.status === "Unpaid") {
frm.add_custom_button(__("Create Payment Entry"), function() {
return frappe.call({
method: 'erpnext.accounts.doctype.payment_entry.payment_entry.get_payment_entry',
args: {
"dt": frm.doc.doctype,
"dn": frm.doc.name
},
callback: function(r) {
var doclist = frappe.model.sync(r.message);
frappe.set_route("Form", doclist[0].doctype, doclist[0].name);
}
});
});
}
},
employee: function(frm) { employee: function(frm) {
frm.events.calculate_work_experience_and_amount(frm); frm.events.calculate_work_experience_and_amount(frm);
}, },

View File

@ -175,9 +175,10 @@
"read_only": 1 "read_only": 1
} }
], ],
"index_web_pages_for_search": 1,
"is_submittable": 1, "is_submittable": 1,
"links": [], "links": [],
"modified": "2020-08-14 11:59:15.499548", "modified": "2020-10-27 14:04:41.886934",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Payroll", "module": "Payroll",
"name": "Gratuity", "name": "Gratuity",
@ -191,7 +192,19 @@
"print": 1, "print": 1,
"read": 1, "read": 1,
"report": 1, "report": 1,
"role": "System Manager", "role": "HR Manager",
"share": 1,
"write": 1
},
{
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "HR User",
"share": 1, "share": 1,
"write": 1 "write": 1
} }

View File

@ -9,7 +9,6 @@ from frappe.model.document import Document
from frappe.utils import flt, get_datetime, get_link_to_form from frappe.utils import flt, get_datetime, get_link_to_form
from math import floor from math import floor
from frappe.utils import get_datetime
class Gratuity(Document): class Gratuity(Document):
def validate(self): def validate(self):
data = calculate_work_experience_and_amount(self.employee, self.gratuity_rule) data = calculate_work_experience_and_amount(self.employee, self.gratuity_rule)
@ -22,6 +21,9 @@ class Gratuity(Document):
self.status = "Paid" self.status = "Paid"
def on_submit(self): def on_submit(self):
create_additional_salary()
def create_additional_salary(self):
if self.pay_via_salary_slip: if self.pay_via_salary_slip:
additional_salary = frappe.new_doc('Additional Salary') additional_salary = frappe.new_doc('Additional Salary')
additional_salary.employee = self.employee additional_salary.employee = self.employee
@ -170,7 +172,7 @@ def get_total_applicable_component_amount(employee, applicable_earnings_componen
fields=["amount"]) fields=["amount"])
total_applicable_components_amount = 0 total_applicable_components_amount = 0
if not len(component_and_amounts): if not len(component_and_amounts):
frappe.throw("No Applicable Component is present in last month salary slip") frappe.throw(_("No Applicable Component is present in last month salary slip"))
for data in component_and_amounts: for data in component_and_amounts:
total_applicable_components_amount += data.amount total_applicable_components_amount += data.amount
@ -180,10 +182,17 @@ def get_gratuity_rule_slabs(gratuity_rule):
return frappe.get_all("Gratuity Rule Slab", filters= {'parent': gratuity_rule}, fields = ["*"], order_by="idx") return frappe.get_all("Gratuity Rule Slab", filters= {'parent': gratuity_rule}, fields = ["*"], order_by="idx")
def get_salary_structure(employee): def get_salary_structure(employee):
return frappe.get_list("Salary Structure Assignment", filters = {"employee": employee, 'docstatus': 1}, fields=["from_date", "salary_structure"], order_by = "from_date desc")[0].salary_structure return frappe.get_list("Salary Structure Assignment", filters = {
"employee": employee, 'docstatus': 1
},
fields=["from_date", "salary_structure"],
order_by = "from_date desc")[0].salary_structure
def get_last_salary_slip(employee): def get_last_salary_slip(employee):
return frappe.get_list("Salary Slip", filters = {"employee": employee, 'docstatus': 1}, order_by = "start_date desc")[0].name return frappe.get_list("Salary Slip", filters = {
"employee": employee, 'docstatus': 1
},
order_by = "start_date desc")[0].name

View File

@ -13,12 +13,10 @@ from frappe.utils import getdate, add_days, get_datetime, flt
class TestGratuity(unittest.TestCase): class TestGratuity(unittest.TestCase):
def setUp(self): def setUp(self):
frappe.db.sql("DELETE FROM `tabgratuity`") frappe.db.sql("DELETE FROM `tabgratuity`")
frappe.db.sql("DELETE FROM `tabAdditional Salary` WHERE ref_doctype = 'Gratuity'") frappe.db.sql("DELETE FROM `tabAdditional Salary` WHERE ref_doctype = 'Gratuity'")
def test_check_gratuity_amount_based_on_current_slab_and_additional_salary_creation(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 = frappe.db.exists("Gratuity Rule", "Rule Under Unlimited Contract on termination (UAE)") rule = frappe.db.exists("Gratuity Rule", "Rule Under Unlimited Contract on termination (UAE)")
@ -33,15 +31,15 @@ class TestGratuity(unittest.TestCase):
rule.save() rule.save()
rule.reload() rule.reload()
gra = frappe.new_doc("Gratuity") gratuity = frappe.new_doc("Gratuity")
gra.employee = employee gratuity.employee = employee
gra.posting_date = getdate() gratuity.posting_date = getdate()
gra.gratuity_rule = rule.name gratuity.gratuity_rule = rule.name
gra.pay_via_salary_slip = 1 gratuity.pay_via_salary_slip = 1
gra.salary_component = "Performance Bonus" gratuity.salary_component = "Performance Bonus"
gra.payroll_date = getdate() gratuity.payroll_date = getdate()
gra.save() gratuity.save()
gra.submit() gratuity.submit()
#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'])
@ -49,11 +47,11 @@ class TestGratuity(unittest.TestCase):
experience = employee_total_workings_days/rule.total_working_days_per_year experience = employee_total_workings_days/rule.total_working_days_per_year
gra.reload() gratuity.reload()
from math import floor from math import floor
self.assertEqual(floor(experience), gra.current_work_experience) self.assertEqual(floor(experience), gratuity.current_work_experience)
#amount Calculation 6 #amount Calculation 6
component_amount = frappe.get_list("Salary Detail", component_amount = frappe.get_list("Salary Detail",
@ -68,15 +66,13 @@ class TestGratuity(unittest.TestCase):
''' 5 - 0 fraction is 1 ''' ''' 5 - 0 fraction is 1 '''
gratuity_amount = component_amount[0].amount * experience gratuity_amount = component_amount[0].amount * experience
gra.reload() gratuity.reload()
self.assertEqual(flt(gratuity_amount, 2), flt(gra.amount, 2)) self.assertEqual(flt(gratuity_amount, 2), flt(gratuity.amount, 2))
#additional salary creation (Pay via salary slip) #additional salary creation (Pay via salary slip)
self.assertTrue(frappe.db.exists("Additional Salary", {"ref_docname": gra.name})) self.assertTrue(frappe.db.exists("Additional Salary", {"ref_docname": gratuity.name}))
self.assertEqual(gra.status, "Paid") self.assertEqual(gratuity.status, "Paid")
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()
@ -102,17 +98,17 @@ class TestGratuity(unittest.TestCase):
mof.save() mof.save()
gra = frappe.new_doc("Gratuity") gratuity = frappe.new_doc("Gratuity")
gra.employee = employee gratuity.employee = employee
gra.posting_date = getdate() gratuity.posting_date = getdate()
gra.gratuity_rule = rule.name gratuity.gratuity_rule = rule.name
gra.pay_via_salary_slip = 0 gratuity.pay_via_salary_slip = 0
gra.payroll_date = getdate() gratuity.payroll_date = getdate()
gra.expense_account = "Payment Account - _TC" gratuity.expense_account = "Payment Account - _TC"
gra.mode_of_payment = "Cheque" gratuity.mode_of_payment = "Cheque"
gra.save() gratuity.save()
gra.submit() gratuity.submit()
#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'])
@ -120,11 +116,11 @@ class TestGratuity(unittest.TestCase):
experience = employee_total_workings_days/rule.total_working_days_per_year experience = employee_total_workings_days/rule.total_working_days_per_year
gra.reload() gratuity.reload()
from math import floor from math import floor
self.assertEqual(floor(experience), gra.current_work_experience) self.assertEqual(floor(experience), gratuity.current_work_experience)
#amount Calculation 6 #amount Calculation 6
component_amount = frappe.get_list("Salary Detail", component_amount = frappe.get_list("Salary Detail",
@ -145,25 +141,29 @@ class TestGratuity(unittest.TestCase):
gratuity_amount = ((0 * 1) + (4 * 0.7) + (1 * 1)) * component_amount[0].amount gratuity_amount = ((0 * 1) + (4 * 0.7) + (1 * 1)) * component_amount[0].amount
gra.reload() gratuity.reload()
self.assertEqual(flt(gratuity_amount, 2), flt(gra.amount, 2)) self.assertEqual(flt(gratuity_amount, 2), flt(gratuity.amount, 2))
self.assertEqual(gra.status, "Unpaid") self.assertEqual(gratuity.status, "Unpaid")
from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry
pay_entry = get_payment_entry("Gratuity", gra.name) pay_entry = get_payment_entry("Gratuity", gratuity.name)
pay_entry.reference_no = "123467" pay_entry.reference_no = "123467"
pay_entry.reference_date = getdate() pay_entry.reference_date = getdate()
pay_entry.save() pay_entry.save()
pay_entry.submit() pay_entry.submit()
gra.reload() gratuity.reload()
self.assertEqual(gra.status, "Paid") self.assertEqual(gratuity.status, "Paid")
self.assertEqual(gra.paid_amount, flt(gra.amount, 2)) self.assertEqual(gratuity.paid_amount, flt(gratuity.amount, 2))
def tearDown(self):
frappe.db.sql("DELETE FROM `tabgratuity`")
frappe.db.sql("DELETE FROM `tabAdditional Salary` WHERE ref_doctype = 'Gratuity'")
def create_employee_and_get_last_salary_slip(): def create_employee_and_get_last_salary_slip():
employee = make_employee("test_employee@salary.com") employee = make_employee("test_employee@salary.com")

View File

@ -25,7 +25,7 @@ frappe.ui.form.on('Gratuity Rule Slab', {
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;
if(array_idx > 0){ if(array_idx > 0){
row.from_year = cur_frm.doc.gratuity_rule_slabs[array_idx-1].to_year; row.from_year = cur_frm.doc.gratuity_rule_slabs[array_idx-1].to_year;
frm.refresh(); frm.refresh();

View File

@ -75,8 +75,9 @@
"label": "Minimum Year for Gratuity" "label": "Minimum Year for Gratuity"
} }
], ],
"index_web_pages_for_search": 1,
"links": [], "links": [],
"modified": "2020-08-17 14:17:02.594665", "modified": "2020-10-27 14:04:31.617621",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Payroll", "module": "Payroll",
"name": "Gratuity Rule", "name": "Gratuity Rule",
@ -90,7 +91,19 @@
"print": 1, "print": 1,
"read": 1, "read": 1,
"report": 1, "report": 1,
"role": "All", "role": "HR Manager",
"share": 1,
"write": 1
},
{
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "HR User",
"share": 1, "share": 1,
"write": 1 "write": 1
} }