fix: add order_by params to Frappeclient get_list (#33324)

* fix: add order_by params to client getlist

* fix(test): Test for groupby and orderby

* chore: pre-commit

* fix(test): Add test for group_by

* fix(test): Use dbapi for testing

* linter fix

* chore(test): linter
This commit is contained in:
Shadrak Gurupnor 2025-07-21 19:23:32 +05:30 committed by GitHub
parent 1cc3c6aff0
commit 68246a73fb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 42 additions and 1 deletions

View file

@ -107,12 +107,23 @@ class FrappeClient:
headers=self.headers,
)
def get_list(self, doctype, fields='["name"]', filters=None, limit_start=0, limit_page_length=None):
def get_list(
self,
doctype,
fields='["name"]',
filters=None,
limit_start=0,
limit_page_length=None,
order_by=None,
group_by=None,
):
"""Return list of records of a particular type."""
if not isinstance(fields, str):
fields = json.dumps(fields)
params = {
"fields": fields,
"order_by": order_by,
"group_by": group_by,
}
if filters:
params["filters"] = json.dumps(filters)

View file

@ -52,6 +52,36 @@ class TestFrappeClient(IntegrationTestCase):
self.assertTrue(len(doc_list))
def test_list_summary(self):
server = FrappeClient(get_url(), "Administrator", self.PASSWORD, verify=False)
server.insert_many(
[
{"doctype": "Note", "title": "Sing"},
{"doctype": "Note", "title": "a"},
{"doctype": "Note", "title": "song"},
{"doctype": "Note", "title": "of"},
{"doctype": "Note", "title": "sixpence"},
]
)
notes = server.get_list("Note", fields=["title"], order_by="creation desc")
notes = [d.get("title") for d in notes]
self.assertEqual(notes[0], "sixpence")
getlist_users = server.get_list(
"User",
fields=["count(name) as user_count"],
filters={"user_type": "System User"},
group_by="user_type",
)
getall_users = frappe.db.get_all(
"User",
fields=["count(name) as system_user_count"],
filters={"user_type": "System User"},
group_by="user_type",
)
self.assertEqual(getlist_users[0]["user_count"], getall_users[0]["system_user_count"])
def test_get_doc(self):
USER = "Administrator"
TITLE = "get_this"