add punch mission in report attendances

This commit is contained in:
mohammed-alkhazrji 2025-06-29 18:08:10 +03:00
parent 082e00b718
commit 4929f48e01
2 changed files with 76 additions and 25 deletions

View File

@ -16,9 +16,9 @@
<!-- <field name="dpi">90</field>-->
<field name="margin_top">30</field>
<field name="margin_right">5</field>
<field name="margin_right">1</field>
<field name="margin_bottom">10</field>
<field name="margin_left">5</field>
<field name="margin_left">1</field>
<field name="header_line" eval="False"/>
<field name="header_spacing">35</field>
<field name="dpi">90</field>
@ -157,7 +157,7 @@
</t>
</div>
</template>
<template id="late_attendance_report_template">
<template id="late_attendance_report_template">
<t t-foreach="mykey" t-as="key">
<div class="page" style="font-size:12pt" dir="rtl">
<center>
@ -385,16 +385,18 @@
<th style="border: 1px solid gray; padding: 1px; font-size:0.8em;background-color: #b9d7d4;color: black;width:10%;text-align:center;">رقم الهوية</th>
<th style="border: 1px solid gray; padding: 1px; font-size:0.8em;background-color: #b9d7d4;color: black;width:10%;text-align:center;">اﻹدارة</th>
<th style="border: 1px solid gray; padding: 1px; font-size:0.8em;background-color: #b9d7d4;color: black;width:10%;text-align:center;">المسمي الوظيفي</th>
<th style="border: 1px solid gray; padding: 1px; font-size:0.8em;background-color: #b9d7d4;color: black;width:6%;text-align:center;">ايام الحضور</th>
<th style="border: 1px solid gray; padding: 1px; font-size:0.8em;background-color: #b9d7d4;color: black;width:6%;text-align:center;">الاجازات</th>
<th style="border: 1px solid gray; padding: 1px; font-size:0.8em;background-color: #b9d7d4;color: black;width:6%;text-align:center;">الاجازات الرسمية</th>
<th style="border: 1px solid gray; padding: 1px; font-size:0.8em;background-color: #b9d7d4;color: black;width:6%;text-align:center;">الغياب</th>
<th style="border: 1px solid gray; padding: 1px; font-size:0.8em;background-color: #b9d7d4;color: black;width:6%;text-align:center;">ساعات العمل الفعلية</th>
<th style="border: 1px solid gray; padding: 1px; font-size:0.8em;background-color: #b9d7d4;color: black;width:6%;text-align:center;">ساعات العمل الاضافية</th>
<th style="border: 1px solid gray; padding: 1px; font-size:0.8em;background-color: #b9d7d4;color: black;width:6%;text-align:center;">الاستئذان</th>
<th style="border: 1px solid gray; padding: 1px; font-size:0.8em;background-color: #b9d7d4;color: black;width:6%;text-align:center;">مهام عمل/انتداب/تدريب</th>
<th style="border: 1px solid gray; padding: 1px; font-size:0.8em;background-color: #b9d7d4;color: black;width:4%;text-align:center;">ايام<br/>الحضور</th>
<th style="border: 1px solid gray; padding: 1px; font-size:0.8em;background-color: #b9d7d4;color: black;width:4%;text-align:center;">الاجازات</th>
<th style="border: 1px solid gray; padding: 1px; font-size:0.8em;background-color: #b9d7d4;color: black;width:4%;text-align:center;">الاجازات<br/>الرسمية</th>
<th style="border: 1px solid gray; padding: 1px; font-size:0.8em;background-color: #b9d7d4;color: black;width:4%;text-align:center;">الغياب</th>
<th style="border: 1px solid gray; padding: 1px; font-size:0.8em;background-color: #b9d7d4;color: black;width:4%;text-align:center;">نسيان<br/>البصمة</th>
<th style="border: 1px solid gray; padding: 1px; font-size:0.8em;background-color: #b9d7d4;color: black;width:6%;text-align:center;">ساعات<br/>العمل<br/>الفعلية</th>
<th style="border: 1px solid gray; padding: 1px; font-size:0.8em;background-color: #b9d7d4;color: black;width:6%;text-align:center;">ساعات<br/>العمل<br/>الاضافية</th>
<th style="border: 1px solid gray; padding: 1px; font-size:0.8em;background-color: #b9d7d4;color: black;width:4%;text-align:center;">الاستئذان</th>
<th style="border: 1px solid gray; padding: 1px; font-size:0.8em;background-color: #b9d7d4;color: black;width:6%;text-align:center;">مهام<br/>عمل<br/>انتداب<br/>تدريب</th>
<th style="border: 1px solid gray; padding: 1px; font-size:0.8em;background-color: #b9d7d4;color: black;width:6%;text-align:center;">التأخيرات</th>
<th style="border: 1px solid gray; padding: 1px; font-size:0.8em;background-color: #b9d7d4;color: black;width:6%;text-align:center;">الخروج المبكر</th>
<th style="border: 1px solid gray; padding: 1px; font-size:0.8em;background-color: #b9d7d4;color: black;width:6%;text-align:center;">الخروج<br/>المبكر</th>
</tr>
</thead>
<tbody>
@ -408,13 +410,15 @@
<td style="border: 1px solid gray;padding: 1px; width:10%;font-size:0.8em;background-color: white;color: black; text-align:center" t-esc="row['department']"/>
<td style="border: 1px solid gray;padding: 1px; width:10%;font-size:0.8em;background-color: white;color: black; text-align:center" t-esc="row['job']"/>
<td style="border: 1px solid gray;padding: 1px; width:6%;font-size:0.8em;background-color: white;color: black; text-align:center" t-esc="row['days_present']"/>
<td style="border: 1px solid gray;padding: 1px; width:6%;font-size:0.8em;background-color: white;color: black; text-align:center" t-esc="row['leave_days']"/>
<td style="border: 1px solid gray;padding: 1px; width:6%;font-size:0.8em;background-color: white;color: black; text-align:center" t-esc="row['holiday_days']"/>
<td style="border: 1px solid gray;padding: 1px; width:4%;font-size:0.8em;background-color: white;color: black; text-align:center" t-esc="row['days_present']"/>
<td style="border: 1px solid gray;padding: 1px; width:4%;font-size:0.8em;background-color: white;color: black; text-align:center" t-esc="row['leave_days']"/>
<td style="border: 1px solid gray;padding: 1px; width:4%;font-size:0.8em;background-color: white;color: black; text-align:center" t-esc="row['holiday_days']"/>
<td style="border: 1px solid gray;padding: 1px; width:6%;font-size:0.8em;background-color: white;color: black; text-align:center" t-esc="row['absent_days']"/>
<td style="border: 1px solid gray;padding: 1px; width:6%;font-size:0.8em;background-color: white;color: black; text-align:center" t-esc="row['missing_punch_days']"/>
<td style="border: 1px solid gray;padding: 1px; width:6%;font-size:0.8em;background-color: white;color: black; text-align:center" t-esc="row['office_hours']"/>
<td style="border: 1px solid gray;padding: 1px; width:6%;font-size:0.8em;background-color: white;color: black; text-align:center" t-esc="row['extra_hours']"/>
<td style="border: 1px solid gray;padding: 1px; width:6%;font-size:0.8em;background-color: white;color: black; text-align:center" t-esc="row['permission_hours']"/>
<td style="border: 1px solid gray;padding: 1px; width:4%;font-size:0.8em;background-color: white;color: black; text-align:center" t-esc="row['permission_hours']"/>
<td style="border: 1px solid gray;padding: 1px; width:6%;font-size:0.8em;background-color: white;color: black; text-align:center" t-esc="row['mission_hours']"/>
<td style="border: 1px solid gray;padding: 1px; width:6%;font-size:0.8em;background-color: white;color: black; text-align:center" t-esc="row['lateness_approved']"/>
<td style="border: 1px solid gray;padding: 1px; width:6%;font-size:0.8em;background-color: white;color: black; text-align:center" t-esc="row['early_exit_approved']"/>
@ -430,6 +434,7 @@
<td style="border: 1px solid gray;padding: 1px;font-size:0.8em;background-color: #f9f9f9;color: black;" t-esc="totals['leave_days']"/>
<td style="border: 1px solid gray;padding: 1px;font-size:0.8em;background-color: #f9f9f9;color: black;" t-esc="totals['holiday_days']"/>
<td style="border: 1px solid gray;padding: 1px;font-size:0.8em;background-color: #f9f9f9;color: black;" t-esc="totals['absent_days']"/>
<td style="border: 1px solid gray;padding: 1px;font-size:0.8em;background-color: #f9f9f9;color: black;" t-esc="totals['missing_punch_days']"/>
<td style="border: 1px solid gray;padding: 1px;font-size:0.8em;background-color: #f9f9f9;color: black;" t-esc="totals['office_hours']"/>
<td style="border: 1px solid gray;padding: 1px;font-size:0.8em;background-color: #f9f9f9;color: black;" t-esc="totals['extra_hours']"/>
<td style="border: 1px solid gray;padding: 1px;font-size:0.8em;background-color: #f9f9f9;color: black;" t-esc="totals['permission_hours']"/>

View File

@ -95,6 +95,7 @@ class ReportAttendancePublic(models.AbstractModel):
key_list = []
total_dic = {}
mykey = []
resource = self.env['resource.calendar'].browse(resource_calender_id)
if resource and not employee_ids:
if resource.employee_ids:
@ -134,6 +135,11 @@ class ReportAttendancePublic(models.AbstractModel):
note = resource.leave_id.holiday_status_id.name
elif resource.approve_personal_permission:
note = resource.personal_permission_id.permission_type_id.name
elif not resource.public_holiday and not resource.normal_leave:
if resource.sign_in and not resource.sign_out:
note = 'نسيان بصمة'
elif not resource.sign_in and resource.sign_out:
note = 'نسيان بصمة'
data.append({
'date': resource.date,
@ -151,7 +157,6 @@ class ReportAttendancePublic(models.AbstractModel):
'employee_id': resource.employee_id,
'employee_name': resource.employee_id.name,
})
data = sorted(data, key=lambda d: d['date'])
for emp in employees:
list_cat = attendance_transaction_ids.filtered(lambda r: r.employee_id.name == emp)
@ -160,6 +165,14 @@ class ReportAttendancePublic(models.AbstractModel):
total_late_early = str(datetime.timedelta(minutes=total_early_exit + total_lateness))
total_extra_hours = sum(list_cat.mapped('additional_hours'))
total_extra_hours = str(datetime.timedelta(minutes=total_extra_hours))
list_missing_punch = attendance_transaction_ids.filtered(
lambda r: r.employee_id.name == emp and
not r.public_holiday and
not r.normal_leave and
((r.sign_in and not r.sign_out) or (not r.sign_in and r.sign_out))
)
total_missing_punch = len(list_missing_punch)
list_absent = attendance_transaction_ids.filtered(
lambda r: r.employee_id.name == emp and r.is_absent == True)
total_absent = len(list_absent)
@ -176,7 +189,8 @@ class ReportAttendancePublic(models.AbstractModel):
"total_extra_hours": total_extra_hours, "total_late_early": total_late_early,
"total_leave": total_leave, 'total_absent': total_absent,
'total_not_sig_in': total_not_sig_in,
'total_not_sig_out': total_not_sig_out}
'total_not_sig_out': total_not_sig_out,
'total_missing_punch':total_missing_punch}
grouped = collections.defaultdict(list)
for item in data:
grouped[item['employee_name']].append(item)
@ -338,6 +352,7 @@ class ReportAttendancegeneral(models.AbstractModel):
key_list = []
total_dic = {}
mykey = []
print("gg122e")
resource = self.env['resource.calendar'].browse(resource_calender_id)
if resource and not employee_ids:
if resource.employee_ids:
@ -377,6 +392,11 @@ class ReportAttendancegeneral(models.AbstractModel):
note = resource.leave_id.holiday_status_id.name
elif resource.approve_personal_permission:
note = resource.personal_permission_id.permission_type_id.name
elif not resource.public_holiday and not resource.normal_leave:
if resource.sign_in and not resource.sign_out:
note = 'نسيان بصمة'
elif not resource.sign_in and resource.sign_out:
note = 'نسيان بصمة'
data.append({
'date': resource.date,
@ -403,6 +423,15 @@ class ReportAttendancegeneral(models.AbstractModel):
total_late_early = str(datetime.timedelta(minutes=total_early_exit + total_lateness))
total_extra_hours = sum(list_cat.mapped('additional_hours'))
total_extra_hours = str(datetime.timedelta(minutes=total_extra_hours))
list_missing_punch = attendance_transaction_ids.filtered(
lambda r: r.employee_id.name == emp and
not r.public_holiday and
not r.normal_leave and
((r.sign_in and not r.sign_out) or (not r.sign_in and r.sign_out))
)
total_missing_punch = len(list_missing_punch)
list_absent = attendance_transaction_ids.filtered(
lambda r: r.employee_id.name == emp and r.is_absent == True)
total_absent = len(list_absent)
@ -415,11 +444,13 @@ class ReportAttendancegeneral(models.AbstractModel):
lambda r: r.employee_id.name == emp and (r.normal_leave or r.approve_personal_permission))
total_not_sig_out = len(list_not_log_out)
total_leave = len(list_leave)
print('total_missing_punch',total_missing_punch)
total_dic[emp] = {'total_lateness': total_lateness, 'total_early_exit': total_early_exit,
"total_extra_hours": total_extra_hours, "total_late_early": total_late_early,
"total_leave": total_leave, 'total_absent': total_absent,
'total_not_sig_in': total_not_sig_in,
'total_not_sig_out': total_not_sig_out}
'total_not_sig_out': total_not_sig_out,
'total_missing_punch':total_missing_punch}
grouped = collections.defaultdict(list)
for item in data:
grouped[item['employee_name']].append(item)
@ -491,6 +522,10 @@ class ReportAttendancegeneral(models.AbstractModel):
absent = {l.date for l in lines if l.is_absent}
vacation = {l.date for l in lines if l.normal_leave}
holidays = {l.date for l in lines if l.public_holiday}
missing_punch = {l.date for l in lines if
not l.public_holiday and
not l.normal_leave and
((l.sign_in and not l.sign_out) or (not l.sign_in and l.sign_out))}
iq = getattr(emp, 'iqama_number', False) or getattr(emp, 'saudi_number', '')
calendar_name = lines[0].calendar_id.name if lines and lines[0].calendar_id else ''
@ -505,7 +540,7 @@ class ReportAttendancegeneral(models.AbstractModel):
'leave_days': len(vacation),
'holiday_days': len(holidays),
'absent_days': len(absent),
'missing_punch_days': len(missing_punch),
'office_hours': hhmm(sum(lines.mapped('office_hours'))),
'extra_hours': hhmm(sum(lines.mapped('additional_hours'))),
'permission_hours': hhmm(sum(lines.mapped('total_permission_hours'))),
@ -527,7 +562,7 @@ class ReportAttendancegeneral(models.AbstractModel):
'leave_days': sum(row['leave_days'] for row in summary_rows),
'holiday_days': sum(row['holiday_days'] for row in summary_rows),
'absent_days': sum(row['absent_days'] for row in summary_rows),
'missing_punch_days': sum(row['missing_punch_days'] for row in summary_rows),
'office_hours': hhmm(sum(row['office_hours_int'] for row in summary_rows)),
'extra_hours': hhmm(sum(row['extra_hours_int'] for row in summary_rows)),
'permission_hours': hhmm(sum(row['permission_hours_int'] for row in summary_rows)),
@ -660,6 +695,8 @@ class AttendancesReportXls(models.AbstractModel):
# return
if totals_only:
print("حةبنرىي لايتلﻻنتبلﻻ ")
sheet.merge_range('F2:P2', _('تقرير الحضور والانصراف للموظفين'), fmt)
sheet.write('G3', _('من تاريخ'), fmt)
sheet.write('J3', _('إلى تاريخ'), fmt)
@ -667,10 +704,12 @@ class AttendancesReportXls(models.AbstractModel):
sheet.write(2, 10, str(end_date), fmt)
headers = [
'الرقم الوظيفي', 'اسم الموظف','الدوام', 'رقم الهوية', 'اﻹدارة', 'المسمي الوظيفي',
'ايام الحضور', 'الاجازات', 'الاجازات الرسمية', 'الغياب', 'ساعات العمل الفعلية',
'ساعات العمل الاضافية', 'الاستئذان', 'مهام عمل/انتداب/تدريب', 'التأخيرات', 'الخروج المبكر',
'الرقم الوظيفي', 'اسم الموظف', 'الدوام', 'رقم الهوية', 'اﻹدارة', 'المسمي الوظيفي',
'ايام الحضور', 'الاجازات', 'الاجازات الرسمية', 'الغياب', 'نسيان البصمة', # إضافة العمود الجديد
'ساعات العمل الفعلية', 'ساعات العمل الاضافية', 'الاستئذان', 'مهام عمل/انتداب/تدريب',
'التأخيرات', 'الخروج المبكر',
]
for col, h in enumerate(headers, start=1):
sheet.write(5, col, h, fmt)
@ -689,7 +728,7 @@ class AttendancesReportXls(models.AbstractModel):
total_leave = 0
total_holidays = 0
total_absent = 0
total_missing_punch = 0
for emp in att.mapped('employee_id'):
emp_att_lines = att.filtered(lambda l: l.employee_id == emp)
for seq in sorted(set(emp_att_lines.mapped('sequence'))): # For each shift (1, 2)
@ -699,11 +738,16 @@ class AttendancesReportXls(models.AbstractModel):
absent = {l.date for l in lines if l.is_absent}
vacation = {l.date for l in lines if l.normal_leave}
holidays = {l.date for l in lines if l.public_holiday}
missing_punch = {l.date for l in lines if
not l.public_holiday and
not l.normal_leave and
((l.sign_in and not l.sign_out) or (not l.sign_in and l.sign_out))}
total_days += len(all_days - absent - vacation - holidays)
total_leave += len(vacation)
total_holidays += len(holidays)
total_absent += len(absent)
total_missing_punch += len(missing_punch) # إضافة للمجموع
iq = getattr(emp, 'iqama_number', False) or getattr(emp, 'saudi_number', '')
calendar_name = lines[0].calendar_id.name if lines and lines[0].calendar_id else ''
@ -720,6 +764,7 @@ class AttendancesReportXls(models.AbstractModel):
len(vacation),
len(holidays),
len(absent),
len(missing_punch),
hhmm(sum(lines.mapped('office_hours'))),
hhmm(sum(lines.mapped('additional_hours'))),
hhmm(sum(lines.mapped('total_permission_hours'))),
@ -736,6 +781,7 @@ class AttendancesReportXls(models.AbstractModel):
total_leave,
total_holidays,
total_absent,
total_missing_punch,
hhmm(sum(att.mapped('office_hours'))),
hhmm(sum(att.mapped('additional_hours'))),
hhmm(sum(att.mapped('total_permission_hours'))),