Skip to content

Commit

Permalink
Merge pull request #477 from saurabh6790/timesheet-based-payroll
Browse files Browse the repository at this point in the history
fix: do not hide payroll frequency if its based on timesheet
  • Loading branch information
saurabh6790 authored Jun 15, 2023
2 parents afd70a3 + 9f4b219 commit 471287f
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 20 deletions.
3 changes: 2 additions & 1 deletion hrms/patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ hrms.patches.post_install.set_payroll_entry_status
hrms.patches.v1_0.rearrange_employee_fields
hrms.patches.post_install.update_allocate_on_in_leave_type
hrms.patches.v14_0.create_custom_field_for_appraisal_template
hrms.patches.post_install.update_performance_module_changes #2023-04-17
hrms.patches.post_install.update_performance_module_changes #2023-04-17
hrms.patches.v14_0.update_payroll_frequency_to_none_if_salary_slip_is_based_on_timesheet
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import frappe


def execute():
frappe.reload_doc("payroll", "doctype", "salary_structure")

salary_strucutres = frappe.get_all(
"Salary Structure", filters={"salary_slip_based_on_timesheet": 1}, fields=["name"]
)

if len(salary_strucutres) > 0:
for salary_strucutre in salary_strucutres:
frappe.db.set_value("Salary Structure", salary_strucutre.name, "payroll_frequency", "")
4 changes: 2 additions & 2 deletions hrms/payroll/doctype/payroll_entry/payroll_entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,9 @@ frappe.ui.form.on('Payroll Entry', {

get_employee_filters: function (frm) {
let filters = {};
filters['salary_slip_based_on_timesheet'] = frm.doc.salary_slip_based_on_timesheet;

let fields = ['company', 'start_date', 'end_date', 'payroll_frequency', 'payroll_payable_account',
'currency', 'department', 'branch', 'designation'];
'currency', 'department', 'branch', 'designation', 'salary_slip_based_on_timesheet'];

fields.forEach(field => {
if (frm.doc[field]) {
Expand Down Expand Up @@ -308,6 +307,7 @@ frappe.ui.form.on('Payroll Entry', {

salary_slip_based_on_timesheet: function (frm) {
frm.toggle_reqd(['payroll_frequency'], !frm.doc.salary_slip_based_on_timesheet);
hrms.set_payroll_frequency_to_null(frm);
},

set_start_end_dates: function (frm) {
Expand Down
6 changes: 3 additions & 3 deletions hrms/payroll/doctype/payroll_entry/payroll_entry.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@
"field_order": [
"select_payroll_period",
"posting_date",
"payroll_frequency",
"company",
"column_break_5",
"currency",
"exchange_rate",
"payroll_payable_account",
"status",
"section_break_cypo",
"salary_slip_based_on_timesheet",
"payroll_frequency",
"start_date",
"end_date",
"column_break_13",
"salary_slip_based_on_timesheet",
"deduct_tax_for_unclaimed_employee_benefits",
"deduct_tax_for_unsubmitted_tax_exemption_proof",
"employees_tab",
Expand Down Expand Up @@ -329,7 +329,7 @@
"icon": "fa fa-cog",
"is_submittable": 1,
"links": [],
"modified": "2023-01-05 17:07:00.372983",
"modified": "2023-05-26 17:03:51.264095",
"modified_by": "Administrator",
"module": "Payroll",
"name": "Payroll Entry",
Expand Down
23 changes: 16 additions & 7 deletions hrms/payroll/doctype/payroll_entry/payroll_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,23 @@ def on_cancel(self):
self.db_set("error_message", "")

def make_filters(self):
return frappe._dict(
filters = frappe._dict(
company=self.company,
branch=self.branch,
department=self.department,
designation=self.designation,
currency=self.currency,
payroll_frequency=self.payroll_frequency,
start_date=self.start_date,
end_date=self.end_date,
payroll_payable_account=self.payroll_payable_account,
salary_slip_based_on_timesheet=self.salary_slip_based_on_timesheet,
)

if not self.salary_slip_based_on_timesheet:
filters.update(dict(payroll_frequency=self.payroll_frequency))

return filters

@frappe.whitelist()
def fill_employee_details(self):
filters = self.make_filters()
Expand Down Expand Up @@ -919,11 +923,12 @@ def get_holiday_list_based_count(
return holiday_list_based_count[key] or 0


def get_sal_struct(
def get_salary_structure(
company: str, currency: str, salary_slip_based_on_timesheet: int, payroll_frequency: str
) -> list[str]:
SalaryStructure = frappe.qb.DocType("Salary Structure")
return (

query = (
frappe.qb.from_(SalaryStructure)
.select(SalaryStructure.name)
.where(
Expand All @@ -932,9 +937,13 @@ def get_sal_struct(
& (SalaryStructure.company == company)
& (SalaryStructure.currency == currency)
& (SalaryStructure.salary_slip_based_on_timesheet == salary_slip_based_on_timesheet)
& (SalaryStructure.payroll_frequency == payroll_frequency)
)
).run(pluck=True)
)

if not salary_slip_based_on_timesheet:
query = query.where(SalaryStructure.payroll_frequency == payroll_frequency)

return query.run(pluck=True)


def get_filtered_employees(
Expand Down Expand Up @@ -1322,7 +1331,7 @@ def get_employee_list(
offset=None,
ignore_match_conditions=False,
) -> list:
sal_struct = get_sal_struct(
sal_struct = get_salary_structure(
filters.company,
filters.currency,
filters.salary_slip_based_on_timesheet,
Expand Down
3 changes: 1 addition & 2 deletions hrms/payroll/doctype/salary_slip/salary_slip.json
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@
"search_index": 1
},
{
"depends_on": "eval:(!doc.salary_slip_based_on_timesheet)",
"fieldname": "payroll_frequency",
"fieldtype": "Select",
"label": "Payroll Frequency",
Expand Down Expand Up @@ -753,7 +752,7 @@
"idx": 9,
"is_submittable": 1,
"links": [],
"modified": "2023-02-22 18:23:49.783449",
"modified": "2023-04-26 17:29:49.079158",
"modified_by": "Administrator",
"module": "Payroll",
"name": "Salary Slip",
Expand Down
4 changes: 3 additions & 1 deletion hrms/payroll/doctype/salary_structure/salary_structure.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ frappe.ui.form.on('Salary Structure', {
},

salary_slip_based_on_timesheet: function(frm) {
frm.trigger("toggle_fields")
frm.trigger("toggle_fields");
hrms.set_payroll_frequency_to_null(frm);

},

preview_salary_slip: function(frm) {
Expand Down
9 changes: 5 additions & 4 deletions hrms/payroll/doctype/salary_structure/salary_structure.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
"column_break1",
"is_active",
"is_default",
"payroll_frequency",
"currency",
"amended_from",
"time_sheet_earning_detail",
"leave_encashment_amount_per_day",
"max_benefits",
"column_break_17",
"salary_slip_based_on_timesheet",
"payroll_frequency",
"salary_component",
"hour_rate",
"earning_deduction",
Expand Down Expand Up @@ -73,7 +73,7 @@
},
{
"default": "Monthly",
"depends_on": "eval:(!doc.salary_slip_based_on_timesheet)",
"depends_on": "eval:doc.salary_slip_based_on_timesheet == 0",
"fieldname": "payroll_frequency",
"fieldtype": "Select",
"label": "Payroll Frequency",
Expand All @@ -99,7 +99,8 @@
"default": "0",
"fieldname": "salary_slip_based_on_timesheet",
"fieldtype": "Check",
"label": "Salary Slip Based on Timesheet"
"label": "Salary Slip Based on Timesheet",
"search_index": 1
},
{
"fieldname": "column_break_17",
Expand Down Expand Up @@ -237,7 +238,7 @@
"idx": 1,
"is_submittable": 1,
"links": [],
"modified": "2023-03-24 18:16:49.424812",
"modified": "2023-06-13 18:02:31.779947",
"modified_by": "Administrator",
"module": "Payroll",
"name": "Salary Structure",
Expand Down
6 changes: 6 additions & 0 deletions hrms/public/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,11 @@ $.extend(hrms, {
cur_frm.save();
}
});
},

set_payroll_frequency_to_null: (frm) => {
if (frm.doc.salary_slip_based_on_timesheet ==1){
frm.set_value("payroll_frequency", "");
}
}
})

0 comments on commit 471287f

Please sign in to comment.