Skip to content

Commit

Permalink
Fix invoice pdf export bug. Closes #141.
Browse files Browse the repository at this point in the history
  • Loading branch information
fgaudin committed Mar 2, 2011
1 parent 9b55b80 commit 9aa3616
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def invoice_footer(canvas, doc):
splitted_para = para.breakLines(label_width)
label = " ".join(splitted_para.lines[0][1])
if row.proposal.reference:
label = label + " - [%s]" % (row.proposal.reference)
label = "%s - [%s]" % (label.decode('utf-8'), row.proposal.reference)
data.append([label, localize(row.quantity), localize(row.unit_price), localize(row.quantity * row.unit_price)])
for extra_row in splitted_para.lines[1:]:
label = " ".join(extra_row[1])
Expand Down
32 changes: 32 additions & 0 deletions accounts/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# coding=utf-8
from decimal import Decimal
from django.test.testcases import TransactionTestCase
import datetime
Expand Down Expand Up @@ -1075,6 +1076,37 @@ def testBug96(self):
self.assertEquals(response.status_code, 302)
self.assertEquals(Invoice.objects.get(invoice_id=1).amount, 1100)

def testBug141(self):
"""
Non ascii characters make invoice download crashes
"""
i = Invoice.objects.create(customer_id=self.proposal.project.customer_id,
invoice_id=1,
state=INVOICE_STATE_EDITED,
amount='1000',
edition_date=datetime.date(2010, 8, 31),
payment_date=datetime.date(2010, 9, 30),
paid_date=None,
payment_type=PAYMENT_TYPE_CHECK,
execution_begin_date=datetime.date(2010, 8, 1),
execution_end_date=datetime.date(2010, 8, 7),
penalty_date=datetime.date(2010, 10, 8),
penalty_rate='1.5',
discount_conditions='Néant',
owner_id=1)

i_row = InvoiceRow.objects.create(proposal_id=self.proposal.id,
invoice_id=i.id,
label='Test accent é',
category=ROW_CATEGORY_SERVICE,
quantity=10,
unit_price='100',
balance_payments=False,
owner_id=1)

response = self.client.get(reverse('invoice_download', kwargs={'id': i.id}))
self.assertEqual(response.status_code, 200)

class InvoiceBug106Test(TransactionTestCase):
fixtures = ['test_users', 'test_contacts', 'test_projects']

Expand Down

0 comments on commit 9aa3616

Please sign in to comment.