Browse Source

Merge pull request #15574 from resilient-tech/fix-limit-in-get-method

fix: limit in `Document.get`
version-14
mergify[bot] 3 years ago
committed by GitHub
parent
commit
6f8f792c01
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 5 deletions
  1. +2
    -5
      frappe/model/base_document.py
  2. +5
    -0
      frappe/tests/test_document.py

+ 2
- 5
frappe/model/base_document.py View File

@@ -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

+ 5
- 0
frappe/tests/test_document.py View File

@@ -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…
Cancel
Save