Skip to content

Commit

Permalink
Merge pull request #168 from Segelzwerg/164-pdf-align-values-on-the-r…
Browse files Browse the repository at this point in the history
…ight

Right align numbers
  • Loading branch information
Segelzwerg authored Nov 29, 2024
2 parents 2b2303d + 909e679 commit d8ee134
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
8 changes: 4 additions & 4 deletions invoice/templates/invoice/invoice_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@
<tr>
<td>{{ item.name }}</td>
<td>{{ item.description }}</td>
<td>{{ item.quantity }}</td>
<td>{{ item.price|floatformat:2 }}</td>
<td>{{ item.tax_string }}</td>
<td>{{ item.total|floatformat:2 }}</td>
<td class="text-end">{{ item.quantity }}</td>
<td class="text-end">{{ item.price|floatformat:2 }}</td>
<td class="text-end">{{ item.tax_string }}</td>
<td class="text-end">{{ item.total|floatformat:2 }}</td>
</tr>
{% endfor %}
</tbody>
Expand Down
4 changes: 2 additions & 2 deletions invoice/templates/invoice/invoice_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
<td>{{ invoice.date }}</td>
<td>{{ invoice.vendor.name }} ({{ invoice.vendor.company_name }})</td>
<td>{{ invoice.customer.first_name }} {{ invoice.customer.last_name }}</td>
<td>{{ invoice.net_total|floatformat:2 }}</td>
<td>{{ invoice.total|floatformat:2 }}</td>
<td class="text-end">{{ invoice.net_total|floatformat:2 }}</td>
<td class="text-end">{{ invoice.total|floatformat:2 }}</td>
<td><a href="/invoice/{{ invoice.id }}/">Update</a> / <a href="/invoice/
{{ invoice.id }}/delete/">Delete</a></td>
</tr>
Expand Down
20 changes: 15 additions & 5 deletions invoice/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.urls import reverse_lazy
from django.views.generic import CreateView, UpdateView, DeleteView, ListView
from django.views.generic import TemplateView
from reportlab.lib import colors
from reportlab.pdfgen import canvas
from reportlab.platypus import Table

Expand Down Expand Up @@ -163,16 +164,25 @@ def pdf_invoice(request, invoice_id) -> FileResponse:
y_steps += 1

data = Invoice.objects.get(id=invoice_id).table_export
table = Table(data=data)
table = Table(
data=data,
style=[
('GRID', (0, 0), (-1, -1), 0.5, colors.grey),
('LEADING', (0, 0), (-1, 0), 10),
('ALIGNMENT', (2, 1), (6, -1), "RIGHT"),
]
)
_, table_height = table.wrapOn(pdf_object, 0, 0)

table_y_start = get_y_position(y_print_start, y_step, y_steps)
table.drawOn(pdf_object, x=100, y=table_y_start - table_height)

pdf_object.drawString(A4_WIDTH - 250, table_y_start - table_height - y_step,
f'Net Total: {invoice.net_total:.2f}')
pdf_object.drawString(A4_WIDTH - 250, table_y_start - table_height - y_step * 2,
f'Total: {invoice.total:.2f}')
pdf_object.drawString(A4_WIDTH - 280, table_y_start - table_height - y_step,'Net Total:')
pdf_object.drawAlignedString(A4_WIDTH - 195, table_y_start - table_height - y_step,f'{invoice.net_total:.2f}')

pdf_object.drawString(A4_WIDTH - 280, table_y_start - table_height - y_step * 2, 'Total:')
pdf_object.drawAlignedString(A4_WIDTH - 195, table_y_start - table_height - y_step * 2, f'{invoice.total:.2f}')

if invoice.vendor.tax_id:
pdf_object.drawString(100, 100, f'Tax ID: {invoice.vendor.tax_id}')
if invoice.vendor.bank_account:
Expand Down

0 comments on commit d8ee134

Please sign in to comment.