Skip to content

Commit

Permalink
Merge pull request #27332 from marination/paging-discount-fix
Browse files Browse the repository at this point in the history
fix: Paging and Discount filter
  • Loading branch information
marination committed Sep 3, 2021
2 parents d3330ce + 477870e commit aee2e04
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
1 change: 1 addition & 0 deletions erpnext/e_commerce/api.py
Expand Up @@ -29,6 +29,7 @@ def get_product_filter_data(query_args=None):
if isinstance(query_args, str):
query_args = json.loads(query_args)

query_args = frappe._dict(query_args)
if query_args:
search = query_args.get("search")
field_filters = query_args.get("field_filters", {})
Expand Down
2 changes: 1 addition & 1 deletion erpnext/e_commerce/product_data_engine/query.py
Expand Up @@ -289,7 +289,7 @@ def combine_web_item_group_results(self, item_group, result, website_item_groups
def filter_results_by_discount(self, fields, result):
if fields and fields.get("discount"):
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:
# no limit was added to results while querying
Expand Down
Expand Up @@ -274,10 +274,9 @@ def test_product_list_with_discount_filters(self):
)
items = result.get("items")

# check if only product with 10% and below discount are fetched in the right order
self.assertEqual(len(items), 2)
self.assertEqual(items[0].get("item_code"), "Test 13I Laptop")
self.assertEqual(items[1].get("item_code"), "Test 12I Laptop")
# check if only product with 10% and below discount are fetched
self.assertEqual(len(items), 1)
self.assertEqual(items[0].get("item_code"), "Test 12I Laptop")

def test_product_list_with_api(self):
"Test products listing using API."
Expand Down

0 comments on commit aee2e04

Please sign in to comment.