fix: limit without filter

This commit is contained in:
Pruthvi Patel 2022-02-15 13:06:55 +05:30
parent 054d6d8f19
commit 7ce9f1eaa1
2 changed files with 7 additions and 1 deletions

View file

@ -149,6 +149,9 @@ class BaseDocument(object):
self.set(key, [])
value = self.__dict__.get(key)
if limit and isinstance(value, (list, tuple)) and len(value) > limit:
value = value[:limit]
return value
else:
return self.__dict__

View file

@ -264,7 +264,10 @@ class TestDocument(unittest.TestCase):
def test_limit_for_get(self):
doc = frappe.get_doc("DocType", "DocType")
# assuming DocType has more that 3 Data fields
# assuming DocType has more than 3 Data fields
self.assertEquals(len(doc.get("fields", limit=3)), 3)
# limit with filters
self.assertEquals(len(doc.get("fields", filters={"fieldtype": "Data"}, limit=3)), 3)
def test_virtual_fields(self):