Skip to content

Commit

Permalink
Added start_position and max_results parameters to "where" and "all" …
Browse files Browse the repository at this point in the history
…methods.
  • Loading branch information
ej2 committed Sep 13, 2015
1 parent 35f7286 commit 44ae8bb
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ List of objects:
from quickbooks.object.customer import Customer
customers = Customer.all()

__Note:__ The maximum number of entities that can be returned in a response is 1000. If the result size is not specified, the default number is 100.
(See [Intuit developer guide](https://developer.intuit.com/docs/0100_accounting/0300_developer_guides/querying_data) for supported SQL statements)

Filtered list of objects:

Expand All @@ -78,10 +80,19 @@ List with custom Where Clause (do not include the "WHERE"):
customers = Customer.where("Active = True AND CompanyName LIKE 'S%'")


List with custom Where Clause with paging:


customers = Customer.where("Active = True AND CompanyName LIKE 'S%'", start_position=1, max_results=25)


Filtering a list with a custom query (See [Intuit developer guide](https://developer.intuit.com/docs/0100_accounting/0300_developer_guides/querying_data) for supported SQL statements):

customer = Customer.query("SELECT * FROM Customer WHERE Active = True")

Filtering a list with a custom query with paging:

customer = Customer.query("SELECT * FROM Customer WHERE Active = True STARTPOSITION 1 MAXRESULTS 25")

Get single object by Id and update:

Expand Down
20 changes: 15 additions & 5 deletions quickbooks/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,12 @@ class ListMixin(object):
qbo_object_name = ""

@classmethod
def all(cls):
return cls.where("")
def all(cls, start_position="", max_results=100):
"""
:param max_results: The maximum number of entities that can be returned in a response is 1000.
:return: Returns list
"""
return cls.where("", start_position=start_position, max_results=max_results)

@classmethod
def filter(cls, **kwargs):
Expand All @@ -80,23 +84,29 @@ def filter(cls, **kwargs):
return cls.where(build_where_clause(**kwargs))

@classmethod
def where(cls, where_clause=""):
def where(cls, where_clause="", start_position="", max_results=""):
"""
:param where_clause: QBO SQL where clause (DO NOT include 'WHERE')
:return: Returns list filtered by input where_clause
"""
if where_clause:
where_clause = "WHERE " + where_clause

select = "select * from {0} {1}".format(cls.qbo_object_name, where_clause)
if start_position:
start_position = " STARTPOSITION " + start_position

if max_results:
max_results = " MAXRESULTS " + max_results

select = "select * from {0} {1}{2}{3}".format(cls.qbo_object_name, where_clause, start_position, max_results)

return cls.query(select)

@classmethod
def query(cls, select):
"""
:param select: QBO SQL query select statement
:return: List
:return: Returns list
"""

qb = QuickBooks()
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from setuptools import setup, find_packages


VERSION = (0, 2, 3)
VERSION = (0, 2, 4)
version = '.'.join(map(str, VERSION))

setup(
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ListMixinTest(unittest.TestCase):
@patch('quickbooks.mixins.ListMixin.where')
def test_all(self, where):
Department.all()
where.assert_called_once_with("")
where.assert_called_once_with('', max_results=1000, start_position='')

@patch('quickbooks.mixins.ListMixin.where')
def test_filter(self, where):
Expand Down

0 comments on commit 44ae8bb

Please sign in to comment.