Skip to content

Commit

Permalink
Merge pull request #1522 from frappe/version-15-hotfix
Browse files Browse the repository at this point in the history
chore: release v15
  • Loading branch information
ruchamahabal authored Mar 13, 2024
2 parents f75977c + 93ac8bf commit 55e907f
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 42 deletions.
8 changes: 6 additions & 2 deletions hrms/hr/doctype/leave_ledger_entry/leave_ledger_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import frappe
from frappe import _
from frappe.model.document import Document
from frappe.utils import DATE_FORMAT, flt, getdate, today
from frappe.utils import DATE_FORMAT, flt, get_link_to_form, getdate, today


class LeaveLedgerEntry(Document):
Expand Down Expand Up @@ -40,7 +40,11 @@ def validate_leave_allocation_against_leave_application(ledger):
if leave_application_records:
frappe.throw(
_("Leave allocation {0} is linked with the Leave Application {1}").format(
ledger.transaction_name, ", ".join(leave_application_records)
ledger.transaction_name,
", ".join(
get_link_to_form("Leave Application", application)
for application in leave_application_records
),
)
)

Expand Down
5 changes: 4 additions & 1 deletion hrms/hr/doctype/shift_assignment/shift_assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,14 @@ def get_shift_assignments(start: str, end: str, filters: str | list | None = Non
if not filters:
filters = []

filters.extend([["start_date", ">=", start], ["end_date", "<=", end], ["docstatus", "=", 1]])
filters.extend([["start_date", "<=", end], ["docstatus", "=", 1]])

or_filters = [["end_date", ">=", start], ["end_date", "is", "not set"]]

return frappe.get_list(
"Shift Assignment",
filters=filters,
or_filters=or_filters,
fields=[
"name",
"start_date",
Expand Down
25 changes: 20 additions & 5 deletions hrms/hr/doctype/shift_assignment/test_shift_assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,17 +230,32 @@ def test_multiple_shift_assignments_for_same_day(self):
def test_calendar(self):
employee1 = make_employee("[email protected]", company="_Test Company")
employee2 = make_employee("[email protected]", company="_Test Company")
employee3 = make_employee("[email protected]", company="_Test Company")

shift_type = setup_shift_type(shift_type="Shift 1", start_time="08:00:00", end_time="12:00:00")
date = getdate()
shift1 = make_shift_assignment(shift_type.name, employee1, date)
make_shift_assignment(shift_type.name, employee2, date)
shift1 = make_shift_assignment(shift_type.name, employee1, date) # 1 day
make_shift_assignment(shift_type.name, employee2, date) # excluded due to employee filter
make_shift_assignment(
shift_type.name, employee3, add_days(date, -3), add_days(date, -2)
) # excluded
shift2 = make_shift_assignment(shift_type.name, employee3, add_days(date, -1), date) # 2 days
shift3 = make_shift_assignment(
shift_type.name, employee3, add_days(date, 1), add_days(date, 2)
) # 2 days
shift4 = make_shift_assignment(
shift_type.name, employee3, add_days(date, 30), add_days(date, 30)
) # 1 day
make_shift_assignment(shift_type.name, employee3, add_days(date, 31)) # excluded

events = get_events(
start=date, end=date, filters=[["Shift Assignment", "employee", "=", employee1, False]]
start=date,
end=add_days(date, 30),
filters=[["Shift Assignment", "employee", "!=", employee2, False]],
)
self.assertEqual(len(events), 1)
self.assertEqual(events[0]["name"], shift1.name)
self.assertEqual(len(events), 6)
for shift in events:
self.assertIn(shift["name"], [shift1.name, shift2.name, shift3.name, shift4.name])

def test_calendar_for_night_shift(self):
employee1 = make_employee("[email protected]", company="_Test Company")
Expand Down
2 changes: 1 addition & 1 deletion hrms/hr/page/organizational_chart/organizational_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def get_connections(employee: str, lft: int, rgt: int) -> int:
query = (
frappe.qb.from_(Employee)
.select(Count(Employee.name))
.where((Employee.lft > lft) & (Employee.rgt < rgt))
.where((Employee.lft > lft) & (Employee.rgt < rgt) & (Employee.status == "Active"))
).run()

return query[0][0]
76 changes: 44 additions & 32 deletions hrms/hr/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
# License: GNU General Public License v3. See license.txt

import frappe
from frappe import _
from frappe import _, qb
from frappe.model.document import Document
from frappe.query_builder import Criterion
from frappe.query_builder.custom import ConstantColumn
from frappe.utils import (
add_days,
comma_and,
Expand Down Expand Up @@ -721,59 +723,69 @@ def get_matching_queries(
filter_by_reference_date=None,
from_reference_date=None,
to_reference_date=None,
common_filters=None,
):
"""Returns matching queries for Bank Reconciliation"""
queries = []
if transaction.withdrawal > 0:
if "expense_claim" in document_types:
ec_amount_matching = get_ec_matching_query(
bank_account, company, exact_match, from_date, to_date
bank_account, company, exact_match, from_date, to_date, common_filters
)
queries.extend([ec_amount_matching])

return queries


def get_ec_matching_query(bank_account, company, exact_match, from_date=None, to_date=None):
def get_ec_matching_query(
bank_account, company, exact_match, from_date=None, to_date=None, common_filters=None
):
# get matching Expense Claim query
filters = []
ec = qb.DocType("Expense Claim")

mode_of_payments = [
x["parent"]
for x in frappe.db.get_all(
"Mode of Payment Account", filters={"default_account": bank_account}, fields=["parent"]
)
]

mode_of_payments = "('" + "', '".join(mode_of_payments) + "' )"
company_currency = get_company_currency(company)

filter_by_date = ""
filters.append(ec.docstatus == 1)
filters.append(ec.is_paid == 1)
filters.append(ec.clearance_date.isnull())
filters.append(ec.mode_of_payment.isin(mode_of_payments))
if exact_match:
filters.append(ec.total_sanctioned_amount == common_filters.amount)
else:
filters.append(ec.total_sanctioned_amount.gt(common_filters.amount))

if from_date and to_date:
filter_by_date = f"AND posting_date BETWEEN '{from_date}' AND '{to_date}'"
order_by = "posting_date"

return f"""
SELECT
( CASE WHEN employee = %(party)s THEN 1 ELSE 0 END
+ 1 ) AS rank,
'Expense Claim' as doctype,
name,
total_sanctioned_amount as paid_amount,
'' as reference_no,
'' as reference_date,
employee as party,
'Employee' as party_type,
posting_date,
{company_currency!r} as currency
FROM
`tabExpense Claim`
WHERE
total_sanctioned_amount {'= %(amount)s' if exact_match else '> 0.0'}
AND docstatus = 1
AND is_paid = 1
AND ifnull(clearance_date, '') = ""
AND mode_of_payment in {mode_of_payments}
{filter_by_date}
"""
filters.append(ec.posting_date[from_date:to_date])

ref_rank = frappe.qb.terms.Case().when(ec.employee == common_filters.party, 1).else_(0)

ec_query = (
qb.from_(ec)
.select(
(ref_rank + 1).as_("rank"),
ec.name,
ec.total_sanctioned_amount.as_("paid_amount"),
ConstantColumn("").as_("reference_no"),
ConstantColumn("").as_("reference_date"),
ec.employee.as_("party"),
ConstantColumn("Employee").as_("party_type"),
ec.posting_date,
ConstantColumn(company_currency).as_("currency"),
)
.where(Criterion.all(filters))
)

if from_date and to_date:
ec_query = ec_query.orderby(ec.posting_date)

return ec_query


def notify_bulk_action_status(doctype: str, failure: list, success: list) -> None:
Expand Down
2 changes: 1 addition & 1 deletion hrms/payroll/doctype/salary_slip/salary_slip.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ def calculate_lwp_ppl_and_absent_days_based_on_attendance(

# skip counting absent on holidays
if not consider_marked_attendance_on_holidays and getdate(d.attendance_date) in holidays:
if d.status == "Absent" or (
if d.status in ["Absent", "Half Day"] or (
d.leave_type
and d.leave_type in leave_type_map.keys()
and not leave_type_map[d.leave_type]["include_holiday"]
Expand Down
49 changes: 49 additions & 0 deletions hrms/payroll/doctype/salary_slip/test_salary_slip.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,55 @@ def test_consider_marked_attendance_on_holidays_with_unmarked_attendance(self):
# no_of_days - period before DOJ
self.assertEqual(ss.payment_days, no_of_days[0] - 3 - 1)

@change_settings(
"Payroll Settings",
{
"payroll_based_on": "Attendance",
"consider_unmarked_attendance_as": "Present",
"include_holidays_in_total_working_days": 1,
"consider_marked_attendance_on_holidays": 0,
},
)
def test_consider_marked_attendance_on_holidays_with_half_day_on_holiday(self):
from erpnext.setup.doctype.holiday_list.holiday_list import is_holiday

no_of_days = get_no_of_days()
month_start_date, month_end_date = get_first_day(nowdate()), get_last_day(nowdate())
joining_date = add_days(month_start_date, 3)

emp_id = make_employee(
"[email protected]",
status="Active",
date_of_joining=joining_date,
relieving_date=None,
)

for days in range(date_diff(month_end_date, joining_date) + 1):
date = add_days(joining_date, days)
if not is_holiday("Salary Slip Test Holiday List", date):
mark_attendance(emp_id, date, "Present", ignore_validate=True)

# mark half day on holiday
first_sunday = get_first_sunday(for_date=joining_date, find_after_for_date=True)
mark_attendance(emp_id, first_sunday, "Half Day", ignore_validate=True)

ss = make_employee_salary_slip(
emp_id,
"Monthly",
"Test Salary Slip With Holidays Included",
)

self.assertEqual(ss.total_working_days, no_of_days[0])
# no_of_days - period before DOJ
self.assertEqual(ss.payment_days, no_of_days[0] - 3)

# enable consider marked attendance on holidays
frappe.db.set_single_value("Payroll Settings", "consider_marked_attendance_on_holidays", 1)
ss.save()
self.assertEqual(ss.total_working_days, no_of_days[0])
# no_of_days - period before DOJ - 0.5 LWP on holiday (half day present)
self.assertEqual(ss.payment_days, no_of_days[0] - 3 - 0.5)

@change_settings("Payroll Settings", {"include_holidays_in_total_working_days": 1})
def test_payment_days(self):
from hrms.payroll.doctype.salary_structure.test_salary_structure import (
Expand Down

0 comments on commit 55e907f

Please sign in to comment.