test client info
This commit is contained in:
parent
c318180f48
commit
6dccb3927a
3 changed files with 59 additions and 12 deletions
|
@ -92,7 +92,7 @@ class ClientInfo(AddressInfo):
|
||||||
:type country: str or unicode or None
|
:type country: str or unicode or None
|
||||||
:type post_code: str or unicode or None
|
:type post_code: str or unicode or None
|
||||||
:type email: str or unicode or None
|
:type email: str or unicode or None
|
||||||
:type post_code: str or unicode or None
|
:type client_id: str or unicode or int or None
|
||||||
"""
|
"""
|
||||||
super(ClientInfo, self).__init__(name, street, city, state, country, post_code)
|
super(ClientInfo, self).__init__(name, street, city, state, country, post_code)
|
||||||
self.email = email
|
self.email = email
|
||||||
|
|
|
@ -8,7 +8,6 @@ from reportlab.lib.pagesizes import letter
|
||||||
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
|
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
|
||||||
from reportlab.lib.units import inch
|
from reportlab.lib.units import inch
|
||||||
from reportlab.platypus import SimpleDocTemplate, Paragraph, Table, Spacer
|
from reportlab.platypus import SimpleDocTemplate, Paragraph, Table, Spacer
|
||||||
from reportlab.platypus.doctemplate import _doNothing
|
|
||||||
|
|
||||||
from pyinvoice.components import SimpleTable, TableWithHeader, PaidStamp
|
from pyinvoice.components import SimpleTable, TableWithHeader, PaidStamp
|
||||||
from pyinvoice.models import PDFInfo, Item, Transaction, InvoiceInfo, ServiceProviderInfo, ClientInfo
|
from pyinvoice.models import PDFInfo, Item, Transaction, InvoiceInfo, ServiceProviderInfo, ClientInfo
|
||||||
|
@ -125,26 +124,29 @@ class SimpleInvoice(SimpleDocTemplate):
|
||||||
self._story.append(SimpleTable(service_provider_info_data, horizontal_align='RIGHT'))
|
self._story.append(SimpleTable(service_provider_info_data, horizontal_align='RIGHT'))
|
||||||
|
|
||||||
def _client_info_data(self):
|
def _client_info_data(self):
|
||||||
|
if not isinstance(self.client_info, ClientInfo):
|
||||||
|
return []
|
||||||
|
|
||||||
props = [('name', 'Name'), ('street', 'Street'), ('city', 'City'), ('state', 'State'),
|
props = [('name', 'Name'), ('street', 'Street'), ('city', 'City'), ('state', 'State'),
|
||||||
('country', 'Country'), ('post_code', 'Post code'), ('email', 'Email'), ('client_id', 'Client id')]
|
('country', 'Country'), ('post_code', 'Post code'), ('email', 'Email'), ('client_id', 'Client id')]
|
||||||
return self._attribute_to_table_data(self.client_info, props)
|
return self._attribute_to_table_data(self.client_info, props)
|
||||||
|
|
||||||
def _build_client_info(self):
|
def _build_client_info(self):
|
||||||
# ClientInfo
|
# ClientInfo
|
||||||
if isinstance(self.client_info, ClientInfo):
|
client_info_data = self._client_info_data()
|
||||||
self._story.append(
|
if client_info_data:
|
||||||
Paragraph('Client', self._defined_styles.get('Heading1'))
|
self._story.append(Paragraph('Client', self._defined_styles.get('Heading1')))
|
||||||
)
|
self._story.append(SimpleTable(client_info_data, horizontal_align='LEFT'))
|
||||||
|
|
||||||
self._story.append(
|
|
||||||
SimpleTable(self._client_info_data(), horizontal_align='LEFT')
|
|
||||||
)
|
|
||||||
|
|
||||||
def _build_service_provider_and_client_info(self):
|
def _build_service_provider_and_client_info(self):
|
||||||
if isinstance(self.service_provider_info, ServiceProviderInfo) and isinstance(self.client_info, ClientInfo):
|
if isinstance(self.service_provider_info, ServiceProviderInfo) and isinstance(self.client_info, ClientInfo):
|
||||||
# Merge Table
|
# Merge Table
|
||||||
table_data = [
|
table_data = [
|
||||||
[Paragraph('Service Provider', self._defined_styles.get('Heading1')), '', '', Paragraph('Client', self._defined_styles.get('Heading1')), '']
|
[
|
||||||
|
Paragraph('Service Provider', self._defined_styles.get('Heading1')), '',
|
||||||
|
'',
|
||||||
|
Paragraph('Client', self._defined_styles.get('Heading1')), ''
|
||||||
|
]
|
||||||
]
|
]
|
||||||
table_style = [
|
table_style = [
|
||||||
('SPAN', (0, 0), (1, 0)),
|
('SPAN', (0, 0), (1, 0)),
|
||||||
|
@ -288,4 +290,8 @@ class SimpleInvoice(SimpleDocTemplate):
|
||||||
self._build_transactions()
|
self._build_transactions()
|
||||||
self._build_bottom_tip()
|
self._build_bottom_tip()
|
||||||
|
|
||||||
self.build(self._story, onFirstPage=PaidStamp(7 * inch, 5.8 * inch) if self.is_paid else _doNothing)
|
kwargs = {}
|
||||||
|
if self.is_paid:
|
||||||
|
kwargs['onFirstPage'] = PaidStamp(7 * inch, 5.8 * inch)
|
||||||
|
|
||||||
|
self.build(self._story, **kwargs)
|
|
@ -211,3 +211,44 @@ class TestSimpleInvoice(unittest.TestCase):
|
||||||
invoice.finish()
|
invoice.finish()
|
||||||
|
|
||||||
self.assertTrue(os.path.exists(invoice_path))
|
self.assertTrue(os.path.exists(invoice_path))
|
||||||
|
|
||||||
|
def test_client_info(self):
|
||||||
|
invoice_path = os.path.join(self.file_base_dir, 'client_info.pdf')
|
||||||
|
if os.path.exists(invoice_path):
|
||||||
|
os.remove(invoice_path)
|
||||||
|
|
||||||
|
invoice = SimpleInvoice(invoice_path)
|
||||||
|
|
||||||
|
# Before add client info
|
||||||
|
info_data = invoice._client_info_data()
|
||||||
|
self.assertEqual(info_data, [])
|
||||||
|
|
||||||
|
# Empty info
|
||||||
|
invoice.client_info = ClientInfo()
|
||||||
|
info_data = invoice._client_info_data()
|
||||||
|
self.assertEqual(info_data, [])
|
||||||
|
|
||||||
|
invoice.client_info = ClientInfo(
|
||||||
|
name='Client ccc',
|
||||||
|
street='Street sss',
|
||||||
|
city='City ccc',
|
||||||
|
state='State sss',
|
||||||
|
country='Country ccc',
|
||||||
|
post_code='Post code ppp',
|
||||||
|
email='Email@example.com',
|
||||||
|
client_id=3214
|
||||||
|
)
|
||||||
|
|
||||||
|
# After add client info
|
||||||
|
info_data = invoice._client_info_data()
|
||||||
|
self.assertEqual(len(info_data), 8)
|
||||||
|
self.assertEqual(info_data[0][0], 'Name:')
|
||||||
|
self.assertEqual(info_data[0][1], 'Client ccc')
|
||||||
|
self.assertEqual(info_data[6][0], 'Email:')
|
||||||
|
self.assertEqual(info_data[6][1], 'Email@example.com')
|
||||||
|
self.assertEqual(info_data[7][0], 'Client id:')
|
||||||
|
self.assertEqual(info_data[7][1], 3214)
|
||||||
|
|
||||||
|
invoice.finish()
|
||||||
|
|
||||||
|
self.assertTrue(os.path.exists(invoice_path))
|
Loading…
Reference in a new issue