WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Fixing the visibility of Attendance records, specifically absent ones. #3723

@hadeelNRD

Description

@hadeelNRD

Information about bug

Fix: Include all Attendance records regardless of Checkin status

Changed the JOIN type from INNER JOIN to LEFT JOIN when connecting
'Attendance' and 'Employee Checkin' tables in the attendance query.

This ensures that Attendance records that do not have associated Employee
Checkins (such as 'Absent' or manual entries) are correctly included in the result set,
preventing data loss in reports/views relying on this query.

the old function:

query = (
	frappe.qb.from_(attendance)
	.inner_join(checkin)
	.on(checkin.attendance == attendance.name)
	.inner_join(shift_type)
	.on(attendance.shift == shift_type.name)
	.select(
		attendance.name,
		attendance.employee,
		attendance.employee_name,
		attendance.shift,
		attendance.attendance_date,
		attendance.status,
		attendance.in_time,
		attendance.out_time,
		attendance.working_hours,
		attendance.late_entry,
		attendance.early_exit,
		attendance.department,
		attendance.company,
		checkin.shift_start,
		checkin.shift_end,
		checkin.shift_actual_start,
		checkin.shift_actual_end,
		shift_type.enable_late_entry_marking,
		shift_type.late_entry_grace_period,
		shift_type.enable_early_exit_marking,
		shift_type.early_exit_grace_period,
	)
	.where(attendance.docstatus == 1)
	.groupby(attendance.name)
)

the new query:

query = (
	frappe.qb.from_(attendance)
	# Use LEFT JOIN here to keep all Attendance records
	.left_join(checkin) 
	.on(checkin.attendance == attendance.name)
	# This can remain inner_join if every attendance has a shift type
	.inner_join(shift_type)
	.on(attendance.shift == shift_type.name)
	.select(
		attendance.name,
		attendance.employee,
		attendance.employee_name,
		attendance.shift,
		attendance.attendance_date,
		attendance.status,
		attendance.in_time,
		attendance.out_time,
		attendance.working_hours,
		attendance.late_entry,
		attendance.early_exit,
		attendance.department,
		attendance.company,
		checkin.shift_start,
		checkin.shift_end,
		checkin.shift_actual_start,
		checkin.shift_actual_end,
		shift_type.enable_late_entry_marking,
		shift_type.late_entry_grace_period,
		shift_type.enable_early_exit_marking,
		shift_type.early_exit_grace_period,
	)
	.where(attendance.docstatus == 1)
	.groupby(attendance.name)
)

Module

HR

Version

ERPNext: v15.57.5 (version-15)

Frappe Framework: v15.63.1 (v15.23.1)

Frappe HR: v15.43.0 (heads/v15.35.2)

Frappe Lending: v0.0.1 (version-15)

Installation method

manual install

Relevant log output / Stack trace / Full Error Message.

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions