Item total
This commit is contained in:
parent
03b18cec2f
commit
b13a80160d
4 changed files with 29 additions and 8 deletions
|
@ -22,17 +22,21 @@ class SimpleTable(Table):
|
||||||
|
|
||||||
|
|
||||||
class TableWithHeader(Table):
|
class TableWithHeader(Table):
|
||||||
def __init__(self, data, horizontal_align=None):
|
def __init__(self, data, horizontal_align=None, style=None):
|
||||||
Table.__init__(self, data, hAlign=horizontal_align)
|
Table.__init__(self, data, hAlign=horizontal_align)
|
||||||
|
|
||||||
style = TableStyle([
|
default_style = [
|
||||||
('INNERGRID', (0, 0), (-1, -1), .25, colors.black),
|
('INNERGRID', (0, 0), (-1, -1), .25, colors.black),
|
||||||
('BOX', (0, 0), (-1, -1), .25, colors.black),
|
('BOX', (0, 0), (-1, -1), .25, colors.black),
|
||||||
('BACKGROUND', (0, 0), (-1, -len(data)), colors.lightgrey),
|
('BACKGROUND', (0, 0), (-1, -len(data)), colors.lightgrey),
|
||||||
('ALIGN', (0, 0), (-1, -1), 'CENTER'),
|
('ALIGN', (0, 0), (-1, -1), 'CENTER'),
|
||||||
('VALIGN', (0, 0), (-1, -1), 'MIDDLE')
|
('VALIGN', (0, 0), (-1, -1), 'MIDDLE')
|
||||||
])
|
]
|
||||||
self.setStyle(style)
|
|
||||||
|
if style and isinstance(style, list):
|
||||||
|
default_style.extend(style)
|
||||||
|
|
||||||
|
self.setStyle(TableStyle(default_style))
|
||||||
|
|
||||||
|
|
||||||
class PaidStamp(object):
|
class PaidStamp(object):
|
||||||
|
|
|
@ -64,7 +64,6 @@ class Item(object):
|
||||||
:param unit_price: Unit price
|
:param unit_price: Unit price
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
# TODO: add vat/tax, subtotal
|
|
||||||
self.item_id = item_id
|
self.item_id = item_id
|
||||||
self.name = name
|
self.name = name
|
||||||
self.description = description
|
self.description = description
|
||||||
|
|
|
@ -42,6 +42,8 @@ class SimpleInvoice(SimpleDocTemplate):
|
||||||
self.client_info = None
|
self.client_info = None
|
||||||
self.is_paid = False
|
self.is_paid = False
|
||||||
self._items = []
|
self._items = []
|
||||||
|
self.item_tax_total = None
|
||||||
|
self.item_total = None
|
||||||
self._transactions = []
|
self._transactions = []
|
||||||
self._story = []
|
self._story = []
|
||||||
|
|
||||||
|
@ -176,8 +178,22 @@ class SimpleInvoice(SimpleDocTemplate):
|
||||||
self._story.append(
|
self._story.append(
|
||||||
Paragraph('Detail', self._defined_styles.get('Heading1'))
|
Paragraph('Detail', self._defined_styles.get('Heading1'))
|
||||||
)
|
)
|
||||||
item_data.insert(0, ('Item id', 'Name', 'Description', 'Units', 'Unit Price', 'Vat/Tax', 'Subtotal'))
|
item_data.insert(0, ('#', 'Name', 'Description', 'Units', 'Unit Price', 'Vat/Tax', 'Subtotal'))
|
||||||
self._story.append(TableWithHeader(item_data, horizontal_align='LEFT'))
|
if self.item_tax_total or self.item_total:
|
||||||
|
item_data.append(
|
||||||
|
(
|
||||||
|
'Total', '', '', '', '',
|
||||||
|
self.item_tax_total if self.item_tax_total else '-',
|
||||||
|
self.item_total if self.item_total else '-'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
style = [
|
||||||
|
('SPAN', (0, len(item_data) - 1), (4, len(item_data) - 1)),
|
||||||
|
('ALIGN', (0, len(item_data) - 1), (-3, -1), 'RIGHT'),
|
||||||
|
]
|
||||||
|
else:
|
||||||
|
style = None
|
||||||
|
self._story.append(TableWithHeader(item_data, horizontal_align='LEFT', style=style))
|
||||||
|
|
||||||
def __build_transactions(self):
|
def __build_transactions(self):
|
||||||
# Transaction
|
# Transaction
|
||||||
|
|
|
@ -32,9 +32,11 @@ doc.client_info = ClientInfo(
|
||||||
post_code='222222'
|
post_code='222222'
|
||||||
)
|
)
|
||||||
|
|
||||||
doc.add_item(Item('0000', 'Item', 'Item', 1, '1.1', '1.1'))
|
doc.add_item(Item('0000', 'Item', 'Item', 1, '1.1', '1.32', '0.22'))
|
||||||
doc.add_item(Item('1111', 'Item', 'Item', 2, '2.2', '4.4'))
|
doc.add_item(Item('1111', 'Item', 'Item', 2, '2.2', '4.4'))
|
||||||
doc.add_item(Item('2222', 'Item', 'Item', 3, '3.3', '9.9'))
|
doc.add_item(Item('2222', 'Item', 'Item', 3, '3.3', '9.9'))
|
||||||
|
doc.item_tax_total = Decimal('.22')
|
||||||
|
doc.item_total = Decimal('16.2')
|
||||||
|
|
||||||
doc.add_transaction(Transaction('Paypal', 111, datetime.now(), 1))
|
doc.add_transaction(Transaction('Paypal', 111, datetime.now(), 1))
|
||||||
doc.add_transaction(Transaction('Strip', 222, datetime.now(), 2))
|
doc.add_transaction(Transaction('Strip', 222, datetime.now(), 2))
|
||||||
|
|
Loading…
Reference in a new issue