This commit is contained in:
gsinghpal
2026-03-09 15:21:22 -04:00
parent a3e85a23ef
commit acd3fc455e
243 changed files with 20459 additions and 4197 deletions

View File

@@ -360,7 +360,7 @@ class HrAttendance(models.Model):
('x_fclk_enable_clock', '=', True),
])
template = self.env.ref('fusion_clock.mail_template_weekly_summary', raise_if_not_found=False)
company_email = self.env.company.email or ''
for emp in employees:
if not emp.work_email:
@@ -373,35 +373,66 @@ class HrAttendance(models.Model):
('check_out', '!=', False),
])
total_net = sum(a.x_fclk_net_hours or 0 for a in atts)
total_ot = sum(a.x_fclk_overtime_hours or 0 for a in atts)
penalties = self.env['fusion.clock.penalty'].sudo().search_count([
total_net = round(sum(a.x_fclk_net_hours or 0 for a in atts), 1)
total_ot = round(sum(a.x_fclk_overtime_hours or 0 for a in atts), 1)
penalty_count = self.env['fusion.clock.penalty'].sudo().search_count([
('employee_id', '=', emp.id),
('date', '>=', week_start),
('date', '<=', week_end),
])
ActivityLog = self.env['fusion.clock.activity.log'].sudo()
absences = ActivityLog.search_count([
absence_count = ActivityLog.search_count([
('employee_id', '=', emp.id),
('log_type', '=', 'absent'),
('log_date', '>=', datetime.combine(week_start, datetime.min.time())),
('log_date', '<', datetime.combine(week_end + timedelta(days=1), datetime.min.time())),
])
if template:
try:
template.with_context(
week_start=week_start,
week_end=week_end,
total_hours=round(total_net, 1),
overtime_hours=round(total_ot, 1),
penalty_count=penalties,
absence_count=absences,
streak=emp.x_fclk_ontime_streak,
).send_mail(emp.id, force_send=False)
except Exception as e:
_logger.error("Fusion Clock: Failed to send weekly summary to %s: %s", emp.name, e)
streak = emp.x_fclk_ontime_streak or 0
def _row(label, value, bg=False):
bg_style = 'background:#f8f9fa;' if bg else ''
return (
f'<tr style="{bg_style}">'
f'<td style="padding:10px 14px;border:1px solid #e0e0e0;font-weight:600;">{label}</td>'
f'<td style="padding:10px 14px;border:1px solid #e0e0e0;">{value}</td>'
f'</tr>'
)
body = (
'<div style="margin:0;padding:0;font-family:Arial,Helvetica,sans-serif;">'
'<table width="600" style="margin:0 auto;background:#ffffff;border:1px solid #e0e0e0;border-radius:8px;overflow:hidden;">'
'<tr><td style="padding:24px 32px;background:#1a1d23;border-radius:8px 8px 0 0;">'
'<h2 style="color:#10B981;margin:0;">Fusion Clock</h2>'
'<p style="color:#9ca3af;margin:4px 0 0;">Weekly Summary</p>'
'</td></tr>'
'<tr><td style="padding:24px 32px;">'
f'<p>Hello <strong>{emp.name}</strong>,</p>'
f'<p>Here is your attendance summary for <strong>{week_start}</strong> to <strong>{week_end}</strong>:</p>'
'<table width="100%" style="margin:16px 0;border-collapse:collapse;">'
+ _row('Total Hours', f'{total_net}h', True)
+ _row('Overtime', f'{total_ot}h', False)
+ _row('Penalties', str(penalty_count), True)
+ _row('Absences', str(absence_count), False)
+ _row('On-Time Streak', f'{streak} days', True)
+ '</table>'
'<p>Log in to <a href="/my/clock" style="color:#10B981;">your portal</a> to view details.</p>'
'<p style="color:#6b7280;font-size:12px;margin-top:16px;">This is an automated message from Fusion Clock.</p>'
'</td></tr></table></div>'
)
try:
mail = self.env['mail.mail'].sudo().create({
'subject': f'Your Weekly Attendance Summary ({week_start} - {week_end})',
'email_from': company_email,
'email_to': emp.work_email,
'body_html': body,
'auto_delete': True,
})
mail.send()
except Exception as e:
_logger.error("Fusion Clock: Failed to send weekly summary to %s: %s", emp.name, e)
@api.model
def _fclk_notify_office(self, office_user_id, summary, note, res_model, res_id):