Skip to content

Commit

Permalink
fix: Added regional setups
Browse files Browse the repository at this point in the history
- Added regional reports Provident Fund Deductions and Professional Tax Deductions

- Added helper js file `salary_slip_deductions_report_filters.js`

- Added custom field setups and gratuity rules setups for UAE and India

- Hook for setting up company fixtures and regional setups on company update if country has changed
  • Loading branch information
ruchamahabal committed Jun 27, 2022
1 parent 6f9ef74 commit 7f6a194
Show file tree
Hide file tree
Showing 18 changed files with 854 additions and 34 deletions.
4 changes: 4 additions & 0 deletions hrms/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
app_description = "Modern HR and Payroll Software"
app_email = "contact@frappe.io"
app_license = "GNU General Public License (v3)"
required_apps = ["erpnext"]


# Includes in <head>
Expand Down Expand Up @@ -123,6 +124,9 @@
"validate": "erpnext.setup.doctype.employee.employee.validate_employee_role",
"on_update": "erpnext.setup.doctype.employee.employee.update_user_permissions",
},
"Company": {
"on_update": "hrms.overrides.company.make_company_fixtures",
},
"Timesheet": {"validate": "hrms.hr.utils.validate_active_employee"},
"Payment Entry": {
"on_submit": "hrms.hr.doctype.expense_claim.expense_claim.update_payment_for_expense_claim",
Expand Down
61 changes: 61 additions & 0 deletions hrms/overrides/company.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt

import json

import frappe
from frappe import _


def make_company_fixtures(doc, method=None):
if not frappe.flags.country_change:
return

run_regional_setup(doc.company, doc.country)
make_salary_components(doc.country)


def run_regional_setup(company, country):
company = company or frappe.db.get_value("Global Defaults", None, "default_company")

try:
module_name = f"hrms.regional.{frappe.scrub(country)}.setup.setup"
frappe.get_attr(module_name)(company, False)
except ImportError:
pass
except Exception:
frappe.log_error("Unable to setup country fixtures for HRMS")
frappe.throw(
_("Failed to setup defaults for country {0}. Please contact support.").format(
frappe.bold(country)
)
)


def make_salary_components(country):
docs = []

file_name = "salary_components.json"
file_path = frappe.get_app_path("hrms", "payroll", "data", file_name)
docs.extend(json.loads(read_data_file(file_path)))

file_path = frappe.get_app_path("hrms", "regional", frappe.scrub(country), "data", file_name)
docs.extend(json.loads(read_data_file(file_path)))

for d in docs:
try:
doc = frappe.get_doc(d)
doc.flags.ignore_permissions = True
doc.insert(ignore_if_duplicate=True)
except frappe.NameError:
frappe.clear_messages()
except frappe.DuplicateEntryError:
frappe.clear_messages()


def read_data_file(file_path):
try:
with open(file_path, "r") as f:
return f.read()
except IOError:
return "{}"
27 changes: 27 additions & 0 deletions hrms/payroll/data/salary_components.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[
{
"doctype": "Salary Component",
"salary_component": "Income Tax",
"description": "Income Tax",
"type": "Deduction",
"is_income_tax_component": 1
},
{
"doctype": "Salary Component",
"salary_component": "Basic",
"description": "Basic",
"type": "Earning"
},
{
"doctype": "Salary Component",
"salary_component": "Arrear",
"description": "Arrear",
"type": "Earning"
},
{
"doctype": "Salary Component",
"salary_component": "Leave Encashment",
"description": "Leave Encashment",
"type": "Earning"
}
]
4 changes: 2 additions & 2 deletions hrms/payroll/doctype/gratuity/test_gratuity.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import unittest

import frappe
from erpnext.regional.united_arab_emirates.setup import create_gratuity_rule
from erpnext.setup.doctype.employee.test_employee import make_employee
from erpnext.setup.doctype.holiday_list.test_holiday_list import set_holiday_list
from frappe.tests.utils import FrappeTestCase
Expand All @@ -19,6 +18,7 @@
make_holiday_list,
)
from hrms.payroll.doctype.salary_structure.salary_structure import make_salary_slip
from hrms.regional.united_arab_emirates.setup import setup

test_dependencies = ["Salary Component", "Salary Slip", "Account"]

Expand Down Expand Up @@ -156,7 +156,7 @@ def test_gratuity_based_on_all_previous_slabs_via_payment_entry(self):
def get_gratuity_rule(name):
rule = frappe.db.exists("Gratuity Rule", name)
if not rule:
create_gratuity_rule()
setup()
rule = frappe.get_doc("Gratuity Rule", name)
rule.applicable_earnings_component = []
rule.append("applicable_earnings_component", {"salary_component": "Basic Salary"})
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors
// For license information, please see license.txt
/* eslint-disable */

frappe.require("assets/hrms/js/salary_slip_deductions_report_filters.js", function() {
frappe.query_reports["Professional Tax Deductions"] = hrms.salary_slip_deductions_report_filters;
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"add_total_row": 0,
"creation": "2020-06-02 00:37:44.537355",
"disable_prepared_report": 0,
"disabled": 0,
"docstatus": 0,
"doctype": "Report",
"idx": 0,
"is_standard": "Yes",
"modified": "2022-06-26 19:02:26.306348",
"modified_by": "Administrator",
"module": "Payroll",
"name": "Professional Tax Deductions",
"owner": "Administrator",
"prepared_report": 0,
"ref_doctype": "Salary Slip",
"report_name": "Professional Tax Deductions",
"report_type": "Script Report",
"roles": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Copyright (c) 2013, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt


import frappe
from frappe import _

from hrms.payroll.report.provident_fund_deductions.provident_fund_deductions import get_conditions


def execute(filters=None):
data = get_data(filters)
columns = get_columns(filters) if len(data) else []

return columns, data


def get_columns(filters):
columns = [
{
"label": _("Employee"),
"options": "Employee",
"fieldname": "employee",
"fieldtype": "Link",
"width": 200,
},
{
"label": _("Employee Name"),
"options": "Employee",
"fieldname": "employee_name",
"fieldtype": "Link",
"width": 160,
},
{"label": _("Amount"), "fieldname": "amount", "fieldtype": "Currency", "width": 140},
]

return columns


def get_data(filters):

data = []

component_type_dict = frappe._dict(
frappe.db.sql(
""" select name, component_type from `tabSalary Component`
where component_type = 'Professional Tax' """
)
)

if not len(component_type_dict):
return []

conditions = get_conditions(filters)

entry = frappe.db.sql(
""" select sal.employee, sal.employee_name, ded.salary_component, ded.amount
from `tabSalary Slip` sal, `tabSalary Detail` ded
where sal.name = ded.parent
and ded.parentfield = 'deductions'
and ded.parenttype = 'Salary Slip'
and sal.docstatus = 1 %s
and ded.salary_component in (%s)
"""
% (conditions, ", ".join(["%s"] * len(component_type_dict))),
tuple(component_type_dict.keys()),
as_dict=1,
)

for d in entry:

employee = {"employee": d.employee, "employee_name": d.employee_name, "amount": d.amount}

data.append(employee)

return data
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors
// For license information, please see license.txt
/* eslint-disable */

frappe.require("assets/hrms/js/salary_slip_deductions_report_filters.js", function() {
frappe.query_reports["Provident Fund Deductions"] = hrms.salary_slip_deductions_report_filters;
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"add_total_row": 0,
"creation": "2020-06-01 23:44:07.919117",
"disable_prepared_report": 0,
"disabled": 0,
"docstatus": 0,
"doctype": "Report",
"idx": 0,
"is_standard": "Yes",
"modified": "2022-06-26 18:54:19.305763",
"modified_by": "Administrator",
"module": "Payroll",
"name": "Provident Fund Deductions",
"owner": "Administrator",
"prepared_report": 0,
"ref_doctype": "Salary Slip",
"report_name": "Provident Fund Deductions",
"report_type": "Script Report",
"roles": []
}

0 comments on commit 7f6a194

Please sign in to comment.