From d2ce9278915f86fa4f553de3ff6de1163f09b8c3 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Thu, 2 May 2024 09:37:24 +0530 Subject: [PATCH 1/2] fix: pricing rule rounding Consider a pricing rule of 20:1 with recursion enabled, free items should follow the below progression | Qty | Free item qty | |-------+---------------| | 0-19 | 0 | | 20-39 | 1 | | 40-59 | 2 | (cherry picked from commit 9bf37426c13d6a92db46a49d58b4d36faef048f2) --- erpnext/accounts/doctype/pricing_rule/utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/pricing_rule/utils.py b/erpnext/accounts/doctype/pricing_rule/utils.py index ce96a3d1240..2a78bebd103 100644 --- a/erpnext/accounts/doctype/pricing_rule/utils.py +++ b/erpnext/accounts/doctype/pricing_rule/utils.py @@ -6,6 +6,7 @@ import copy import json +import math import frappe from frappe import _, bold @@ -638,7 +639,7 @@ def get_product_discount_rule(pricing_rule, item_details, args=None, doc=None): if transaction_qty: qty = flt(transaction_qty) * qty / pricing_rule.recurse_for if pricing_rule.round_free_qty: - qty = round(qty) + qty = math.floor(qty) free_item_data_args = { "item_code": free_item, From e068bec212c03fd05966f6ca7a9afbaab349d785 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Tue, 7 May 2024 09:44:10 +0530 Subject: [PATCH 2/2] refactor(test): test floor based rounding (cherry picked from commit c41a037174c6f6136086de8b3c822ffff2bb9f60) --- erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py index cb0c223bffa..18658e6e4a6 100644 --- a/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py +++ b/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py @@ -976,7 +976,7 @@ class TestPricingRule(unittest.TestCase): so.load_from_db() self.assertEqual(so.items[1].is_free_item, 1) self.assertEqual(so.items[1].item_code, "_Test Item") - self.assertEqual(so.items[1].qty, 4) + self.assertEqual(so.items[1].qty, 3) def test_apply_multiple_pricing_rules_for_discount_percentage_and_amount(self): frappe.delete_doc_if_exists("Pricing Rule", "_Test Pricing Rule 1")