Skip to content

Commit c164821

Browse files
committed
add SKU to Item
1 parent 67141c2 commit c164821

File tree

2 files changed

+39
-8
lines changed

2 files changed

+39
-8
lines changed

quickbooks/mixins.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -255,14 +255,26 @@ class ListMixin(object):
255255

256256
@classmethod
257257
def all(cls, order_by="", start_position="", max_results=100, qb=None):
258-
"""
259-
:param start_position:
260-
:param max_results: The max number of entities that can be returned in a response is 1000.
261-
:param qb:
262-
:return: Returns list
263-
"""
264-
return cls.where("", order_by=order_by, start_position=start_position,
265-
max_results=max_results, qb=qb)
258+
"""Returns list of objects containing all objects in the QuickBooks database"""
259+
if qb is None:
260+
qb = QuickBooks()
261+
262+
# For Item objects, we need to explicitly request the SKU field
263+
if cls.qbo_object_name == "Item":
264+
select = "SELECT *, Sku FROM {0}".format(cls.qbo_object_name)
265+
else:
266+
select = "SELECT * FROM {0}".format(cls.qbo_object_name)
267+
268+
if order_by:
269+
select += " ORDER BY {0}".format(order_by)
270+
271+
if start_position:
272+
select += " STARTPOSITION {0}".format(start_position)
273+
274+
if max_results:
275+
select += " MAXRESULTS {0}".format(max_results)
276+
277+
return cls.query(select, qb=qb)
266278

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

tests/integration/test_item.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,22 @@ def test_create(self):
4545
self.assertEqual(query_item.IncomeAccountRef.value, self.income_account.Id)
4646
self.assertEqual(query_item.ExpenseAccountRef.value, self.expense_account.Id)
4747
self.assertEqual(query_item.AssetAccountRef.value, self.asset_account.Id)
48+
49+
def test_sku_in_all(self):
50+
"""Test that SKU is properly returned when using Item.all()"""
51+
# First create an item with a SKU
52+
unique_name = "Test SKU Item {0}".format(datetime.now().strftime('%d%H%M%S'))
53+
item = Item()
54+
item.Name = unique_name
55+
item.Type = "Service"
56+
item.Sku = "TEST_SKU_" + self.account_number
57+
item.IncomeAccountRef = self.income_account.to_ref()
58+
item.ExpenseAccountRef = self.expense_account.to_ref()
59+
item.save(qb=self.qb_client)
60+
61+
# Now fetch all items and verify the SKU is present
62+
items = Item.all(max_results=100, qb=self.qb_client)
63+
found_item = next((i for i in items if i.Id == item.Id), None)
64+
65+
self.assertIsNotNone(found_item, "Created item not found in Item.all() results")
66+
self.assertEqual(found_item.Sku, "TEST_SKU_" + self.account_number)

0 commit comments

Comments
 (0)