changes
This commit is contained in:
@@ -170,17 +170,79 @@ class FusionClockReport(models.Model):
|
||||
})
|
||||
|
||||
def _send_report_email(self):
|
||||
"""Send the report via mail template."""
|
||||
"""Send the report with the PDF attached."""
|
||||
self.ensure_one()
|
||||
if self.employee_id:
|
||||
template = self.env.ref('fusion_clock.mail_template_clock_employee_report', raise_if_not_found=False)
|
||||
else:
|
||||
template = self.env.ref('fusion_clock.mail_template_clock_batch_report', raise_if_not_found=False)
|
||||
company_email = self.company_id.email or ''
|
||||
|
||||
if template:
|
||||
template.send_mail(self.id, force_send=True)
|
||||
if self.employee_id:
|
||||
email_to = self.employee_id.work_email or ''
|
||||
subject = f"Your Attendance Report - {self.date_start} to {self.date_end}"
|
||||
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;">'
|
||||
'<h2 style="color:#10B981;margin:0;">Fusion Clock</h2>'
|
||||
'<p style="color:#9ca3af;margin:4px 0 0;">Attendance Report</p>'
|
||||
'</td></tr><tr><td style="padding:24px 32px;">'
|
||||
f'<p>Hello <strong>{self.employee_id.name}</strong>,</p>'
|
||||
f'<p>Your attendance report for <strong>{self.date_start}</strong> to '
|
||||
f'<strong>{self.date_end}</strong> is ready.</p>'
|
||||
'<table width="100%" style="margin:16px 0;border-collapse:collapse;">'
|
||||
f'<tr style="background:#f8f9fa;"><td style="padding:10px 14px;border:1px solid #e0e0e0;font-weight:600;">Days Worked</td>'
|
||||
f'<td style="padding:10px 14px;border:1px solid #e0e0e0;">{self.days_worked}</td></tr>'
|
||||
f'<tr><td style="padding:10px 14px;border:1px solid #e0e0e0;font-weight:600;">Total Hours</td>'
|
||||
f'<td style="padding:10px 14px;border:1px solid #e0e0e0;">{self.total_hours:.1f}h</td></tr>'
|
||||
f'<tr style="background:#f8f9fa;"><td style="padding:10px 14px;border:1px solid #e0e0e0;font-weight:600;">Net Hours</td>'
|
||||
f'<td style="padding:10px 14px;border:1px solid #e0e0e0;">{self.net_hours:.1f}h</td></tr>'
|
||||
f'<tr><td style="padding:10px 14px;border:1px solid #e0e0e0;font-weight:600;">Total Breaks</td>'
|
||||
f'<td style="padding:10px 14px;border:1px solid #e0e0e0;">{self.total_breaks:.0f} min</td></tr>'
|
||||
'</table>'
|
||||
'<p>The full PDF report is attached.</p>'
|
||||
'<p style="color:#6b7280;font-size:12px;margin-top:16px;">This is an automated message from Fusion Clock.</p>'
|
||||
'</td></tr></table></div>'
|
||||
)
|
||||
else:
|
||||
_logger.warning("Fusion Clock: Mail template not found for report %s", self.id)
|
||||
ICP = self.env['ir.config_parameter'].sudo()
|
||||
email_to = ICP.get_param('fusion_clock.report_recipient_emails', '')
|
||||
subject = f"Employee Attendance Batch Report - {self.date_start} to {self.date_end}"
|
||||
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;">'
|
||||
'<h2 style="color:#10B981;margin:0;">Fusion Clock</h2>'
|
||||
'<p style="color:#9ca3af;margin:4px 0 0;">Batch Attendance Report</p>'
|
||||
'</td></tr><tr><td style="padding:24px 32px;">'
|
||||
f'<p>The attendance batch report for <strong>{self.date_start}</strong> to '
|
||||
f'<strong>{self.date_end}</strong> is attached.</p>'
|
||||
'<p>This report includes all employees\' attendance summaries with daily breakdowns, '
|
||||
'total hours, and penalty information.</p>'
|
||||
'<p style="color:#6b7280;font-size:12px;margin-top:16px;">This is an automated message from Fusion Clock.</p>'
|
||||
'</td></tr></table></div>'
|
||||
)
|
||||
|
||||
if not email_to:
|
||||
_logger.warning("Fusion Clock: No email recipient for report %s", self.id)
|
||||
return
|
||||
|
||||
mail_vals = {
|
||||
'subject': subject,
|
||||
'email_from': company_email,
|
||||
'email_to': email_to,
|
||||
'body_html': body,
|
||||
'auto_delete': True,
|
||||
}
|
||||
|
||||
if self.report_pdf:
|
||||
mail_vals['attachment_ids'] = [(0, 0, {
|
||||
'name': self.report_pdf_filename or 'report.pdf',
|
||||
'datas': self.report_pdf,
|
||||
'mimetype': 'application/pdf',
|
||||
})]
|
||||
|
||||
try:
|
||||
self.env['mail.mail'].sudo().create(mail_vals).send()
|
||||
except Exception as e:
|
||||
_logger.error("Fusion Clock: Failed to send report email: %s", e)
|
||||
|
||||
def action_export_csv(self):
|
||||
"""Export the report data as a CSV file for payroll."""
|
||||
|
||||
Reference in New Issue
Block a user