merge merchant and client info

This commit is contained in:
zhangshine 2015-06-08 23:55:05 +08:00
parent 67bb548a62
commit 07b99f7e94
3 changed files with 49 additions and 13 deletions

View file

@ -36,8 +36,9 @@ class ServiceProviderInfo(AddressInfo):
"""
Service provider/Merchant information
"""
def __init__(self, name, street, city, state, country, post_code):
def __init__(self, name, street, city, state, country, post_code, vat_tax_number=None):
super(ServiceProviderInfo, self).__init__(name, street, city, state, country, post_code)
self.vat_tax_number = vat_tax_number
class ClientInfo(AddressInfo):

View file

@ -4,7 +4,7 @@ from reportlab.lib.enums import TA_CENTER, TA_RIGHT
from reportlab.lib.pagesizes import letter
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.lib.units import inch
from reportlab.platypus import SimpleDocTemplate, Paragraph
from reportlab.platypus import SimpleDocTemplate, Paragraph, Table
from pyinvoice.components import SimpleTable, TableWithHeader, PaidStamp
from pyinvoice.models import PDFInfo, Item, Transaction, InvoiceInfo, ServiceProviderInfo, ClientInfo
@ -92,19 +92,28 @@ class SimpleInvoice(SimpleDocTemplate):
SimpleTable(self.__attribute_to_table_data(self.invoice_info, props), horizontal_align='RIGHT')
)
def __service_provider_data(self):
props = [('name', 'Name'), ('street', 'Street'), ('city', 'City'), ('state', 'State'),
('country', 'Country'), ('post_code', 'Post code'), ('vat_tax_number', 'Vat/Tax number')]
return self.__attribute_to_table_data(self.service_provider_info, props)
def __build_service_provider_info(self):
# Merchant
if isinstance(self.service_provider_info, ServiceProviderInfo):
self._story.append(
Paragraph('Merchant', self._defined_styles.get('RightHeading1'))
)
props = [('name', 'Name'), ('street', 'Street'), ('city', 'City'), ('state', 'State'),
('country', 'Country'), ('post_code', 'Post code')]
self._story.append(
SimpleTable(self.__attribute_to_table_data(self.service_provider_info, props), horizontal_align='RIGHT')
SimpleTable(self.__service_provider_data(), horizontal_align='RIGHT')
)
def __client_info_data(self):
props = [('name', 'Name'), ('street', 'Street'), ('city', 'City'), ('state', 'State'),
('country', 'Country'), ('post_code', 'Post code'), ('email', 'Email'), ('client_id', 'Client id')]
return self.__attribute_to_table_data(self.client_info, props)
def __build_client_info(self):
# ClientInfo
if isinstance(self.client_info, ClientInfo):
@ -112,12 +121,38 @@ class SimpleInvoice(SimpleDocTemplate):
Paragraph('Client', self._defined_styles.get('Heading1'))
)
props = [('name', 'Name'), ('street', 'Street'), ('city', 'City'), ('state', 'State'),
('country', 'Country'), ('post_code', 'Post code'), ('email', 'Email'), ('client_id', 'Client id')]
self._story.append(
SimpleTable(self.__attribute_to_table_data(self.client_info, props), horizontal_align='LEFT')
SimpleTable(self.__client_info_data(), horizontal_align='LEFT')
)
def __build_service_provider_and_client_info(self):
if isinstance(self.service_provider_info, ServiceProviderInfo) and isinstance(self.client_info, ClientInfo):
# Merge Table
table_data = [
[Paragraph('Service Provider', self._defined_styles.get('Heading1')), '', Paragraph('Client', self._defined_styles.get('Heading1')), '']
]
table_style = [
('SPAN', (0, 0), (1, 0)),
('SPAN', (2, 0), (3, 0)),
]
client_info_data = self.__client_info_data()
service_provider_data = self.__service_provider_data()
diff = abs(len(client_info_data) - len(service_provider_data))
if diff > 0:
if len(client_info_data) < len(service_provider_data):
client_info_data.extend([["", ""]]*diff)
else:
service_provider_data.extend([["", ""]*diff])
for d in zip(service_provider_data, client_info_data):
d[0].extend(d[1])
table_data.append(d[0])
self._story.append(
Table(table_data, style=table_style)
)
else:
self.__build_service_provider_info()
self.__build_client_info()
def __build_items(self):
# Items
item_data = [
@ -160,8 +195,7 @@ class SimpleInvoice(SimpleDocTemplate):
self._story = []
self.__build_invoice_info()
self.__build_service_provider_info()
self.__build_client_info()
self.__build_service_provider_and_client_info()
self.__build_items()
self.__build_transactions()

View file

@ -17,7 +17,8 @@ doc.service_provider_info = ServiceProviderInfo(
city='My City',
state='My State',
country='My Country',
post_code='222222'
post_code='222222',
vat_tax_number='Vat/Tax number'
)
doc.client_info = ClientInfo(
@ -31,7 +32,7 @@ doc.client_info = ClientInfo(
post_code='222222'
)
doc.add_item(Item('0000', 'Item 0000', 'Item Description 1 Long--------------------------------Item Description 1 Long', 1, Decimal('1.1')))
doc.add_item(Item('0000', 'Item 0000', 'Item Description 1', 1, Decimal('1.1')))
doc.add_item(Item('1111', 'Item 1111', 'Item Description 2', 2, Decimal('2.2')))
doc.add_item(Item('2222', 'Item 2222', 'Item Description 3', 3, Decimal('3.3')))