Skip to content

Commit 7c67ce6

Browse files
committed
Updated Attachable and created integration tests.
1 parent c2648d1 commit 7c67ce6

7 files changed

Lines changed: 84 additions & 20 deletions

File tree

CHANGELOG.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
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+
9+
410
* 0.4.0 (June 15, 2016)
511
* Added a way of disconnecting a Quickbooks Account to client.
612
* Added support for Quickbooks Reports.

README.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,19 @@ Review results for batch operation:
244244
print "Error " + error.Message
245245

246246

247+
Adding attachments (See `Attachable documentation`_ for list of valid file types):
248+
249+
::
250+
251+
attachment = Attachable()
252+
253+
attachment.AttachableRef = AttachableRef()
254+
attachment.AttachableRef.EntityRef = entity.to_ref()
255+
256+
attachment.FileName = 'Filename'
257+
attachment._FilePath = 'full path to file'
258+
attachment.ContentType = 'application/pdf'
259+
attachment.save(qb=qb)
247260

248261
**Note:** Objects and object property names match their Quickbooks
249262
counterparts and do not follow PEP8.
@@ -258,6 +271,7 @@ on Python 2.
258271
.. _Disconnect documentation: https://developer.intuit.com/docs/0050_quickbooks_api/0020_authentication_and_authorization/oauth_management_api#/Disconnect
259272
.. _quickbooks-python: https://github.com/troolee/quickbooks-python
260273
.. _Minor versions: https://developer.intuit.com/docs/0100_accounting/0300_developer_guides/minor_versions
274+
.. _Attachable documentation: https://developer.intuit.com/docs/api/accounting/Attachable
261275

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

quickbooks/objects/attachable.py

Lines changed: 5 additions & 15 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):
@@ -45,17 +49,3 @@ def to_ref(self):
4549
ref.type = self.qbo_object_name
4650
ref.value = self.Id
4751
return ref
48-
49-
def save(self, qb=None):
50-
if not qb:
51-
qb = QuickBooks()
52-
53-
if self.Id and self.Id > 0:
54-
json_data = qb.update_object(self.qbo_object_name, self.to_json(), _file_path=self._FilePath)
55-
else:
56-
json_data = qb.create_object(self.qbo_object_name, self.to_json(), _file_path=self._FilePath)
57-
58-
obj = type(self).from_json(json_data['AttachableResponse'][0]['Attachable'])
59-
self.Id = obj.Id
60-
61-
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/purchase.py

Lines changed: 4 additions & 1 deletion
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
@@ -55,7 +58,7 @@ def __init__(self):
5558
@python_2_unicode_compatible
5659
class PurchaseLine(QuickbooksBaseObject):
5760
class_dict = {
58-
"AccountBasedExpenseLineDetail": Ref,
61+
"AccountBasedExpenseLineDetail": AccountBasedExpenseLineDetail,
5962
"ItemBasedExpenseLineDetail": ItemBasedExpenseLineDetail,
6063
}
6164

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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")))

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)