Skip to content

Commit f88dc26

Browse files
committed
fix: update free item qty while adding same item in seperate row
1 parent f3cf28a commit f88dc26

File tree

1 file changed

+11
-2
lines changed
  • erpnext/accounts/doctype/pricing_rule

1 file changed

+11
-2
lines changed

erpnext/accounts/doctype/pricing_rule/utils.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -651,8 +651,17 @@ def get_product_discount_rule(pricing_rule, item_details, args=None, doc=None):
651651

652652
qty = pricing_rule.free_qty or 1
653653
if pricing_rule.is_recursive:
654-
transaction_qty = (args.get("qty") if args else doc.total_qty) - pricing_rule.apply_recursion_over
655-
if transaction_qty:
654+
transaction_qty = sum(
655+
[
656+
row.qty
657+
for row in doc.items
658+
if not row.is_free_item
659+
and row.item_code == args.item_code
660+
and row.pricing_rules == args.pricing_rules
661+
]
662+
)
663+
transaction_qty = transaction_qty - pricing_rule.apply_recursion_over
664+
if transaction_qty and transaction_qty > 0:
656665
qty = flt(transaction_qty) * qty / pricing_rule.recurse_for
657666
if pricing_rule.round_free_qty:
658667
qty = (flt(transaction_qty) // pricing_rule.recurse_for) * (pricing_rule.free_qty or 1)

0 commit comments

Comments
 (0)