Initial roborto accounting implementation
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
"""Branded business-letter PDF renderer."""
|
||||
from html import escape
|
||||
from pathlib import Path
|
||||
|
||||
from reportlab.lib.units import mm
|
||||
from reportlab.platypus import Paragraph,Spacer,Table,TableStyle
|
||||
|
||||
from roborto_accounting.persistence.models import BusinessLetter,BusinessSettings
|
||||
from roborto_accounting.reporting.documents.theme import DocumentTheme
|
||||
|
||||
def render_letter_pdf(path:Path,*,letter:BusinessLetter,settings:BusinessSettings,theme:DocumentTheme)->Path:
|
||||
contact=[value for value in (settings.postal_address,settings.general_email,settings.website,settings.telephone) if value]
|
||||
recipient="<br/>".join(escape(value) for value in (letter.recipient_name,*letter.recipient_address.splitlines(),letter.recipient_email) if value)
|
||||
story=theme.header(contact)
|
||||
story.extend([Paragraph(letter.letter_date.strftime("%d %B %Y"),theme.body),Spacer(1,10*mm),Paragraph("TO",theme.section),Paragraph(recipient,theme.body),Spacer(1,10*mm)])
|
||||
if letter.reference:story.extend([Paragraph("REFERENCE",theme.section),Paragraph(escape(letter.reference),theme.body),Spacer(1,4*mm)])
|
||||
story.extend([Paragraph("SUBJECT",theme.section),Paragraph(f"<b>{escape(letter.subject)}</b>",theme.body),Spacer(1,9*mm)])
|
||||
for block in letter.body_text.split("\n\n"):
|
||||
story.extend([Paragraph(escape(block).replace("\n","<br/>"),theme.body),Spacer(1,5*mm)])
|
||||
sender=settings.trading_name or "roborto"
|
||||
story.extend([Spacer(1,4*mm),Paragraph("Kind regards,",theme.body),Spacer(1,5*mm),Paragraph(f"<b>{escape(sender)}</b>",theme.body)])
|
||||
if settings.business_descriptor:story.append(Paragraph(escape(settings.business_descriptor),theme.body))
|
||||
return theme.build(path,story)
|
||||
Reference in New Issue
Block a user