Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .gitignore

This file was deleted.

1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ six==1.12.0
sqlparse==0.3.0
webencodings==0.5.1
xhtml2pdf==0.2.3
WeasyPrint==50
25 changes: 14 additions & 11 deletions salaries/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@
from django.template import loader, Context
from django.views.generic import View
from django.utils.text import slugify

from easy_pdf.rendering import render_to_pdf
from .models import Salary

from .models import Salary, TimeRecord
from weasyprint import HTML, CSS
from django.template.loader import render_to_string
from .admin import SalaryAdmin

class SendPayslip(View):
""" send payslip to email
"""
def get(self, *args, **kwargs):
#payroll = get_object_or_404(Salary, **kwargs)

salary = get_object_or_404(Salary, **kwargs)
time_record = TimeRecord.objects.filter(salary=salary)
html = render_to_string('emails/payslip.html',{'salary': salary, 'time_record': time_record})
pdf = HTML(string=html).write_pdf()

pdf = render_to_pdf(
'emails/payslip.html',
{}
)
html_content = "<p>payslip is attached</p>"

msg = EmailMultiAlternatives("Swiftkind Payroll", "payslip is attached", settings.DEFAULT_FROM_EMAIL, ['earvin@swiftkind.com'])
msg = EmailMultiAlternatives("Swiftkind Payroll", "payslip is attached", settings.DEFAULT_FROM_EMAIL, ['erykestabillo@gmail.com'])
msg.attach_alternative(html_content, "text/html")
msg.attach('payslip.pdf', pdf, 'application/pdf')
msg.send()
Expand All @@ -34,8 +34,11 @@ class DownloadPayslip(View):
""" download payslip
"""
def get(self, *args, **kwargs):

salary = get_object_or_404(Salary, **kwargs)
pdf = render_to_pdf('emails/payslip.html', {'salary': salary})
time_record = TimeRecord.objects.filter(salary=salary)
html = render_to_string('emails/payslip.html',{'salary': salary, 'time_record': time_record})
pdf = HTML(string=html).write_pdf()

filename = slugify(f"{salary.user.get_full_name()} {salary.period}")

Expand Down
Loading