Skip to content

Commit

Permalink
Merge pull request frappe#41658 from rtdany10/pr-transaction-condition
Browse files Browse the repository at this point in the history
fix: condition-wise filter for transaction based pricing rule
  • Loading branch information
ruthra-kumar authored Jun 1, 2024
2 parents ee846f5 + 3f23436 commit 666232f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
24 changes: 24 additions & 0 deletions erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,30 @@ def test_pricing_rule_for_transaction(self):
for doc in [si, si1]:
doc.delete()

def test_pricing_rule_for_transaction_with_condition(self):
make_item("PR Transaction Condition")
frappe.delete_doc_if_exists("Pricing Rule", "_Test Pricing Rule")
make_pricing_rule(
selling=1,
min_qty=0,
price_or_product_discount="Product",
apply_on="Transaction",
free_item="PR Transaction Condition",
free_qty=1,
free_item_rate=10,
condition="customer=='_Test Customer 1'",
)

si = create_sales_invoice(qty=5, customer="_Test Customer 1", do_not_submit=True)
self.assertEqual(len(si.items), 2)
self.assertEqual(si.items[1].rate, 10)

si1 = create_sales_invoice(qty=5, customer="_Test Customer 2", do_not_submit=True)
self.assertEqual(len(si1.items), 1)

for doc in [si, si1]:
doc.delete()

def test_remove_pricing_rule(self):
item = make_item("Water Flask")
make_item_price("Water Flask", "_Test Price List", 100)
Expand Down
1 change: 1 addition & 0 deletions erpnext/accounts/doctype/pricing_rule/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,7 @@ def apply_pricing_rule_on_transaction(doc):

if pricing_rules:
pricing_rules = filter_pricing_rules_for_qty_amount(doc.total_qty, doc.total, pricing_rules)
pricing_rules = filter_pricing_rule_based_on_condition(pricing_rules, doc)

if not pricing_rules:
remove_free_item(doc)
Expand Down

0 comments on commit 666232f

Please sign in to comment.