Skip to content

Commit cbbe336

Browse files
author
Jason Otero
committed
Merge branch 'integration_tests' of https://github.com/sidecars/python-quickbooks into integration_tests
2 parents ed55e2e + 26ddd45 commit cbbe336

11 files changed

Lines changed: 290 additions & 6 deletions

File tree

CHANGELOG.rst

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

4+
* 0.4.1 (July 22, 2016)
5+
* Fixed bug on PurchaseLine.
6+
* Added ability to query current user.
7+
* Added support to reconnect an account.
8+
* Added to_ref method to Bill object.
9+
* Fixed issues creating notes with Attachable.
10+
411
* 0.4.0 (June 15, 2016)
512
* Added a way of disconnecting a Quickbooks Account to client.
613
* Added support for Quickbooks Reports.

README.rst

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,63 @@ Review results for batch operation:
243243
for error in fault.Error:
244244
print "Error " + error.Message
245245

246+
Attachments
247+
----------------
248+
See `Attachable documentation`_ for list of valid file types.
249+
250+
Attaching a note:
251+
252+
::
253+
254+
attachment = Attachable()
255+
256+
attachable_ref = AttachableRef()
257+
attachable_ref = .EntityRef = entity.to_ref()
258+
259+
attachment.AttachableRef.append(attachable_ref)
260+
261+
attachment.Note = 'This is a note'
262+
attachment.save(qb=client)
263+
264+
Attaching a file:
265+
266+
::
267+
268+
attachment = Attachable()
269+
270+
attachable_ref = AttachableRef()
271+
attachable_ref = .EntityRef = entity.to_ref()
272+
273+
attachment.AttachableRef.append(attachable_ref)
274+
275+
attachment.FileName = 'Filename'
276+
attachment._FilePath = '/folder/filename' # full path to file
277+
attachment.ContentType = 'application/pdf'
278+
attachment.save(qb=client)
279+
280+
Working with JSON data
281+
----------------
282+
All objects include ``to_json`` and ``from_json`` methods.
283+
284+
Converting an object to JSON data:
285+
286+
::
287+
288+
account = Account.get(1, qb=client)
289+
json_data = account.to_json()
290+
291+
Loading JSON data into a quickbooks object:
292+
293+
::
246294

295+
account = Account()
296+
account.from_json(
297+
{
298+
"AccountType": "Accounts Receivable",
299+
"Name": "MyJobs"
300+
}
301+
)
302+
account.save(qb=client)
247303

248304
**Note:** Objects and object property names match their Quickbooks
249305
counterparts and do not follow PEP8.
@@ -258,6 +314,7 @@ on Python 2.
258314
.. _Disconnect documentation: https://developer.intuit.com/docs/0050_quickbooks_api/0020_authentication_and_authorization/oauth_management_api#/Disconnect
259315
.. _quickbooks-python: https://github.com/troolee/quickbooks-python
260316
.. _Minor versions: https://developer.intuit.com/docs/0100_accounting/0300_developer_guides/minor_versions
317+
.. _Attachable documentation: https://developer.intuit.com/docs/api/accounting/Attachable
261318

262319
.. |Build Status| image:: https://travis-ci.org/sidecars/python-quickbooks.svg?branch=master
263320
:target: https://travis-ci.org/sidecars/python-quickbooks

quickbooks/objects/attachable.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from six import python_2_unicode_compatible
2-
from .base import Ref, QuickbooksManagedObject, QuickbooksTransactionEntity
2+
from .base import Ref, QuickbooksManagedObject, QuickbooksTransactionEntity, AttachableRef
33
from ..client import QuickBooks
44

55

@@ -16,6 +16,10 @@ class Attachable(QuickbooksManagedObject, QuickbooksTransactionEntity):
1616
"EntityRef": Ref,
1717
}
1818

19+
list_dict = {
20+
"AttachableRef": AttachableRef,
21+
}
22+
1923
qbo_object_name = "Attachable"
2024

2125
def __init__(self):
@@ -55,7 +59,11 @@ def save(self, qb=None):
5559
else:
5660
json_data = qb.create_object(self.qbo_object_name, self.to_json(), _file_path=self._FilePath)
5761

58-
obj = type(self).from_json(json_data['AttachableResponse'][0]['Attachable'])
62+
if self.FileName:
63+
obj = type(self).from_json(json_data['AttachableResponse'][0]['Attachable'])
64+
else:
65+
obj = type(self).from_json(json_data['Attachable'])
66+
5967
self.Id = obj.Id
6068

6169
return obj

quickbooks/objects/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,10 @@ class AttachableRef(QuickbooksBaseObject):
170170
def __init__(self):
171171
super(AttachableRef, self).__init__()
172172

173-
self.LineInfo = ""
173+
self.LineInfo = None
174174
self.IncludeOnSend = False
175-
self.Inactive = False
176-
self.NoRefOnly = False
175+
self.Inactive = None
176+
self.NoRefOnly = None
177177

178178
self.EntityRef = None
179179
self.CustomField = []

quickbooks/objects/bill.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,13 @@ def to_linked_txn(self):
134134
linked_txn.TxnLineId = 1
135135

136136
return linked_txn
137+
138+
def to_ref(self):
139+
ref = Ref()
140+
141+
ref.name = self.DisplayName
142+
ref.type = self.qbo_object_name
143+
ref.value = self.Id
144+
145+
return ref
146+

quickbooks/objects/purchase.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
@python_2_unicode_compatible
99
class AccountBasedExpenseLineDetail(QuickbooksBaseObject):
1010
class_dict = {
11+
"CustomerRef": Ref,
1112
"ClassRef": Ref,
1213
"AccountRef": Ref,
1314
"TaxCodeRef": Ref
@@ -18,6 +19,8 @@ class AccountBasedExpenseLineDetail(QuickbooksBaseObject):
1819
def __init__(self):
1920
super(AccountBasedExpenseLineDetail, self).__init__()
2021
self.BillableStatus = ""
22+
self.TaxAmount = None
23+
self.TaxInclusiveAmt = None # Available in Minor verion 1
2124
self.ClassRef = None
2225
self.AccountRef = None
2326
self.TaxCodeRef = None
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import os
2+
import unittest
3+
from datetime import datetime
4+
5+
from quickbooks.client import QuickBooks
6+
from quickbooks.objects.attachable import Attachable
7+
from quickbooks.objects.base import Ref, AttachableRef
8+
from quickbooks.objects.vendor import Vendor
9+
10+
11+
class AttachableTest(unittest.TestCase):
12+
def setUp(self):
13+
self.qb_client = QuickBooks(
14+
sandbox=True,
15+
consumer_key=os.environ.get('CONSUMER_KEY'),
16+
consumer_secret=os.environ.get('CONSUMER_SECRET'),
17+
access_token=os.environ.get('ACCESS_TOKEN'),
18+
access_token_secret=os.environ.get('ACCESS_TOKEN_SECRET'),
19+
company_id=os.environ.get('COMPANY_ID')
20+
)
21+
22+
self.time = datetime.now()
23+
24+
def test_create_note(self):
25+
attachable = Attachable()
26+
27+
vendor = Vendor.all(max_results=1, qb=self.qb_client)[0]
28+
29+
attachable_ref = AttachableRef()
30+
attachable_ref.EntityRef = vendor.to_ref()
31+
attachable.AttachableRef.append(attachable_ref)
32+
33+
attachable.Note = "Test note added on {}".format(self.time.strftime("%Y-%m-%d %H:%M:%S"))
34+
35+
attachable.save(qb=self.qb_client)
36+
query_attachable = Attachable.get(attachable.Id, qb=self.qb_client)
37+
38+
self.assertEquals(query_attachable.AttachableRef[0].EntityRef.value, vendor.Id)
39+
self.assertEquals(query_attachable.Note, "Test note added on {}".format(self.time.strftime("%Y-%m-%d %H:%M:%S")))
40+
41+
def test_update_note(self):
42+
attachable = Attachable.all(max_results=1, qb=self.qb_client)[0]
43+
44+
attachable.Note = "Note updated on {}".format(self.time.strftime("%Y-%m-%d %H:%M:%S"))
45+
attachable.save(qb=self.qb_client)
46+
47+
query_attachable = Attachable.get(attachable.Id, qb=self.qb_client)
48+
self.assertEquals(query_attachable.Note, "Note updated on {}".format(self.time.strftime("%Y-%m-%d %H:%M:%S")))
49+
50+
def test_create_file(self):
51+
attachable = Attachable()
52+
53+
vendor = Vendor.all(max_results=1, qb=self.qb_client)[0]
54+
55+
attachable_ref = AttachableRef()
56+
attachable_ref.EntityRef = vendor.to_ref()
57+
attachable.AttachableRef.append(attachable_ref)
58+
59+
attachable.FileName = 'TestFileName'
60+
attachable._FilePath = __file__
61+
attachable.ContentType = 'application/txt'
62+
63+
attachable.save(qb=self.qb_client)
64+
query_attachable = Attachable.get(attachable.Id, qb=self.qb_client)
65+
66+
self.assertEquals(query_attachable.AttachableRef[0].EntityRef.value, vendor.Id)

tests/integration/test_vendor.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import os
2+
import unittest
3+
from datetime import datetime
4+
5+
from quickbooks.client import QuickBooks
6+
from quickbooks.objects.base import Address, PhoneNumber, EmailAddress, WebAddress
7+
from quickbooks.objects.vendor import Vendor
8+
9+
10+
class VendorTest(unittest.TestCase):
11+
def setUp(self):
12+
self.qb_client = QuickBooks(
13+
sandbox=True,
14+
consumer_key=os.environ.get('CONSUMER_KEY'),
15+
consumer_secret=os.environ.get('CONSUMER_SECRET'),
16+
access_token=os.environ.get('ACCESS_TOKEN'),
17+
access_token_secret=os.environ.get('ACCESS_TOKEN_SECRET'),
18+
company_id=os.environ.get('COMPANY_ID')
19+
)
20+
21+
self.account_number = datetime.now().strftime('%d%H%M')
22+
self.name = "Test Vendor {0}".format(self.account_number)
23+
24+
def test_create(self):
25+
vendor = Vendor()
26+
27+
vendor.TaxIdentifier = '99-9999999'
28+
vendor.AcctNum = self.account_number
29+
vendor.Title = 'Ms.'
30+
vendor.GivenName = 'First'
31+
vendor.FamilyName = 'Last'
32+
vendor.Suffix = 'Sr.'
33+
vendor.CompanyName = self.name
34+
vendor.DisplayName = self.name
35+
vendor.PrintOnCheckName = self.name
36+
37+
vendor.BillAddr = Address()
38+
vendor.BillAddr.Line1 = "123 Main"
39+
vendor.BillAddr.Line2 = "Apartment 1"
40+
vendor.BillAddr.City = "City"
41+
vendor.BillAddr.Country = "U.S.A"
42+
vendor.BillAddr.CountrySubDivisionCode = "CA"
43+
vendor.BillAddr.PostalCode = "94030"
44+
45+
vendor.PrimaryPhone = PhoneNumber()
46+
vendor.PrimaryPhone.FreeFormNumber = '555-555-5555'
47+
48+
vendor.PrimaryEmailAddr = EmailAddress()
49+
vendor.PrimaryEmailAddr.Address = 'test@email.com'
50+
51+
vendor.WebAddr = WebAddress()
52+
vendor.WebAddr.URI = 'http://testurl.com'
53+
54+
vendor.save(qb=self.qb_client)
55+
56+
query_vendor = Vendor.get(vendor.Id, qb=self.qb_client)
57+
58+
self.assertEquals(query_vendor.Id, vendor.Id)
59+
60+
self.assertEquals(query_vendor.AcctNum, self.account_number)
61+
self.assertEquals(query_vendor.Title, 'Ms.')
62+
self.assertEquals(query_vendor.GivenName, 'First')
63+
self.assertEquals(query_vendor.FamilyName, 'Last')
64+
self.assertEquals(query_vendor.Suffix, 'Sr.')
65+
self.assertEquals(query_vendor.CompanyName, self.name)
66+
self.assertEquals(query_vendor.DisplayName, self.name)
67+
self.assertEquals(query_vendor.PrintOnCheckName, self.name)
68+
69+
self.assertEquals(query_vendor.BillAddr.Line1, "123 Main")
70+
self.assertEquals(query_vendor.BillAddr.Line2, "Apartment 1")
71+
self.assertEquals(query_vendor.BillAddr.City, "City")
72+
self.assertEquals(query_vendor.BillAddr.Country, "U.S.A")
73+
self.assertEquals(query_vendor.BillAddr.CountrySubDivisionCode, "CA")
74+
self.assertEquals(query_vendor.BillAddr.PostalCode, "94030")
75+
self.assertEquals(query_vendor.PrimaryPhone.FreeFormNumber, '555-555-5555')
76+
self.assertEquals(query_vendor.PrimaryEmailAddr.Address, 'test@email.com')
77+
self.assertEquals(query_vendor.WebAddr.URI, 'http://testurl.com')
78+
79+
def update_vendor(self):
80+
vendor = Vendor.all(max_results=1, qb=self.qb_client)[0]
81+
82+
vendor.GivenName = 'Updated Name'
83+
vendor.FamilyName = 'Updated Lastname'
84+
85+
vendor.save(qb=self.qb_client)
86+
87+
query_vendor = Vendor.get(vendor.Id, qb=self.qb_client)
88+
self.assertEquals(query_vendor.GivenName, 'Updated Name')
89+
self.assertEquals(query_vendor.FamilyName, 'Updated Lastname')
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import unittest
2+
3+
from quickbooks import QuickBooks
4+
from quickbooks.objects.attachable import Attachable
5+
6+
7+
class AttachableTests(unittest.TestCase):
8+
def test_unicode(self):
9+
attachable = Attachable()
10+
attachable.FileName = "test"
11+
12+
self.assertEquals(str(attachable), "test")
13+
14+
def test_to_ref(self):
15+
attachable = Attachable()
16+
attachable.FileName = "test"
17+
attachable.Id = 12
18+
19+
ref = attachable.to_ref()
20+
21+
self.assertEquals(ref.name, "test")
22+
self.assertEquals(ref.type, "Attachable")
23+
self.assertEquals(ref.value, 12)
24+
25+
def test_valid_object_name(self):
26+
attachable = Attachable()
27+
client = QuickBooks()
28+
result = client.isvalid_object_name(attachable.qbo_object_name)
29+
30+
self.assertTrue(result)

tests/unit/objects/test_base.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,11 @@ class AttachableRefTests(unittest.TestCase):
9797
def test_init(self):
9898
attachable = AttachableRef()
9999
attachable.Name = "test"
100+
attachable.IncludeOnSend = False
101+
attachable.Inactive = False
102+
attachable.NoRefOnly = False
100103

101-
self.assertEquals(attachable.LineInfo, "")
104+
self.assertEquals(attachable.LineInfo, None)
102105
self.assertEquals(attachable.IncludeOnSend, False)
103106
self.assertEquals(attachable.Inactive, False)
104107
self.assertEquals(attachable.NoRefOnly, False)

0 commit comments

Comments
 (0)