Merge pull request #3361 from expsa/hr_rep_mod

emp reporttt
This commit is contained in:
eslamtalaat744 2025-05-29 17:09:02 +03:00 committed by GitHub
commit ee5308bd1b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 304 additions and 47 deletions

View File

@ -357,16 +357,24 @@
</template>
<template id="totals_only_attendance_report_template">
<div class="page" style="font-size:12pt" dir="rtl">
<style>
@page {
size: A4 landscape;
margin: 0.5cm;
}
body, .page {
width: 100%;
}
</style>
<!-- <div class="page" style="font-size:12pt" dir="rtl">-->
<!-- print-orientation="landscape"-->
<!-- &lt;!&ndash; print-orientation="landscape" &ndash;&gt;-->
<style>
@page {
size: A4 landscape;
margin: 0.5cm;
}
</style>
<div class="page" style="font-size:12pt;"
dir="rtl"
>
<!-- print-orientation="landscape"-->
<!-- t-att-data-report-orientation="'landscape'"-->
<center>
<h2 style="font-weight:bold">تقرير الحضور والانصراف للموظفين</h2>
</center>
@ -459,10 +467,12 @@
font-family: ae_AlMohanad;
}
</style>
<t t-if="totals_only">
<t t-call="attendances.totals_only_attendance_report_template"/>
</t>
<t t-else="">
<!-- <t t-if="totals_only">-->
<!-- <t t-call="attendances.totals_only_attendance_report_template"/>-->
<!-- </t>-->
<!-- <t t-else="">-->
<t t-if="type == 'late'">
<t t-call="attendances.late_attendance_report_template"/>
</t>
@ -473,41 +483,41 @@
<t t-call="attendances.employee_attendance_report_template"/>
</t>
</t>
<!-- </t>-->
</t>
</template>
<template id="general_attendances_report_temp_land">
<t t-call="web.html_container">
<t t-call="web.external_layout">
<style type="text/css">
@font-face {
font-family: 'ae_AlMohanad';
src: local('ae_AlMohanad'), local('ae_AlMohanad'),
url('/attendances/static/fonts/ae_AlMohanad.ttf') format('truetype');
}
*{
font-family: ae_AlMohanad;
}
</style>
<!-- <t t-if="totals_only">-->
<t t-call="attendances.totals_only_attendance_report_template"/>
<!-- </t>-->
</t>
</t>
</template>
<!-- <template id="general_attendances_report_temp_land">-->
<!-- <t t-call="web.html_container">-->
<!-- <t t-call="web.external_layout">-->
<!-- <style type="text/css">-->
<!-- @font-face {-->
<!-- font-family: 'ae_AlMohanad';-->
<!-- src: local('ae_AlMohanad'), local('ae_AlMohanad'),-->
<!-- url('/attendances/static/fonts/ae_AlMohanad.ttf') format('truetype');-->
<!-- }-->
<!-- *{-->
<!-- font-family: ae_AlMohanad;-->
<!-- }-->
<!-- </style>-->
<!-- &lt;!&ndash; <t t-if="totals_only">&ndash;&gt;-->
<!-- <t t-call="attendances.totals_only_attendance_report_template"/>-->
<!-- &lt;!&ndash; </t>&ndash;&gt;-->
<record id="action_totals_only_attendance_reportt" model="ir.actions.report">
<field name="model">employee.attendance.report</field>
<field name="name">Attendance Report</field>
<field name="report_type">qweb-pdf</field>
<field name="report_name">attendances.general_attendances_report_temp_land</field>
<field name="paperformat_id" ref="attendances.paperformat_attendance_landscapee"/>
<!-- </t>-->
<!-- </t>-->
<!-- </template>-->
<!-- <record id="action_totals_only_attendance_reportt" model="ir.actions.report">-->
<!-- <field name="model">employee.attendance.report</field>-->
<!-- <field name="name">Attendance Report</field>-->
<!-- <field name="report_type">qweb-pdf</field>-->
<!-- <field name="report_name">attendances.general_attendances_report_temp_land</field>-->
<!-- <field name="paperformat_id" ref="attendances.paperformat_attendance_landscapee"/>-->
<!-- </record>-->
</record>
<record id="action_general_attendance_reportt" model="ir.actions.report">

View File

@ -62,10 +62,11 @@ class AttendancesReport(models.TransientModel):
def print_report(self):
if not self.employee_ids:
raise ValidationError(_("Please select Employees Name"))
# if self.print_totals_only == True:
# return self.env.ref("attendances.action_totals_only_attendance_reportt").report_action(self, data=self._payload())
# else:
return self.env.ref("attendances.action_general_attendance_reportt").report_action(self, data=self._payload())
if self.print_totals_only == True:
print("hhhhhhhhhhfff")
return self.env.ref("attendances.action_totals_only_attendance_reportt").report_action(self, data=self._payload())
else:
return self.env.ref("attendances.action_general_attendance_reportt").report_action(self, data=self._payload())
@ -232,6 +233,7 @@ class ReportAttendancePublic(models.AbstractModel):
domain.append(('employee_id', 'in', rc.employee_ids.ids))
att = self.env['hr.attendance.transaction'].search(domain)
print("1111111111111")
for emp in att.mapped('employee_id'):
# lines = att.filtered(lambda l, e=emp: l.employee_id == e)
@ -287,6 +289,251 @@ class ReportAttendancePublic(models.AbstractModel):
'early_exit_approved': hhmm(sum(row['early_exit_approved_int'] for row in summary_rows)),
})
print("222222222")
print(summary_totals)
print(data['model'])
return {
'doc_ids': data['ids'],
'doc_model': data['model'],
'date_start': start_date,
'date_end': end_date,
'type': type_,
'data': final_dic,
'mykey': mykey,
'emp_data': emp_data,
'total': total,
'summary': summary_rows,
'summary_totals': summary_totals,
'totals_only': totals_only,
'print_date': datetime.datetime.now().strftime("%H:%M %m/%d/%Y"),
'print_user': self.env.user.name,
}
class ReportAttendancegeneral(models.AbstractModel):
_name = "report.attendances.general_attendances_report_temp_land"
_description = "General Attendances Report"
def get_value(self, data):
type = data['form']['type']
totals_only = data["form"].get("print_totals_only", False)
employee_ids = data['form']['employee_ids']
resource_calender_id = data['form']['resource_calender_id']
from_date = data['form']['from_date']
to_date = data['form']['to_date']
domain = [('date', '>=', from_date), ('date', '<=', to_date)]
data = []
final_dic = {}
key_list = []
total_dic = {}
mykey = []
resource = self.env['resource.calendar'].browse(resource_calender_id)
if resource and not employee_ids:
if resource.employee_ids:
for emp in resource.employee_ids:
employee_ids.append(emp.id)
# if resource_calender_id:
# contract_ids = self.env['hr.contract'].search([('state', '=', 'program_directory'), ('resource_calendar_id', '=', resource_calender_id)])
# for con in contract_ids:
# employee_ids.append(con.employee_id.id)
# print(">>>>>>>>>>>>>>>>>>>>>>>employeesemployees",employees)
if employee_ids:
last_employee_ids = list(set(employee_ids))
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 = "عطلة رسمية"
elif resource.official_id:
note = resource.official_id.mission_type.name
elif resource.normal_leave:
note = resource.leave_id.holiday_status_id.name
elif resource.approve_personal_permission:
note = resource.personal_permission_id.permission_type_id.name
data.append({
'date': resource.date,
'day': WEEK_DAYS_AR[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,
})
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)
total_lateness = sum(list_cat.mapped('lateness'))
total_early_exit = sum(list_cat.mapped('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)
list_not_log_in = attendance_transaction_ids.filtered(
lambda r: r.employee_id.name == emp and r.sign_in == 0.0)
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.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_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:
grouped[item['employee_name']].append(item)
for key, value in grouped.items():
final_dic[key] = list(value)
key_list.append(key)
mykey = list(dict.fromkeys(key_list))
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({
'date': resource.date,
'employee_name': resource.employee_id.name,
'employee_id_department_id_name': resource.employee_id.department_id.name,
'day': datetime.datetime.strptime(str(resource.date), '%Y-%m-%d').date().strftime('%A'),
})
grouped = collections.defaultdict(list)
for item in data:
grouped[item['employee_id_department_id_name']].append(item)
for key, value in grouped.items():
final_dic[key] = list(value)
key_list.append(key)
mykey = list(dict.fromkeys(key_list))
return final_dic, mykey, '', emp_data_dict
elif type == 'employee':
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_dic[emp] = {'total_lateness': total_lateness, 'total_early_exit': total_early_exit}
key_list.append(emp)
mykey = list(dict.fromkeys(key_list))
return '', mykey, total_dic, emp_data_dict
@api.model
def _get_report_values(self, docids, data=None):
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']
totals_only = data['form'].get('print_totals_only', False)
summary_rows = []
summary_totals = []
if totals_only:
domain = [('date', '>=', start_date), ('date', '<=', end_date)]
emp_ids = data['form']['employee_ids']
cal_id = data['form']['resource_calender_id']
if emp_ids:
domain.append(('employee_id', 'in', list(set(emp_ids))))
elif cal_id:
rc = self.env['resource.calendar'].browse(cal_id)
domain.append(('employee_id', 'in', rc.employee_ids.ids))
att = self.env['hr.attendance.transaction'].search(domain)
print("1111111111111")
for emp in att.mapped('employee_id'):
# lines = att.filtered(lambda l, e=emp: l.employee_id == e)
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)
lines = emp_att_lines.filtered(lambda l: l.sequence == seq)
all_days = {l.date for l in lines}
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}
iq = getattr(emp, 'iqama_number', False) or getattr(emp, 'saudi_number', '')
summary_rows.append({
'employee_number': emp.emp_no or '',
'name': emp.name,
'seq': seq if seq else '',
'iqama': iq.display_name or '',
'department': emp.department_id.name,
'job': emp.sudo().job_id.name,
'days_present': len(all_days - absent - vacation - holidays),
'leave_days': len(vacation),
'holiday_days': len(holidays),
'absent_days': len(absent),
'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'))),
'mission_hours': hhmm(sum(lines.mapped('total_mission_hours'))),
'lateness_approved': hhmm(sum(lines.filtered(lambda l: l.approve_lateness).mapped('lateness'))),
'early_exit_approved': hhmm(sum(lines.filtered(lambda l: l.approve_exit_out).mapped('early_exit'))),
'office_hours_int': (sum(lines.mapped('office_hours'))),
'extra_hours_int': (sum(lines.mapped('additional_hours'))),
'permission_hours_int': (sum(lines.mapped('total_permission_hours'))),
'mission_hours_int': (sum(lines.mapped('total_mission_hours'))),
'lateness_approved_int': (sum(lines.filtered(lambda l: l.approve_lateness).mapped('lateness'))),
'early_exit_approved_int': (sum(lines.filtered(lambda l: l.approve_exit_out).mapped('early_exit'))),
})
summary_totals.append({
'days_present': sum(row['days_present'] for row in summary_rows),
'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),
'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)),
'mission_hours': hhmm(sum(row['mission_hours_int'] for row in summary_rows)),
'lateness_approved':hhmm( sum(row['lateness_approved_int'] for row in summary_rows)),
'early_exit_approved': hhmm(sum(row['early_exit_approved_int'] for row in summary_rows)),
})
print("222222222")
print(summary_totals)
print(data['model'])