From 8bce3828347d87b9c12abc27bb0d1da6a6bcdd99 Mon Sep 17 00:00:00 2001 From: venkat102 Date: Wed, 4 Dec 2024 00:56:36 +0530 Subject: [PATCH 1/2] fix: update free item qty while adding same item in seperate row --- erpnext/accounts/doctype/pricing_rule/utils.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/pricing_rule/utils.py b/erpnext/accounts/doctype/pricing_rule/utils.py index 83186bc1d24..90e0ea256ff 100644 --- a/erpnext/accounts/doctype/pricing_rule/utils.py +++ b/erpnext/accounts/doctype/pricing_rule/utils.py @@ -651,7 +651,16 @@ def get_product_discount_rule(pricing_rule, item_details, args=None, doc=None): qty = pricing_rule.free_qty or 1 if pricing_rule.is_recursive: - transaction_qty = (args.get("qty") if args else doc.total_qty) - pricing_rule.apply_recursion_over + transaction_qty = sum( + [ + row.qty + for row in doc.items + if not row.is_free_item + and row.item_code == args.item_code + and row.pricing_rules == args.pricing_rules + ] + ) + transaction_qty = (transaction_qty or doc.total_qty) - pricing_rule.apply_recursion_over if transaction_qty: qty = flt(transaction_qty) * qty / pricing_rule.recurse_for if pricing_rule.round_free_qty: From 329d14957b0eac1e97424365bb4447d1d2024578 Mon Sep 17 00:00:00 2001 From: venkat102 Date: Wed, 4 Dec 2024 01:08:54 +0530 Subject: [PATCH 2/2] fix: validate negative qty --- erpnext/accounts/doctype/pricing_rule/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/doctype/pricing_rule/utils.py b/erpnext/accounts/doctype/pricing_rule/utils.py index 90e0ea256ff..d8eea29bfc0 100644 --- a/erpnext/accounts/doctype/pricing_rule/utils.py +++ b/erpnext/accounts/doctype/pricing_rule/utils.py @@ -660,8 +660,8 @@ def get_product_discount_rule(pricing_rule, item_details, args=None, doc=None): and row.pricing_rules == args.pricing_rules ] ) - transaction_qty = (transaction_qty or doc.total_qty) - pricing_rule.apply_recursion_over - if transaction_qty: + transaction_qty = transaction_qty - pricing_rule.apply_recursion_over + if transaction_qty and transaction_qty > 0: qty = flt(transaction_qty) * qty / pricing_rule.recurse_for if pricing_rule.round_free_qty: qty = (flt(transaction_qty) // pricing_rule.recurse_for) * (pricing_rule.free_qty or 1)