Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: qty filter not working if apply_multiple_pricing_rules is enabled #28877

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,26 @@ def test_pricing_rule_for_transaction(self):
for doc in [si, si1]:
doc.delete()

def test_multiple_pricing_rules_with_min_qty(self):
make_pricing_rule(discount_percentage=20, selling=1, priority=1, min_qty=4,
apply_multiple_pricing_rules=1, title="_Test Pricing Rule with Min Qty - 1")
make_pricing_rule(discount_percentage=10, selling=1, priority=2, min_qty=4,
apply_multiple_pricing_rules=1, title="_Test Pricing Rule with Min Qty - 2")

si = create_sales_invoice(do_not_submit=True, customer="_Test Customer 1", qty=1, currency="USD")
item = si.items[0]
item.stock_qty = 1
si.save()
self.assertFalse(item.discount_percentage)
item.qty = 5
item.stock_qty = 5
si.save()
self.assertEqual(item.discount_percentage, 30)
si.delete()

frappe.delete_doc_if_exists("Pricing Rule", "_Test Pricing Rule with Min Qty - 1")
frappe.delete_doc_if_exists("Pricing Rule", "_Test Pricing Rule with Min Qty - 2")

test_dependencies = ["Campaign"]

def make_pricing_rule(**args):
Expand Down
5 changes: 2 additions & 3 deletions erpnext/accounts/doctype/pricing_rule/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,12 @@ def sorted_by_priority(pricing_rules, args, doc=None):
if not pricing_rule.get('priority'):
pricing_rule['priority'] = 1

if pricing_rule.get('apply_multiple_pricing_rules'):
nextchamp-saqib marked this conversation as resolved.
Show resolved Hide resolved
pricing_rule_dict.setdefault(cint(pricing_rule.get("priority")), []).append(pricing_rule)
pricing_rule_dict.setdefault(cint(pricing_rule.get("priority")), []).append(pricing_rule)

for key in sorted(pricing_rule_dict):
pricing_rules_list.extend(pricing_rule_dict.get(key))

return pricing_rules_list or pricing_rules
return pricing_rules_list

def filter_pricing_rule_based_on_condition(pricing_rules, doc=None):
filtered_pricing_rules = []
Expand Down