Skip to content

Commit

Permalink
Merge pull request #3027 from ONE-F-M/test-production
Browse files Browse the repository at this point in the history
Test production to master
  • Loading branch information
mymi14s authored Jan 3, 2024
2 parents f359ad6 + 90b6d4f commit 00caab2
Show file tree
Hide file tree
Showing 24 changed files with 1,356 additions and 461 deletions.
8 changes: 1 addition & 7 deletions one_fm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
from erpnext.stock.doctype.item_price.item_price import ItemPrice
from erpnext.setup.doctype.employee.employee import Employee
from one_fm.api.doc_methods.shift_request import shift_request_submit, validate_approver, shift_request_cancel, validate_default_shift
from one_fm.api.doc_methods.payroll_entry import (
validate_employee_attendance, get_count_holidays_of_employee, get_count_employee_attendance, fill_employee_details, create_salary_slips
)
from one_fm.api.doc_methods.payroll_entry import fill_employee_details
from one_fm.api.doc_methods.salary_slip import (
get_working_days_details, get_unmarked_days_based_on_doj_or_relieving, get_unmarked_days, get_data_for_eval
)
Expand Down Expand Up @@ -72,11 +70,7 @@
ShiftRequest.validate_approver = validate_approver
ShiftRequest.on_cancel = shift_request_cancel
ShiftRequest.validate_default_shift = validate_default_shift
PayrollEntry.validate_employee_attendance = validate_employee_attendance
PayrollEntry.get_count_holidays_of_employee = get_count_holidays_of_employee
PayrollEntry.get_count_employee_attendance = get_count_employee_attendance
PayrollEntry.fill_employee_details = fill_employee_details
PayrollEntry.create_salary_slips = create_salary_slips
SalarySlip.get_working_days_details = get_working_days_details
SalarySlip.get_unmarked_days_based_on_doj_or_relieving = get_unmarked_days_based_on_doj_or_relieving
SalarySlip.get_unmarked_days = get_unmarked_days
Expand Down
83 changes: 2 additions & 81 deletions one_fm/api/doc_methods/payroll_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,40 +27,6 @@
from erpnext.setup.doctype.employee.employee import get_holiday_list_for_employee
from one_fm.utils import production_domain

def validate_employee_attendance(self):
employees_to_mark_attendance = []
days_in_payroll, days_holiday, days_attendance_marked = 0, 0, 0

for employee_detail in self.employees:
employee_joining_date = frappe.db.get_value(
"Employee", employee_detail.employee, "date_of_joining"
)
start_date = self.start_date
if employee_joining_date > getdate(self.start_date):
start_date = employee_joining_date

days_holiday = self.get_count_holidays_of_employee(employee_detail.employee, start_date)
days_attendance_marked, days_scheduled = self.get_count_employee_attendance(employee_detail.employee, start_date)

days_in_payroll = date_diff(self.end_date, self.start_date) + 1
if days_in_payroll != (days_holiday + days_attendance_marked) != (days_holiday + days_scheduled) :
employees_to_mark_attendance.append({
"employee": employee_detail.employee,
"employee_name": employee_detail.employee_name
})
return employees_to_mark_attendance

def get_count_holidays_of_employee(self, employee, start_date):
holiday_list = get_holiday_list_for_employee(employee)
holidays = 0
if holiday_list:
days = frappe.db.sql("""select count(*) from `tabEmployee Schedule` where
employee=%s and date between %s and %s and employee_availability in ("Day Off", "Sick Leave", "Annual Leave", "Emergency Leave") """, (employee,
start_date, self.end_date))
if days and days[0][0]:
holidays = days[0][0]
return holidays

@frappe.whitelist()
def fill_employee_details(self):
"""
Expand Down Expand Up @@ -130,8 +96,6 @@ def fill_employee_details(self):
for d in employees:
self.append('employees', d)
self.number_of_employees = len(self.employees)
if self.validate_attendance:
return self.validate_employee_attendance()

@frappe.whitelist()
def get_emp_list(self, project_list=False):
Expand Down Expand Up @@ -279,21 +243,6 @@ def set_bank_details(self, employee_details):
frappe.throw(_(message))
return employee_details

def get_count_employee_attendance(self, employee, start_date):
scheduled_days = 0
marked_days = 0
roster = frappe.db.sql("""select count(*) from `tabEmployee Schedule` where
employee=%s and date between %s and %s and employee_availability="Working" """,
(employee, start_date, self.end_date))
if roster and roster[0][0]:
scheduled_days = roster[0][0]
attendances = frappe.db.sql("""select count(*) from tabAttendance where
employee=%s and docstatus=1 and attendance_date between %s and %s""",
(employee, start_date, self.end_date))
if attendances and attendances[0][0]:
marked_days = attendances[0][0]
return marked_days, scheduled_days

def auto_create_payroll_entry(payroll_date=None):
"""
Create Payroll Entry record with payroll cycle configured in HR and Payroll Additional Settings.
Expand Down Expand Up @@ -332,7 +281,8 @@ def auto_create_payroll_entry(payroll_date=None):

def create_monthly_payroll_entry(payroll_date, start_date, end_date):
try:
payroll_type = ["Basic", "Over-Time"]
# payroll_type = ["Basic", "Over-Time"]
payroll_type = ["Basic"]
for types in payroll_type:
payroll_entry = frappe.new_doc("Payroll Entry")
payroll_entry.posting_date = getdate(payroll_date)
Expand Down Expand Up @@ -634,35 +584,6 @@ def email_missing_payment_information(recipients):
# print(frappe.session.data)
# print(recipients, '\n\n\n')

@frappe.whitelist()
def create_salary_slips(doc):
"""
Creates salary slip for selected employees if already not created
"""
doc.check_permission("write")
employees = [emp.employee for emp in doc.employees]
if employees:
if len(employees) > 30 or frappe.flags.enqueue_payroll_entry:
doc.db_set("status", "Queued")
frappe.enqueue(
create_salary_slips_for_employees,
employees=employees,
payroll_entry=doc,
publish_progress=False,
timeout=6000,
queue='long'
)
frappe.msgprint(
_("Salary Slip creation is queued. It may take a few minutes"),
alert=True,
indicator="blue",
)
else:
create_salary_slips_for_employees(employees, payroll_entry = doc, publish_progress=False)
# since this method is called via frm.call this doc needs to be updated manually
doc.reload()


def log_payroll_failure(process, payroll_entry, error):
error_log = frappe.log_error(
title=_("Salary Slip {0} failed for Payroll Entry {1}").format(process, payroll_entry.name)
Expand Down
Loading

0 comments on commit 00caab2

Please sign in to comment.