Skip to content

Commit

Permalink
fix(invoice): improve invoice rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
nijel committed Oct 18, 2024
1 parent 4eca23a commit ee1003f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 21 deletions.
17 changes: 11 additions & 6 deletions weblate_web/invoices/templates/invoice-template.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ <h1>Invoice number {{ invoice.number }}</h1>
</header>

<div id="contacts" class="fullwidth">
<address id="to">Invoice to<br/>
<address id="to">
<h2>Invoice to</h2>
{{ invoice.customer.name }}<br/>
{{ invoice.customer.address }}<br/>
{% if invoice.customer.address_2 %}
Expand All @@ -28,12 +29,10 @@ <h1>Invoice number {{ invoice.number }}</h1>
{% if invoice.customer.tax %}
Reg: {{ invoice.customer.tax }}<br/>
{% endif %}
{% if invoice.customer_reference %}
Customer reference: {{ invoice.customer_reference }}<br/>
{% endif %}
</address>

<address id="from">Issued by<br/>
<address id="from">
<h2>Issued by</h2>
Weblate s.r.o<br/>
Nábřežní 694<br/>
471 54 Cvikov<br/>
Expand All @@ -42,6 +41,12 @@ <h1>Invoice number {{ invoice.number }}</h1>
</address>
</div>

{% if invoice.customer_reference %}
<p>
Customer reference: {{ invoice.customer_reference }}
</p>
{% endif %}

<table id="items">
<thead>
<tr>
Expand Down Expand Up @@ -89,7 +94,7 @@ <h1>Invoice number {{ invoice.number }}</h1>
<td>{{ invoice.total_vat_czk }} Kč</td>
<td>{{ invoice.display_total_vat }}</td>
</tr>
<tr>
<tr class="subtotal">
<td>Total including VAT</td>
<td></td>
<td>{{ invoice.total_amount_czk }} Kč</td>
Expand Down
31 changes: 19 additions & 12 deletions weblate_web/invoices/templates/invoice.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ a {
font-size: 11pt;
line-height: 1.6;
}
p {
padding: 0 3mm;
}
h2 {
font-size: 11pt;
margin: 0;
}
body {
margin: 0;
padding: 0;
Expand All @@ -29,7 +36,7 @@ header {

h1 {
font-size: 12pt;
padding-top: 0.3cm;
padding-top: 3mm;
}
header p,
header h1 {
Expand All @@ -45,16 +52,16 @@ img {

.fullwidth {
border-style: solid;
border-width: 0.5cm 1cm;
border-width: 5mm 1cm;
margin: 0 -1cm;
padding: 0;
width: 19cm;
background: #d5f5ee;
border-color: #d5f5ee;
}

#contacts {
display: flex;
background: #e9eaec;
border-color: #e9eaec;
}
address {
font-style: normal;
Expand All @@ -71,15 +78,16 @@ address {
#items {
width: 100%;
border-collapse: collapse;
margin: 0.5cm 0;
margin: 5mm 0;
}
#items th {
font-weight: 400;
}
#items thead {
border-bottom: 0.2mm solid #a9a;
}
#items tfoot {
#items tfoot,
#items .subtotal {
border-top: 0.2mm solid #a9a;
}
#items td:last-of-type {
Expand Down Expand Up @@ -109,10 +117,6 @@ footer {
bottom: 0;
position: absolute;
}
#total {
background: #d5f5ee;
border-color: #d5f5ee;
}
#details td,
#details th,
#total td,
Expand All @@ -124,7 +128,7 @@ footer {
}
footer p,
footer table {
margin-top: 0.5cm;
margin-top: 5mm;
}
footer p,
#details,
Expand All @@ -134,7 +138,10 @@ footer p,
#total strong {
font-size: 18pt;
}
.thanks {
.thanks,
.reference {
color: #1fa385;
}
.thanks {
font-weight: 700;
}
8 changes: 5 additions & 3 deletions weblate_web/invoices/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,26 @@

class InvoiceTestCase(TestCase):
@staticmethod
def create_customer():
def create_customer(vat: str = ""):
return Customer.objects.create(
name="Test customer",
address="Street 42",
city="City",
postcode="424242",
country="cz",
user_id=-1,
vat=vat,
)

def create_invoice(
self,
discount: Discount | None = None,
vat_rate: int = 0,
customer_reference: str = "",
vat: str = "",
):
invoice = Invoice.objects.create(
customer=self.create_customer(),
customer=self.create_customer(vat=vat),
discount=discount,
vat_rate=vat_rate,
kind=InvoiceKindChoices.INVOICE,
Expand All @@ -47,7 +49,7 @@ def validate_invoice(self, invoice: Invoice):
self.assertNotEqual(str(item), "")

def test_total(self):
invoice = self.create_invoice()
invoice = self.create_invoice(vat="CZ8003280318")
self.assertEqual(invoice.total_amount, 100)
self.validate_invoice(invoice)

Expand Down

0 comments on commit ee1003f

Please sign in to comment.