diff --git a/pyinvoice/models.py b/pyinvoice/models.py index 49bbf5e..7a4d171 100644 --- a/pyinvoice/models.py +++ b/pyinvoice/models.py @@ -139,7 +139,7 @@ class Transaction(object): :param transaction_datetime: :type transaction_datetime: date or datetime or str or unicode :param amount: $$ - :type amount: int or str or unicode + :type amount: int or float or str or unicode :return: """ self.gateway = gateway diff --git a/pyinvoice/templates.py b/pyinvoice/templates.py index 99df5ad..bd0b0c4 100644 --- a/pyinvoice/templates.py +++ b/pyinvoice/templates.py @@ -249,8 +249,7 @@ class SimpleInvoice(SimpleDocTemplate): if item_data: self._story.append(TableWithHeader(item_data, horizontal_align='LEFT', style=style)) - def _build_transactions(self): - # Transaction + def _transactions_data(self): transaction_table_data = [ ( t.transaction_id, @@ -261,10 +260,16 @@ class SimpleInvoice(SimpleDocTemplate): ] if transaction_table_data: - self._story.append( - Paragraph('Transaction', self._defined_styles.get('Heading1')) - ) transaction_table_data.insert(0, ('Transaction id', 'Gateway', 'Transaction date', 'Amount')) + + return transaction_table_data + + def _build_transactions(self): + # Transaction + transaction_table_data = self._transactions_data() + + if transaction_table_data: + self._story.append(Paragraph('Transaction', self._defined_styles.get('Heading1'))) self._story.append(TableWithHeader(transaction_table_data, horizontal_align='LEFT')) def _build_bottom_tip(self): diff --git a/tests/test_templates.py b/tests/test_templates.py index e355e95..d6db30d 100644 --- a/tests/test_templates.py +++ b/tests/test_templates.py @@ -251,4 +251,29 @@ class TestSimpleInvoice(unittest.TestCase): invoice.finish() - self.assertTrue(os.path.exists(invoice_path)) \ No newline at end of file + self.assertTrue(os.path.exists(invoice_path)) + + def test_transaction(self): + invoice_path = os.path.join(self.file_base_dir, 'transaction.pdf') + if os.path.exists(invoice_path): + os.remove(invoice_path) + + invoice = SimpleInvoice(invoice_path) + + transaction_data = invoice._transactions_data() + self.assertEqual(transaction_data, []) + + invoice.add_transaction(Transaction('A', 1, date.today(), 9.9)) + invoice.add_transaction(Transaction('B', 3, date(2015, 6, 1), 3.3)) + + transaction_data = invoice._transactions_data() + self.assertEqual(len(transaction_data), 3) + self.assertEqual(transaction_data[0][0], 'Transaction id') + self.assertEqual(transaction_data[1][3], 9.9) + self.assertEqual(transaction_data[2][0], 3) + self.assertEqual(transaction_data[2][2], '2015-06-01') + self.assertEqual(transaction_data[2][3], 3.3) + + invoice.finish() + + self.assertTrue(os.path.exists(invoice_path))