Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 56bfd5a

Browse files
committed
Merge branch 'master' into oauth
2 parents 1ceadd2 + d339f58 commit 56bfd5a

File tree

6 files changed

+71
-36
lines changed

6 files changed

+71
-36
lines changed

quickbooks/cdc.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,33 @@
55

66

77
def change_data_capture(qbo_class_list, timestamp, qb=None):
8-
if qb is None:
9-
qb = QuickBooks()
8+
if qb is None:
9+
qb = QuickBooks()
1010

11-
cdc_class_dict = dict((cls.qbo_object_name, cls) for cls in qbo_class_list)
11+
cdc_class_dict = dict((cls.qbo_object_name, cls) for cls in qbo_class_list)
1212

13-
cdc_class_names = list(cdc_class_dict.keys())
14-
entity_list_string = ','.join(cdc_class_names)
13+
cdc_class_names = list(cdc_class_dict.keys())
14+
entity_list_string = ','.join(cdc_class_names)
1515

16-
if isinstance(timestamp, datetime):
17-
timestamp_string = qb_datetime_format(timestamp)
18-
else:
19-
timestamp_string = timestamp
16+
if isinstance(timestamp, datetime):
17+
timestamp_string = qb_datetime_format(timestamp)
18+
else:
19+
timestamp_string = timestamp
2020

21-
resp = qb.change_data_capture(entity_list_string, timestamp_string)
21+
resp = qb.change_data_capture(entity_list_string, timestamp_string)
2222

23-
cdc_response_dict = resp.pop('CDCResponse')
24-
cdc_response = CDCResponse.from_json(resp)
23+
cdc_response_dict = resp.pop('CDCResponse')
24+
cdc_response = CDCResponse.from_json(resp)
2525

26-
query_response_list = cdc_response_dict[0]['QueryResponse']
27-
for query_response_dict in query_response_list:
28-
qb_object_name = [x for x in query_response_dict if x in cdc_class_names][0]
29-
qb_object_list = query_response_dict.pop(qb_object_name)
30-
qb_object_cls = cdc_class_dict[qb_object_name]
26+
query_response_list = cdc_response_dict[0]['QueryResponse']
27+
for query_response_dict in query_response_list:
28+
qb_object_name = [x for x in query_response_dict if x in cdc_class_names][0]
29+
qb_object_list = query_response_dict.pop(qb_object_name)
30+
qb_object_cls = cdc_class_dict[qb_object_name]
3131

32-
query_response = QueryResponse.from_json(query_response_dict)
33-
query_response._object_list = [qb_object_cls.from_json(obj) for obj in qb_object_list]
32+
query_response = QueryResponse.from_json(query_response_dict)
33+
query_response._object_list = [qb_object_cls.from_json(obj) for obj in qb_object_list]
3434

35-
setattr(cdc_response, qb_object_name, query_response)
35+
setattr(cdc_response, qb_object_name, query_response)
3636

37-
return cdc_response
37+
return cdc_response

quickbooks/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def create_session(self):
149149
self.session = session
150150
else:
151151
raise QuickbooksException(
152-
"Quickbooks authenication fields not set. Cannot create session.")
152+
"Quickbooks authentication fields not set. Cannot create session.")
153153

154154
return self.session
155155

quickbooks/objects/item.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ def __init__(self):
3939
self.SubItem = False
4040
self.FullyQualifiedName = "" # Readonly
4141
self.Taxable = False
42-
self.SalesTaxInclusive = None
42+
self.SalesTaxIncluded = None
4343
self.UnitPrice = 0
4444
self.Type = ""
4545
self.Level = None # Readonly
4646
self.PurchaseDesc = None
47-
self.PurchaseTaxInclusive = None
47+
self.PurchaseTaxIncluded = None
4848
self.PurchaseCost = None
4949
self.TrackQtyOnHand = False
5050
self.QtyOnHand = None

quickbooks/utils.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import six
2+
import sys
23

34

45
def build_where_clause(**kwargs):
@@ -8,7 +9,11 @@ def build_where_clause(**kwargs):
89
where = []
910

1011
for key, value in kwargs.items():
11-
if isinstance(value, six.string_types):
12+
if isinstance(value, six.text_type) and sys.version_info[0] == 2:
13+
# If using python 2, encode unicode as string.
14+
encoded_value = value.encode('utf-8')
15+
where.append("{0} = '{1}'".format(key, encoded_value.replace(r"'", r"\'")))
16+
elif isinstance(value, six.string_types):
1217
where.append("{0} = '{1}'".format(key, value.replace(r"'", r"\'")))
1318
else:
1419
where.append("{0} = {1}".format(key, value))
@@ -25,7 +30,11 @@ def build_choose_clause(choices, field):
2530
where = []
2631

2732
for choice in choices:
28-
if isinstance(choice, six.string_types):
33+
if isinstance(choice, six.text_type) and sys.version_info[0] == 2:
34+
# If using python 2, encode unicode as string.
35+
encoded_choice = choice.encode('utf-8')
36+
where.append("'{0}'".format(encoded_choice.replace(r"'", r"\'")))
37+
elif isinstance(choice, six.string_types):
2938
where.append("'{0}'".format(choice.replace(r"'", r"\'")))
3039
else:
3140
where.append("{0}".format(choice))

tests/integration/test_attachable.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import tempfile
23
import unittest
34
from datetime import datetime
45

@@ -55,16 +56,17 @@ def test_update_note(self):
5556

5657
def test_create_file(self):
5758
attachable = Attachable()
59+
test_file = tempfile.NamedTemporaryFile(suffix=".txt")
5860

5961
vendor = Vendor.all(max_results=1, qb=self.qb_client)[0]
6062

6163
attachable_ref = AttachableRef()
6264
attachable_ref.EntityRef = vendor.to_ref()
6365
attachable.AttachableRef.append(attachable_ref)
6466

65-
attachable.FileName = 'TestFileName'
66-
attachable._FilePath = __file__
67-
attachable.ContentType = 'application/txt'
67+
attachable.FileName = os.path.basename(test_file.name)
68+
attachable._FilePath = test_file.name
69+
attachable.ContentType = 'text/plain'
6870

6971
attachable.save(qb=self.qb_client)
7072
query_attachable = Attachable.get(attachable.Id, qb=self.qb_client)

tests/unit/test_utils.py

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,46 @@
44

55
class UtilsTests(unittest.TestCase):
66
def test_build_where_clause(self):
7-
where_clause = utils.build_where_clause(field1=1, field2="Someone's Company")
7+
where_clause = utils.build_where_clause(field1=1,
8+
field2="Someone's Company")
89

910
self.assertTrue("field1 = 1" in where_clause)
1011
self.assertTrue("field2 = 'Someone\\\'s Company'" in where_clause)
1112

12-
def test_build_where_clause_integers(self):
13-
where_clause = utils.build_choose_clause(choices=[1, 2], field="field1")
13+
def test_build_where_clause_unicode(self):
14+
where_clause = utils.build_where_clause(field1=u"Test 1",
15+
field2=u"Someone's Company")
16+
17+
self.assertTrue("field1 = 'Test 1'" in where_clause)
18+
self.assertTrue("field2 = 'Someone\\\'s Company'" in where_clause)
19+
20+
def test_build_choose_clause_integers(self):
21+
where_clause = utils.build_choose_clause(choices=[1, 2],
22+
field="field1")
1423

1524
self.assertEqual(where_clause, "field1 in (1, 2)")
1625

17-
def test_build_where_clause_strings(self):
18-
where_clause = utils.build_choose_clause(choices=["val1", "val2"], field="field1")
26+
def test_build_choose_clause_strings(self):
27+
where_clause = utils.build_choose_clause(choices=["val1", "val2"],
28+
field="field1")
1929

2030
self.assertEqual(where_clause, "field1 in ('val1', 'val2')")
2131

22-
def test_build_where_clause_quoted_value(self):
23-
where_clause = utils.build_choose_clause(choices=["val1", "Someone's Company"], field="field1")
32+
def test_build_choose_clause_quoted_value(self):
33+
where_clause = utils.build_choose_clause(choices=["val1",
34+
"Someone's Company"],
35+
field="field1")
2436

2537
self.assertEqual(where_clause, "field1 in ('val1', 'Someone\\\'s Company')")
38+
39+
def test_build_choose_clause_unicode(self):
40+
where_clause = utils.build_choose_clause(choices=[u"Test - & % $", u"Another Test"],
41+
field="field1")
42+
43+
self.assertEqual(where_clause, "field1 in ('Test - & % $', 'Another Test')")
44+
45+
def test_build_choose_clause_unicode_escaped(self):
46+
where_clause = utils.build_choose_clause(choices=[u"Test - & % $", u"Another's Test"],
47+
field="field1")
48+
49+
self.assertEqual(where_clause, "field1 in ('Test - & % $', 'Another\\\'s Test')")

0 commit comments

Comments
 (0)