Merge pull request #927 from expsa/fix-report

fix repoer
This commit is contained in:
eslam 2024-08-31 17:09:13 +03:00 committed by GitHub
commit 420c8d09ab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 125 additions and 54 deletions

View File

@ -17,7 +17,7 @@
مجموع التأخيرات
</th>
<th style=" border: 1px solid white; padding: 1px; font-size:0.8em;background-color: white;color: black;width:20%;text-align:center;">
مجموع الانصراف المبكر
مجموع الانصراف المبكر
</th>
</tr>
</thead>
@ -102,11 +102,11 @@
</div>
</template>
<template id="late_attendance_report_template">
<div class="page" style="font-size:12pt">
<div class="page" style="font-size:12pt" dir="rtl">
<br/>
<center><h2 style="font-weight:bold">تقرير تاخير و خروج مبكر</h2></center>
<br/>
<table style="width:100%">
<table style="width:100%;">
<tr>
<td><h4 style="font-weight:bold"> من تاريخ:</h4></td>
<td><t t-esc="date_start"/></td>
@ -116,104 +116,135 @@
</table>
<br/>
<t t-foreach="mykey" t-as="key">
<table style="width:100%">
<tr>
<td style="font-weight:bold">الموظف </td>
<td style="color:black"><t t-esc="key"/></td>
<table style="width:100%;float:right">
<tr style="width:100%;">
<td style="width:25%;font-weight:bold;text-align:right">رقم الموظف </td>
<td style="width:25%;color:black;text-align:right"><t t-esc="emp_data[key][0]['emp_no']"/></td>
<td style="width:25%;font-weight:bold;text-align:right">المسمى الوظيفى </td>
<td style="width:25%;color:black;text-align:right"><t t-esc="emp_data[key][0]['job']"/></td>
</tr>
<tr style="width:100%;">
<td style="width:25%;font-weight:bold;text-align:right"> اسم الموظف </td>
<td style="width:25%;color:black;text-align:right"><t t-esc="key"/></td>
<td style="width:25%;font-weight:bold;text-align:right">الادارة </td>
<td style="width:25%;color:black;text-align:right"><t t-esc="emp_data[key][0]['department']"/></td>
</tr>
</table>
<br/>
<br/>
<table class="table table-condensed">
<thead>
<tr>
<th style=" border: 1px solid gray; padding: 1px; font-size:0.8em;background-color: white;color: black;width:15%;text-align:center;">
<table class="table table-condensed" style="width:100%">
<thead style="width:100%;">
<tr style="width:100%;">
<th style="border: 1px solid gray; padding: 1px; font-size:0.8em;background-color: white;color: black;width:10%;text-align:center;">
التاريخ
</th>
<th style=" border: 1px solid gray; padding: 1px; font-size:0.8em;background-color: white;color: black;width:15%;text-align:center;">
<th style="border: 1px solid gray; padding: 1px; font-size:0.8em;background-color: white;color: black;width:10%;text-align:center;">
اليوم
</th>
<th style=" border: 1px solid gray; padding: 1px; font-size:0.8em;background-color: white;color: black;width:5%;text-align:center;">
وقت الدخول
</th>
<th style=" border: 1px solid gray; padding: 1px;font-size:0.8em;background-color: white;color: black;width:15%;text-align:center;">
<th style=" border: 1px solid gray; padding: 1px;font-size:0.8em;background-color: white;color: black;width:5%;text-align:center;">
وفت الخروج
</th>
<th style=" border: 1px solid gray; padding: 1px;font-size:0.8em;background-color: white;color: black;width:20%;text-align:center;">
تأخير
<th style=" border: 1px solid gray; padding: 1px;font-size:0.8em;background-color: white;color: black;width:5%;text-align:center;">
التأخير
</th>
<th style=" border: 1px solid gray; padding: 1px;font-size:0.8em;background-color: white;color: black;width:20%;text-align:center;">
إنصراف مبكر
<th style=" border: 1px solid gray; padding: 1px;font-size:0.8em;background-color: white;color: black;width:5%;text-align:center;">
التفصير
</th>
<th style=" border: 1px solid gray; padding: 1px;font-size:0.8em;background-color: white;color: black;width:5%;text-align:center;">
الاضافى
</th>
<th style=" border: 1px solid gray; padding: 1px;font-size:0.8em;background-color: white;color: black;width:10%;text-align:center;">
ساعات العمل
</th>
<th style=" border: 1px solid gray; padding: 1px;font-size:0.8em;background-color: white;color: black;width:30%;text-align:center;">
ملاحظة
</th>
<th style=" border: 1px solid gray; padding: 1px;font-size:0.8em;background-color: white;color: black;width:15%;text-align:center;">
ملاحظة
الوردية
</th>
</tr>
</thead>
<tbody>
<t t-foreach="data[key]" t-as="line">
<tr>
<td style="border: 1px solid gray;padding: 1px; width:15%;font-size:0.8em;background-color: white;color: black; text-align:center">
<td style="border: 1px solid gray;padding: 1px; width:10%;font-size:0.8em;background-color: white;color: black; text-align:center">
<t t-esc="line['date']"/>
</td>
<td style="border: 1px solid gray;padding: 1px;font-size:0.8em;background-color: white;color: black;width:15%;text-align:center">
<t t-esc="'%02d:%02d' % (int(str(line['sig_in']).split('.')[0]), int(float(str('%.2f' % line['sig_in']).split('.')[1])/100*60))"/>
<td style="border: 1px solid gray;padding: 1px;font-size:0.8em;background-color: white;color: black;width:10%;text-align:center">
<t t-esc="line['day']"/>
</td>
<td style="border-right: 1px solid gray;padding: 1px;font-size:0.8em;background-color: white;color: black;width:20%;text-align:center">
<td style="border-right: 1px solid gray;padding: 1px;font-size:0.8em;background-color: white;color: black;width:5%;text-align:center">
<t t-esc= "'%02d:%02d' % (int(str(line['sig_in']).split('.')[0]), int(float(str('%.2f' % line['sig_in']).split('.')[1])/100*60))"/>
</td>
<td style="border-right: 1px solid gray;padding: 1px;font-size:0.8em;background-color: white;color: black;width:5%;text-align:center">
<t t-esc= "'%02d:%02d' % (int(str(line['sig_out']).split('.')[0]), int(float(str('%.2f' % line['sig_out']).split('.')[1])/100*60))"/>
</td>
<td style="border: 1px solid gray;padding: 1px;font-size:0.8em;background-color: white;color: black;width:20%;text-align:center">
<td style="border: 1px solid gray;padding: 1px;font-size:0.8em;background-color: white;color: black;width:5%;text-align:center">
<t t-esc="'%02d:%02d' % (int(str(line['lateness']).split('.')[0]), int(float(str('%.2f' % line['lateness']).split('.')[1])/100*60))"/>
</td>
<td style="border: 1px solid gray;padding: 1px;font-size:0.8em;background-color: white;color: black;width:15%;text-align:center">
<td style="border: 1px solid gray;padding: 1px;font-size:0.8em;background-color: white;color: black;width:5%;text-align:center">
<t t-esc="'%02d:%02d' % (int(str(line['early_exit']).split('.')[0]), int(float(str('%.2f' % line['early_exit']).split('.')[1])/100*60))"/>
</td>
<td style="border: 1px solid gray; ;color:white;width:15%">.</td>
<td style="border: 1px solid gray;padding: 1px;font-size:0.8em;background-color: white;color: black;width:5%;text-align:center">
<t t-esc="'%02d:%02d' % (int(str(line['extra_hours']).split('.')[0]), int(float(str('%.2f' % line['extra_hours']).split('.')[1])/100*60))"/>
</td>
<td style="border: 1px solid gray;padding: 1px;font-size:0.8em;background-color: white;color: black;width:10%;text-align:center">
<t t-esc="'%02d:%02d' % (int(str(line['office_hours']).split('.')[0]), int(float(str('%.2f' % line['office_hours']).split('.')[1])/100*60))"/>
</td>
<td style="border: 1px solid gray;padding: 1px;font-size:0.8em;background-color: white;color: black;width:30%;text-align:center">
<t t-esc="line['note']"/>
</td>
<td style="border: 1px solid gray;padding: 1px;font-size:0.8em;background-color: white;color: black;width:15%;text-align:center">
<t t-esc="line['calendar_id']"/>
</td>
</tr>
</t>
</tbody>
<tr>
<td style="border-bottom: 1px solid white; ;color:white">.</td>
</tr>
<tfoot style="display:table-row-group;">
<tr>
<td colspan="6" style="border-bottom: 1px solid gray;padding: 1px;font-size:0.8em;background-color: white;color: black;text-align:center;">المجموع</td>
</tr>
</table>
<table class="table table-condensed" style="width:100%">
<tr>
<td style="border: 1px solid gray;padding: 1px;font-size:0.8em;background-color: white;color: black;text-align:center;">
مجموع التأخيرات
مجموع التأخير والتقصير
</td>
<td style=" border: 1px solid gray;padding: 1px;font-size:0.8em;background-color: white;color: black;text-align:center;">
<t t-esc="total[key]['total_lateness']" />
</td>
<td style=" border: 1px solid gray;padding: 1px;font-size:0.8em;background-color: white;color: black;text-align:center;">
مجموع الخروج المبكر
<t t-esc="total[key]['total_late_early']" />
</td>
<td style=" border: 1px solid gray;padding: 1px;font-size:0.8em;background-color: white;color: black;text-align:center;">
<t t-esc="total[key]['total_early_exit']" />
</td>
<td style=" border: 1px solid gray;padding: 1px;font-size:0.8em;background-color: white;color: black;text-align:center;">
الغيابات
اجمالى ايام الغياب
</td>
<td style=" border: 1px solid gray;padding: 1px;font-size:0.8em;background-color: white;color: black;text-align:center;">
<t t-esc="total[key]['total_absent']" />
</td>
</tr>
<tr>
<td colspan="2" style=" border: 1px solid gray; padding: 1px;font-size:0.8em;background-color: white;color: black;text-align:center;">
عدم تسجيل دخول
<td style=" border: 1px solid gray; padding: 1px;font-size:0.8em;background-color: white;color: black;text-align:center;">
اجمالى الاضافى
</td>
<td style=" border: 1px solid gray;padding: 1px;font-size:0.8em;background-color: white;color: black;text-align:center;">
<t t-esc="total[key]['total_not_sig_in']"/>
<t t-esc="total[key]['total_extra_hours']"/>
</td>
<td colspan="2" style=" border: 1px solid gray;padding: 1px;font-size:0.8em;background-color: white;color: black;text-align:center;">
عدم تسجيل خروج
<td style=" border: 1px solid gray;padding: 1px;font-size:0.8em;background-color: white;color: black;text-align:center;">
اجمالى الاجازات والانتدابات
</td>
<td style=" border: 1px solid gray;padding: 1px;font-size:0.8em;background-color: white;color: black;text-align:center;">
<t t-esc="total[key]['total_not_sig_out']"/>
<t t-esc="total[key]['total_leave']"/>
</td>
</tr>
</tfoot>
</table>
</t>
<table style="width:100%;float:center">
<tr style="width:100%;">
<td style="width:50%;color:black;text-align:center"><t t-esc="print_date"/></td>
<td style="width:50%;color:black;text-align:center"><t t-esc="print_user"/></td>
</tr>
</table>
</div>
</template>
<template id="general_attendances_report_temp">

View File

@ -4,7 +4,7 @@ import collections
import datetime
from odoo import api, fields, models, _
week_dayS_arabic={0:"الاثنين", 1: 'الثلاثاء', 4:'Friday' , 2:'الاربعاء',3: 'الخميس', 6:'الاحد',5: 'السبت'}
class AttendancesReport(models.TransientModel):
_name = "employee.attendance.report"
_description = "Employee Attendance Report"
@ -77,23 +77,54 @@ class ReportAttendancePublic(models.AbstractModel):
domain.append(('employee_id', 'in', last_employee_ids))
attendance_transaction_ids = self.env['hr.attendance.transaction'].search(domain)
employees = attendance_transaction_ids.mapped('employee_id.name')
employee_ids = attendance_transaction_ids.mapped('employee_id')
emp_data=[]
for emp in employee_ids:
emp_data.append({'job': emp.sudo().job_id.name, 'department': emp.department_id.name,
'emp_no': emp.emp_no,'emp_namw':emp.name})
grouped_data = collections.defaultdict(list)
emp_data_dict={}
for item in emp_data:
grouped_data[item['emp_namw']].append(item)
for key,value in grouped_data.items():
emp_data_dict[key]=list(value)
if type == 'late':
for resource in attendance_transaction_ids:
note=''
if resource.is_absent:
note='غياب'
elif resource.public_holiday:
note=resource.public_holiday_id.official_event_id.name
elif resource.official_id:
note = resource.official_id.official_event_id.name
elif resource.normal_leave:
note = resource.leave_id.name
elif resource.approve_personal_permission:
note = resource.personal_permission_id.name
data.append({
'date': resource.date,
'day': week_dayS_arabic[resource.date.weekday()],
'sig_in': resource.sign_in,
'sig_out': resource.sign_out,
'lateness': resource.lateness,
'early_exit': resource.early_exit,
'extra_hours': resource.additional_hours,
'office_hours':resource.office_hours,
'note':note,
'department':resource.employee_id.department_id.name,
'employee_number':resource.employee_number,
'calendar_id':resource.calendar_id.name,
'employee_id': resource.employee_id,
'employee_name': resource.employee_id.name,
})
for emp in employees:
list_cat = attendance_transaction_ids.filtered(lambda r: r.employee_id.name == emp)
total_lateness = sum(list_cat.mapped('lateness'))
total_lateness = str(datetime.timedelta(minutes=total_lateness))
total_early_exit = sum(list_cat.mapped('early_exit'))
total_early_exit = str(datetime.timedelta(minutes=total_early_exit))
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_absent = attendance_transaction_ids.filtered(
lambda r: r.employee_id.name == emp and r.is_absent == True)
total_absent = len(list_absent)
@ -102,9 +133,12 @@ class ReportAttendancePublic(models.AbstractModel):
total_not_sig_in = len(list_not_log_in)
list_not_log_out = attendance_transaction_ids.filtered(
lambda r: r.employee_id.name == emp and r.sign_out == 0.0)
list_leave = attendance_transaction_ids.filtered(
lambda r: r.employee_id.name == emp and (r.public_holiday or r.official_id or r.normal_leave or r.approve_personal_permission ))
total_not_sig_out = len(list_not_log_out)
total_leave = len(list_leave)
total_dic[emp] = {'total_lateness': total_lateness, 'total_early_exit': total_early_exit,
'total_absent': total_absent, 'total_not_sig_in': total_not_sig_in,
"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}
grouped = collections.defaultdict(list)
for item in data:
@ -113,7 +147,7 @@ class ReportAttendancePublic(models.AbstractModel):
final_dic[key] = list(value)
key_list.append(key)
mykey = list(dict.fromkeys(key_list))
return final_dic, mykey, total_dic
return final_dic, mykey,total_dic,emp_data_dict
elif type == 'absent':
for resource in attendance_transaction_ids.filtered(lambda r: r.is_absent == True):
data.append({
@ -140,14 +174,16 @@ class ReportAttendancePublic(models.AbstractModel):
total_dic[emp] = {'total_lateness': total_lateness, 'total_early_exit': total_early_exit}
key_list.append(emp)
mykey = list(dict.fromkeys(key_list))
print("mk",mykey,total_dic)
return '', mykey, total_dic
@api.model
def _get_report_values(self, docids, data=None):
final_dic, mykey, total = self.get_value(data)
final_dic, mykey, total,emp_data = self.get_value(data)
start_date = data['form']['from_date']
end_date = data['form']['to_date']
type = data['form']['type']
print("dataa",mykey,final_dic)
return {
'doc_ids': data['ids'],
'doc_model': data['model'],
@ -156,7 +192,11 @@ class ReportAttendancePublic(models.AbstractModel):
'type': type,
'data': final_dic,
'mykey': mykey,
'emp_data':emp_data,
'total': total,
'print_date':datetime.datetime.now().strftime("%H:%m %m/%d/%Y" ),
'print_user':self.env.user.name
}