[Fix] HR Fixes (#14511)

* Payroll Entry - fix in db query

* Salary Structure Assignment - Company read_only = 1

* Fixes in hr util and benefit claim

* Employee Benefit Application - Late application - fix
This commit is contained in:
Jamsheer
2018-06-14 11:55:17 +05:30
committed by Nabin Hait
parent 17089eeac3
commit c7743932ab
4 changed files with 86 additions and 71 deletions

View File

@@ -105,29 +105,30 @@ def get_max_benefits_remaining(employee, on_date, payroll_period):
# Get all salary slip flexi amount in the payroll period # Get all salary slip flexi amount in the payroll period
prev_sal_slip_flexi_total = get_sal_slip_total_benefit_given(employee, payroll_period_obj) prev_sal_slip_flexi_total = get_sal_slip_total_benefit_given(employee, payroll_period_obj)
# Check salary structure hold depends_on_lwp component if prev_sal_slip_flexi_total > 0:
# If yes then find the amount per day of each component and find the sum # Check salary structure hold depends_on_lwp component
sal_struct_name = get_assigned_salary_structure(employee, on_date) # If yes then find the amount per day of each component and find the sum
if sal_struct_name: sal_struct_name = get_assigned_salary_structure(employee, on_date)
sal_struct = frappe.get_doc("Salary Structure", sal_struct_name) if sal_struct_name:
for sal_struct_row in sal_struct.get("earnings"): sal_struct = frappe.get_doc("Salary Structure", sal_struct_name)
salary_component = frappe.get_doc("Salary Component", sal_struct_row.salary_component) for sal_struct_row in sal_struct.get("earnings"):
if salary_component.depends_on_lwp == 1 and salary_component.is_pro_rata_applicable == 1: salary_component = frappe.get_doc("Salary Component", sal_struct_row.salary_component)
have_depends_on_lwp = True if salary_component.depends_on_lwp == 1 and salary_component.is_pro_rata_applicable == 1:
benefit_amount = get_benefit_pro_rata_ratio_amount(sal_struct, salary_component.max_benefit_amount) have_depends_on_lwp = True
amount_per_day = benefit_amount / payroll_period_days benefit_amount = get_benefit_pro_rata_ratio_amount(sal_struct, salary_component.max_benefit_amount)
per_day_amount_total += amount_per_day amount_per_day = benefit_amount / payroll_period_days
per_day_amount_total += amount_per_day
# Then the sum multiply with the no of lwp in that period # Then the sum multiply with the no of lwp in that period
# Include that amount to the prev_sal_slip_flexi_total to get the actual # Include that amount to the prev_sal_slip_flexi_total to get the actual
if have_depends_on_lwp and per_day_amount_total > 0: if have_depends_on_lwp and per_day_amount_total > 0:
holidays = get_holidays_for_employee(employee, payroll_period_obj.start_date, on_date) holidays = get_holidays_for_employee(employee, payroll_period_obj.start_date, on_date)
working_days = date_diff(on_date, payroll_period_obj.start_date) + 1 working_days = date_diff(on_date, payroll_period_obj.start_date) + 1
leave_days = calculate_lwp(employee, payroll_period_obj.start_date, holidays, working_days) leave_days = calculate_lwp(employee, payroll_period_obj.start_date, holidays, working_days)
leave_days_amount = leave_days * per_day_amount_total leave_days_amount = leave_days * per_day_amount_total
prev_sal_slip_flexi_total += leave_days_amount prev_sal_slip_flexi_total += leave_days_amount
return max_benefits - prev_sal_slip_flexi_total return max_benefits - prev_sal_slip_flexi_total
return max_benefits return max_benefits
def calculate_lwp(employee, start_date, holidays, working_days): def calculate_lwp(employee, start_date, holidays, working_days):

View File

@@ -16,6 +16,8 @@ class EmployeeBenefitClaim(Document):
if not max_benefits or max_benefits <= 0: if not max_benefits or max_benefits <= 0:
frappe.throw(_("Employee {0} has no maximum benefit amount").format(self.employee)) frappe.throw(_("Employee {0} has no maximum benefit amount").format(self.employee))
payroll_period = get_payroll_period(self.claim_date, self.claim_date, frappe.db.get_value("Employee", self.employee, "company")) payroll_period = get_payroll_period(self.claim_date, self.claim_date, frappe.db.get_value("Employee", self.employee, "company"))
if not payroll_period:
frappe.throw(_("{0} is not in a valid Payroll Period").format(self.claim_date))
self.validate_max_benefit_for_component(payroll_period) self.validate_max_benefit_for_component(payroll_period)
self.validate_max_benefit_for_sal_struct(max_benefits) self.validate_max_benefit_for_sal_struct(max_benefits)
self.validate_benefit_claim_amount(max_benefits, payroll_period) self.validate_benefit_claim_amount(max_benefits, payroll_period)

View File

@@ -32,7 +32,7 @@ class PayrollEntry(Document):
select select
name from `tabSalary Structure` name from `tabSalary Structure`
where where
docstatus != 2 and docstatus = 1 and
is_active = 'Yes' is_active = 'Yes'
and company = %(company)s and and company = %(company)s and
ifnull(salary_slip_based_on_timesheet,0) = %(salary_slip_based_on_timesheet)s ifnull(salary_slip_based_on_timesheet,0) = %(salary_slip_based_on_timesheet)s
@@ -47,8 +47,7 @@ class PayrollEntry(Document):
from from
`tabEmployee` t1, `tabSalary Structure Assignment` t2 `tabEmployee` t1, `tabSalary Structure Assignment` t2
where where
t1.docstatus!=2 t1.name = t2.employee
and t1.name = t2.employee
and t2.docstatus = 1 and t2.docstatus = 1
%s """% cond, {"sal_struct": sal_struct, "from_date": self.start_date, "to_date": self.end_date}, as_dict=True) %s """% cond, {"sal_struct": sal_struct, "from_date": self.start_date, "to_date": self.end_date}, as_dict=True)
return emp_list return emp_list

View File

@@ -15,6 +15,7 @@
"fields": [ "fields": [
{ {
"allow_bulk_edit": 0, "allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
@@ -47,6 +48,7 @@
}, },
{ {
"allow_bulk_edit": 0, "allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
@@ -80,6 +82,7 @@
}, },
{ {
"allow_bulk_edit": 0, "allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
@@ -113,6 +116,7 @@
}, },
{ {
"allow_bulk_edit": 0, "allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
@@ -145,6 +149,7 @@
}, },
{ {
"allow_bulk_edit": 0, "allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
@@ -175,6 +180,7 @@
}, },
{ {
"allow_bulk_edit": 0, "allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
@@ -206,6 +212,7 @@
}, },
{ {
"allow_bulk_edit": 0, "allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 1, "allow_on_submit": 1,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
@@ -237,6 +244,7 @@
}, },
{ {
"allow_bulk_edit": 0, "allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
@@ -258,10 +266,10 @@
"precision": "", "precision": "",
"print_hide": 0, "print_hide": 0,
"print_hide_if_no_value": 0, "print_hide_if_no_value": 0,
"read_only": 0, "read_only": 1,
"remember_last_selected_value": 0, "remember_last_selected_value": 0,
"report_hide": 0, "report_hide": 0,
"reqd": 0, "reqd": 1,
"search_index": 0, "search_index": 0,
"set_only_once": 0, "set_only_once": 0,
"translatable": 0, "translatable": 0,
@@ -269,6 +277,7 @@
}, },
{ {
"allow_bulk_edit": 0, "allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
@@ -299,6 +308,7 @@
}, },
{ {
"allow_bulk_edit": 0, "allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
@@ -330,6 +340,7 @@
}, },
{ {
"allow_bulk_edit": 0, "allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
@@ -360,6 +371,7 @@
}, },
{ {
"allow_bulk_edit": 0, "allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
@@ -391,6 +403,7 @@
}, },
{ {
"allow_bulk_edit": 0, "allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
@@ -431,7 +444,7 @@
"issingle": 0, "issingle": 0,
"istable": 0, "istable": 0,
"max_attachments": 0, "max_attachments": 0,
"modified": "2018-05-17 11:25:20.009793", "modified": "2018-06-13 16:18:19.784377",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "HR", "module": "HR",
"name": "Salary Structure Assignment", "name": "Salary Structure Assignment",