Skip to content

Commit f4ddecd

Browse files
committed
Code clean up.
1 parent c46a51d commit f4ddecd

File tree

9 files changed

+70
-42
lines changed

9 files changed

+70
-42
lines changed

CHANGELOG.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
Changelog
22
========
33

4+
* 0.5.6 (January 18th, 2017)
5+
* Fixed issue downloading PDFs in Python 3
6+
47
* 0.5.5 (January 4th, 2017)
58
* Imported QuickBooks objects into __init__.py for easier imports
69
* Removed duplicate class AttachableRef from deposit.py

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ python-quickbooks
33

44
|Build Status| |Coverage Status|
55

6+
67
A Python library for accessing the Quickbooks API. Complete rework of
78
`quickbooks-python`_.
89

quickbooks/client.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ def api_url(self):
129129
return self.api_url_v3
130130

131131
def create_session(self):
132-
if self.consumer_secret and self.consumer_key and self.access_token_secret and self.access_token:
132+
if self.consumer_secret and self.consumer_key \
133+
and self.access_token_secret and self.access_token:
133134
session = OAuth1Session(
134135
self.consumer_key,
135136
self.consumer_secret,
@@ -138,7 +139,8 @@ def create_session(self):
138139
)
139140
self.session = session
140141
else:
141-
raise QuickbooksException("Quickbooks authenication fields not set. Cannot create session.")
142+
raise QuickbooksException(
143+
"Quickbooks authenication fields not set. Cannot create session.")
142144

143145
return self.session
144146

@@ -162,14 +164,14 @@ def get_authorize_url(self):
162164
return self.qbService.get_authorize_url(self.request_token)
163165

164166
def get_current_user(self):
165-
'''Get data from the current user endpoint'''
167+
"""Get data from the current user endpoint"""
166168
url = self.current_user_url
167169
result = self.make_request("GET", url)
168170
return result
169171

170172
def get_report(self, report_type, qs=None):
171-
'''Get data from the report endpoint'''
172-
if qs == None:
173+
"""Get data from the report endpoint"""
174+
if qs is None:
173175
qs = {}
174176

175177
url = self.api_url + "/company/{0}/reports/{1}".format(self.company_id, report_type)
@@ -273,7 +275,8 @@ def make_request(self, request_type, url, request_body=None, content_type='appli
273275
) % (boundary, request_body, boundary, binary_data, boundary)
274276

275277
req = self.session.request(
276-
request_type, url, True, self.company_id, headers=headers, params=params, data=request_body)
278+
request_type, url, True, self.company_id,
279+
headers=headers, params=params, data=request_body)
277280

278281
if req.status_code == httplib.UNAUTHORIZED:
279282
raise AuthorizationException("Application authentication failed", detail=req.text)
@@ -349,7 +352,8 @@ def batch_operation(self, request_body):
349352
return results
350353

351354
def download_pdf(self, qbbo, item_id):
352-
url = self.api_url + "/company/{0}/{1}/{2}/pdf".format(self.company_id, qbbo.lower(), item_id)
355+
url = self.api_url + "/company/{0}/{1}/{2}/pdf".format(
356+
self.company_id, qbbo.lower(), item_id)
353357

354358
if self.session is None:
355359
self.create_session()
@@ -363,9 +367,10 @@ def download_pdf(self, qbbo, item_id):
363367

364368
if response.status_code != httplib.OK:
365369
try:
366-
json = response.json()
370+
result = response.json()
367371
except:
368372
raise QuickbooksException("Error reading json response: {0}".format(response.text), 10000)
369-
self.handle_exceptions(json["Fault"])
373+
374+
self.handle_exceptions(result["Fault"])
370375
else:
371376
return response.content

quickbooks/mixins.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ def to_json(self):
1010

1111
def json_filter(self):
1212
"""
13-
filter out properties that have names starting with _ or properties that have a value of None
13+
filter out properties that have names starting with _
14+
or properties that have a value of None
1415
"""
1516
return lambda obj: dict((k, v) for k, v in obj.__dict__.items()
1617
if not k.startswith('_') and getattr(obj, k) is not None)
@@ -85,23 +86,31 @@ class ListMixin(object):
8586
@classmethod
8687
def all(cls, start_position="", max_results=100, qb=None):
8788
"""
88-
:param max_results: The maximum number of entities that can be returned in a response is 1000.
89+
:param start_position:
90+
:param max_results: The max number of entities that can be returned in a response is 1000.
91+
:param qb:
8992
:return: Returns list
9093
"""
9194
return cls.where("", start_position=start_position, max_results=max_results, qb=qb)
9295

9396
@classmethod
9497
def filter(cls, start_position="", max_results="", qb=None, **kwargs):
9598
"""
99+
:param start_position:
100+
:param max_results:
101+
:param qb:
96102
:param kwargs: field names and values to filter the query
97103
:return: Filtered list
98104
"""
99-
return cls.where(build_where_clause(**kwargs), start_position=start_position, max_results=max_results, qb=qb)
105+
return cls.where(build_where_clause(**kwargs),
106+
start_position=start_position, max_results=max_results, qb=qb)
100107

101108
@classmethod
102109
def choose(cls, choices, field="Id", qb=None):
103110
"""
104-
:param kwargs: field names and values to filter the query
111+
:param choices:
112+
:param field:
113+
:param qb:
105114
:return: Filtered list
106115
"""
107116
return cls.where(build_choose_clause(choices, field), qb=qb)
@@ -110,6 +119,9 @@ def choose(cls, choices, field="Id", qb=None):
110119
def where(cls, where_clause="", start_position="", max_results="", qb=None):
111120
"""
112121
:param where_clause: QBO SQL where clause (DO NOT include 'WHERE')
122+
:param start_position:
123+
:param max_results:
124+
:param qb:
113125
:return: Returns list filtered by input where_clause
114126
"""
115127
if where_clause:
@@ -121,14 +133,16 @@ def where(cls, where_clause="", start_position="", max_results="", qb=None):
121133
if max_results:
122134
max_results = " MAXRESULTS " + str(max_results)
123135

124-
select = "SELECT * FROM {0} {1}{2}{3}".format(cls.qbo_object_name, where_clause, start_position, max_results)
136+
select = "SELECT * FROM {0} {1}{2}{3}".format(
137+
cls.qbo_object_name, where_clause, start_position, max_results)
125138

126139
return cls.query(select, qb=qb)
127140

128141
@classmethod
129142
def query(cls, select, qb=None):
130143
"""
131144
:param select: QBO SQL query select statement
145+
:param qb:
132146
:return: Returns list
133147
"""
134148
if not qb:
@@ -152,4 +166,6 @@ def download_pdf(self, qb=None):
152166
if self.Id and self.Id > 0 and qb is not None:
153167
return qb.download_pdf(self.qbo_object_name, self.Id)
154168
else:
155-
raise QuickbooksException("Cannot download {0} when no Id is assigned or if no quickbooks client is passed in".format(self.qbo_object_name))
169+
raise QuickbooksException(
170+
"Cannot download {0} when no Id is assigned or if no quickbooks client is passed in".format(
171+
self.qbo_object_name))

quickbooks/objects/billpayment.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ def __str__(self):
5252
@python_2_unicode_compatible
5353
class BillPayment(QuickbooksManagedObject, QuickbooksTransactionEntity, LinkedTxnMixin):
5454
"""
55-
QBO definition: A BillPayment entity represents the financial transaction of payment of bills that the
56-
business owner receives from a vendor for goods or services purchased from the vendor. QuickBooks Online
57-
supports bill payments through a credit card or a checking account.
58-
BillPayment.TotalAmt is the total amount associated with this payment. This includes the total of all the
59-
payments from the payment line details. If TotalAmt is greater than the total on the lines being paid,
60-
the overpayment is treated as a credit and exposed as such on the QuickBooks UI. The total amount
61-
cannot be negative.
55+
QBO definition: A BillPayment entity represents the financial transaction of payment
56+
of bills that the business owner receives from a vendor for goods or services purchased
57+
from the vendor. QuickBooks Online supports bill payments through a credit card or a
58+
checking account. BillPayment.TotalAmt is the total amount associated with this payment.
59+
This includes the total of all the payments from the payment line details. If TotalAmt is
60+
greater than the total on the lines being paid, the overpayment is treated as a credit and
61+
exposed as such on the QuickBooks UI. The total amount cannot be negative.
6262
"""
6363

6464
class_dict = {
@@ -82,7 +82,6 @@ def __init__(self):
8282
self.TotalAmt = 0
8383
self.PrivateNote = ""
8484
self.DocNumber = ""
85-
#self.ProcessBillPayment = False
8685

8786
self.VendorRef = None
8887
self.CheckPayment = None

quickbooks/objects/item.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,19 @@
55
@python_2_unicode_compatible
66
class Item(QuickbooksManagedObject, QuickbooksTransactionEntity):
77
"""
8-
QBO definition: An item is a thing that your company buys, sells, or re-sells, such as products and services.
9-
An item is shown as a line on an invoice or other sales form. The Item.Type attribute, which specifies how
10-
the item is used, has one of the following values:
8+
QBO definition: An item is a thing that your company buys, sells, or re-sells,
9+
such as products and services. An item is shown as a line on an invoice or other sales
10+
form. The Item.Type attribute, which specifies how the item is used, has one of
11+
the following values:
1112
12-
Inventory - This type tracks merchandise that your business purchases, stocks, and re-sells as inventory.
13-
QuickBooks tracks the current number of inventory items in stock, cost of goods sold, and the asset value of
14-
the inventory after the purchase and sale of every item.
13+
Inventory - This type tracks merchandise that your business purchases, stocks,
14+
and re-sells as inventory. QuickBooks tracks the current number of inventory items in stock,
15+
cost of goods sold, and the asset value of the inventory after the purchase and sale
16+
of every item.
1517
16-
Service - This type tracks services that you charge on the purchase and tracks merchandise you sell and buy that
17-
is not tracked as inventory. For example, specialized labor, consulting hours, and professional fees.
18+
Service - This type tracks services that you charge on the purchase and tracks
19+
merchandise you sell and buy that is not tracked as inventory. For example, specialized
20+
labor, consulting hours, and professional fees.
1821
"""
1922

2023
class_dict = {
@@ -74,4 +77,3 @@ def to_ref(self):
7477
ref.value = self.Id
7578

7679
return ref
77-

quickbooks/objects/salesreceipt.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
from six import python_2_unicode_compatible
2-
from .base import QuickbooksBaseObject, Ref, CustomField, QuickbooksManagedObject, LinkedTxnMixin, Address, \
2+
from .base import Ref, CustomField, QuickbooksManagedObject, LinkedTxnMixin, Address, \
33
EmailAddress, QuickbooksTransactionEntity, LinkedTxn
44
from .tax import TxnTaxDetail
55
from .detailline import DetailLine
66
from ..mixins import QuickbooksPdfDownloadable
77

88

99
@python_2_unicode_compatible
10-
class SalesReceipt(QuickbooksPdfDownloadable, QuickbooksManagedObject, QuickbooksTransactionEntity, LinkedTxnMixin):
10+
class SalesReceipt(QuickbooksPdfDownloadable, QuickbooksManagedObject,
11+
QuickbooksTransactionEntity, LinkedTxnMixin):
1112
"""
12-
QBO definition: SalesReceipt represents the sales receipt that is given to a customer. A sales receipt is
13-
similar to an invoice. However, for a sales receipt, payment is received as part of the sale of goods and
14-
services. The sales receipt specifies a deposit account where the customer deposits the payment. If the
15-
deposit account is not specified, the payment type is classified as Undeposited Account.
13+
QBO definition: SalesReceipt represents the sales receipt that is given to a customer.
14+
A sales receipt is similar to an invoice. However, for a sales receipt, payment is received
15+
as part of the sale of goods and services. The sales receipt specifies a deposit account
16+
where the customer deposits the payment. If the deposit account is not specified, the
17+
payment type is classified as Undeposited Account.
1618
"""
1719
class_dict = {
1820
"DepartmentRef": Ref,

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def read(*parts):
1010
return fp.read()
1111

1212

13-
VERSION = (0, 5, 5)
13+
VERSION = (0, 5, 6)
1414
version = '.'.join(map(str, VERSION))
1515

1616
setup(

tests/unit/test_batch.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@ def test_invalid_operation(self):
2727

2828
@patch('quickbooks.batch.BatchManager.process_batch')
2929
def test_batch_create(self, process_batch):
30-
results = batch.batch_create(self.obj_list)
30+
batch.batch_create(self.obj_list)
3131
self.assertTrue(process_batch.called)
3232

3333
@patch('quickbooks.batch.BatchManager.process_batch')
3434
def test_batch_update(self, process_batch):
35-
results = batch.batch_update(self.obj_list)
35+
batch.batch_update(self.obj_list)
3636
self.assertTrue(process_batch.called)
3737

3838
@patch('quickbooks.batch.BatchManager.process_batch')
3939
def test_batch_delete(self, process_batch):
40-
results = batch.batch_delete(self.obj_list)
40+
batch.batch_delete(self.obj_list)
4141
self.assertTrue(process_batch.called)
4242

4343
def test_list_to_batch_request(self):

0 commit comments

Comments
 (0)