Skip to content

Commit 0920ee8

Browse files
committed
added order_by to .all()
1 parent 34f94d7 commit 0920ee8

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

README.rst

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,19 @@ Filtered list of objects:
198198
199199
customers = Customer.filter(Active=True, FamilyName="Smith", qb=client)
200200
201+
Filtered list of objects with ordering:
202+
203+
.. code-block:: python
204+
205+
# Get customer invoices ordered by TxnDate
206+
invoices = Invoice.filter(CustomerRef='100', order_by='TxnDate', qb=client)
207+
208+
# Same, but in reverse order
209+
invoices = Invoice.filter(CustomerRef='100', order_by='TxnDate DESC', qb=client)
210+
211+
# Order customers by FamilyName then by GivenName
212+
customers = Customer.all(order_by='FamilyName, GivenName', qb=client)
213+
201214
Filtered list of objects with paging:
202215

203216
.. code-block:: python
@@ -217,6 +230,12 @@ List with custom Where Clause (do not include the ``"WHERE"``):
217230
218231
customers = Customer.where("Active = True AND CompanyName LIKE 'S%'", qb=client)
219232
233+
List with custom Where and ordering:
234+
235+
.. code-block:: python
236+
237+
customers = Customer.where("Active = True AND CompanyName LIKE 'S%'", order_by='DisplayName', qb=client)
238+
220239
List with custom Where Clause and paging:
221240

222241
.. code-block:: python
@@ -443,4 +462,4 @@ on Python 2.
443462
.. |Coverage Status| image:: https://coveralls.io/repos/sidecars/python-quickbooks/badge.svg?branch=master&service=github
444463
:target: https://coveralls.io/github/sidecars/python-quickbooks?branch=master
445464

446-
.. _OAuth 1.0 vs. OAuth 2.0: https://developer.intuit.com/docs/0100_quickbooks_online/0100_essentials/000500_authentication_and_authorization/0010_oauth_1.0a_vs_oauth_2.0_apps
465+
.. _OAuth 1.0 vs. OAuth 2.0: https://developer.intuit.com/docs/0100_quickbooks_online/0100_essentials/000500_authentication_and_authorization/0010_oauth_1.0a_vs_oauth_2.0_apps

quickbooks/mixins.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,15 @@ class ListMixin(object):
153153
qbo_object_name = ""
154154

155155
@classmethod
156-
def all(cls, start_position="", max_results=100, qb=None):
156+
def all(cls, order_by="", start_position="", max_results=100, qb=None):
157157
"""
158158
:param start_position:
159159
:param max_results: The max number of entities that can be returned in a response is 1000.
160160
:param qb:
161161
:return: Returns list
162162
"""
163-
return cls.where("", start_position=start_position, max_results=max_results, qb=qb)
163+
return cls.where("", order_by=order_by, start_position=start_position,
164+
max_results=max_results, qb=qb)
164165

165166
@classmethod
166167
def filter(cls, order_by="", start_position="", max_results="", qb=None, **kwargs):

tests/unit/test_mixins.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def setUp(self):
148148
@patch('quickbooks.mixins.ListMixin.where')
149149
def test_all(self, where):
150150
Department.all()
151-
where.assert_called_once_with('', max_results=100, start_position='', qb=None)
151+
where.assert_called_once_with('', order_by='', max_results=100, start_position='', qb=None)
152152

153153
def test_all_with_qb(self):
154154
with patch.object(self.qb_client, 'query') as query:

0 commit comments

Comments
 (0)