main
Далер 13 hours ago
parent e38e99374a
commit 206ba6983f

@ -76,17 +76,64 @@ class OvertimeReport(models.Model):
def __str__(self):
return f"{self.employee}: {self.overtime} hours on {self.date}"
# PDF Generation for HR Reports
class Report(models.Model):
employee = models.ForeignKey(Employee, on_delete=models.CASCADE)
employee = models.ForeignKey('Employee', on_delete=models.CASCADE)
report_date = models.DateField(auto_now_add=True)
start_date = models.DateField(verbose_name="Начальная дата")
end_date = models.DateField(verbose_name="Конечная дата")
def generate_pdf(self):
buffer = BytesIO()
c = canvas.Canvas(buffer, pagesize=letter)
c.drawString(100, 750, f"Employee: {self.employee.first_name} {self.employee.last_name}")
c.drawString(100, 730, f"Date: {self.report_date}")
c.setFont("Helvetica-Bold", 16)
c.drawString(100, 750, f"Отчет по сотруднику: {self.employee.first_name} {self.employee.last_name}")
c.setFont("Helvetica", 12)
c.drawString(100, 730, f"Должность: {self.employee.position}")
c.drawString(100, 710, f"Email: {self.employee.email}")
c.drawString(100, 690, f"Дата найма: {self.employee.hired_date}")
c.drawString(100, 670, f"Период отчета: {self.start_date} - {self.end_date}")
# Рабочее время
work_logs = WorkTimeLog.objects.filter(
employee=self.employee, date__range=(self.start_date, self.end_date)
).order_by('-date')
y = 640
c.setFont("Helvetica-Bold", 14)
c.drawString(100, y, "Рабочее время:")
y -= 20
for log in work_logs:
c.setFont("Helvetica", 12)
c.drawString(100, y, f"{log.date}: {log.check_in} - {log.check_out} (Часы: {log.worked_hours})")
y -= 20
# Отпуска
leaves = Leave.objects.filter(
employee=self.employee, start_date__lte=self.end_date, end_date__gte=self.start_date
).order_by('-start_date')
c.setFont("Helvetica-Bold", 14)
c.drawString(100, y, "Отпуска и больничные:")
y -= 20
for leave in leaves:
c.setFont("Helvetica", 12)
c.drawString(100, y, f"{leave.leave_type.capitalize()}: {leave.start_date} - {leave.end_date} (Причина: {leave.reason})")
y -= 20
# Переработки
overtime_reports = OvertimeReport.objects.filter(
employee=self.employee, date__range=(self.start_date, self.end_date)
).order_by('-date')
c.setFont("Helvetica-Bold", 14)
c.drawString(100, y, "Переработки:")
y -= 20
for report in overtime_reports:
c.setFont("Helvetica", 12)
c.drawString(100, y, f"{report.date}: {report.overtime} ч. (Комментарий: {report.comment})")
y -= 20
c.showPage()
c.save()
buffer.seek(0)
return buffer

@ -953,3 +953,7 @@ RuntimeError: You called this URL via POST, but the URL doesn't end in a slash a
"POST /api/hq/api/contractor-contacts/upload/ HTTP/1.1" 201 55
Watching for file changes with StatReloader
"GET /api/hr/ HTTP/1.1" 200 10827
/home/dark/Documents/GitHub/store-management-system/hr/urls.py changed, reloading.
Watching for file changes with StatReloader
/home/dark/Documents/GitHub/store-management-system/hr/models.py changed, reloading.
Watching for file changes with StatReloader

Loading…
Cancel
Save