Merge pull request #15574 from resilient-tech/fix-limit-in-get-method
fix: limit in `Document.get`
This commit is contained in:
commit
6f8f792c01
2 changed files with 7 additions and 5 deletions
|
|
@ -1010,15 +1010,12 @@ def _filter(data, filters, limit=None):
|
|||
_filters[f] = fval
|
||||
|
||||
for d in data:
|
||||
add = True
|
||||
for f, fval in _filters.items():
|
||||
if not frappe.compare(getattr(d, f, None), fval[0], fval[1]):
|
||||
add = False
|
||||
break
|
||||
|
||||
if add:
|
||||
else:
|
||||
out.append(d)
|
||||
if limit and (len(out)-1)==limit:
|
||||
if limit and len(out) >= limit:
|
||||
break
|
||||
|
||||
return out
|
||||
|
|
|
|||
|
|
@ -252,3 +252,8 @@ class TestDocument(unittest.TestCase):
|
|||
'currency': 100000
|
||||
})
|
||||
self.assertEquals(d.get_formatted('currency', currency='INR', format="#,###.##"), '₹ 100,000.00')
|
||||
|
||||
def test_limit_for_get(self):
|
||||
doc = frappe.get_doc("DocType", "DocType")
|
||||
# assuming DocType has more that 3 Data fields
|
||||
self.assertEquals(len(doc.get("fields", filters={"fieldtype": "Data"}, limit=3)), 3)
|
||||
Loading…
Add table
Reference in a new issue