mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-12 17:51:20 +00:00
Merge pull request #27332 from marination/paging-discount-fix
fix: Paging and Discount filter
This commit is contained in:
@@ -29,6 +29,7 @@ def get_product_filter_data(query_args=None):
|
|||||||
if isinstance(query_args, str):
|
if isinstance(query_args, str):
|
||||||
query_args = json.loads(query_args)
|
query_args = json.loads(query_args)
|
||||||
|
|
||||||
|
query_args = frappe._dict(query_args)
|
||||||
if query_args:
|
if query_args:
|
||||||
search = query_args.get("search")
|
search = query_args.get("search")
|
||||||
field_filters = query_args.get("field_filters", {})
|
field_filters = query_args.get("field_filters", {})
|
||||||
|
|||||||
@@ -289,7 +289,7 @@ class ProductQuery:
|
|||||||
def filter_results_by_discount(self, fields, result):
|
def filter_results_by_discount(self, fields, result):
|
||||||
if fields and fields.get("discount"):
|
if fields and fields.get("discount"):
|
||||||
discount_percent = frappe.utils.flt(fields["discount"][0])
|
discount_percent = frappe.utils.flt(fields["discount"][0])
|
||||||
result = [row for row in result if row.get("discount_percent") and row.discount_percent >= discount_percent]
|
result = [row for row in result if row.get("discount_percent") and row.discount_percent <= discount_percent]
|
||||||
|
|
||||||
if self.filter_with_discount:
|
if self.filter_with_discount:
|
||||||
# no limit was added to results while querying
|
# no limit was added to results while querying
|
||||||
|
|||||||
@@ -274,10 +274,9 @@ class TestProductDataEngine(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
items = result.get("items")
|
items = result.get("items")
|
||||||
|
|
||||||
# check if only product with 10% and below discount are fetched in the right order
|
# check if only product with 10% and below discount are fetched
|
||||||
self.assertEqual(len(items), 2)
|
self.assertEqual(len(items), 1)
|
||||||
self.assertEqual(items[0].get("item_code"), "Test 13I Laptop")
|
self.assertEqual(items[0].get("item_code"), "Test 12I Laptop")
|
||||||
self.assertEqual(items[1].get("item_code"), "Test 12I Laptop")
|
|
||||||
|
|
||||||
def test_product_list_with_api(self):
|
def test_product_list_with_api(self):
|
||||||
"Test products listing using API."
|
"Test products listing using API."
|
||||||
|
|||||||
Reference in New Issue
Block a user