From 5e875b238c9d1a1c376f2fa98c0d2451da7e80b7 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Fri, 21 Jun 2024 15:46:16 +0530 Subject: [PATCH 1/2] fix: pricing rule with and without 'apply multiple' and priority Either all of the pricing rules identified for an item should have 'apply multiple' enabled. If not, Priority is applied and only the highest priority is applied --- erpnext/accounts/doctype/pricing_rule/utils.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/erpnext/accounts/doctype/pricing_rule/utils.py b/erpnext/accounts/doctype/pricing_rule/utils.py index 9bd417fa5b3..d8f2302d7ef 100644 --- a/erpnext/accounts/doctype/pricing_rule/utils.py +++ b/erpnext/accounts/doctype/pricing_rule/utils.py @@ -174,12 +174,9 @@ def _get_pricing_rules(apply_on, args, values): def apply_multiple_pricing_rules(pricing_rules): - apply_multiple_rule = [ - d.apply_multiple_pricing_rules for d in pricing_rules if d.apply_multiple_pricing_rules - ] - - if not apply_multiple_rule: - return False + for d in pricing_rules: + if not d.apply_multiple_pricing_rules: + return False return True From efebc3662e8b76ea82866f940ed0bc9032c819e2 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Sat, 22 Jun 2024 20:26:23 +0530 Subject: [PATCH 2/2] test: priority takes effect on with and without apply multiple --- .../doctype/pricing_rule/test_pricing_rule.py | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py index 7f9c55ff24f..72961a6b6ec 100644 --- a/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py +++ b/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py @@ -1237,6 +1237,68 @@ class TestPricingRule(unittest.TestCase): frappe.delete_doc_if_exists("Pricing Rule", "_Test Pricing Rule 1") frappe.delete_doc_if_exists("Pricing Rule", "_Test Pricing Rule 2") + def test_pricing_rules_with_and_without_apply_multiple(self): + item = make_item("PR Item 99") + + test_records = [ + { + "doctype": "Pricing Rule", + "title": "_Test discount on item group", + "name": "_Test discount on item group", + "apply_on": "Item Group", + "item_groups": [ + { + "item_group": "Products", + } + ], + "selling": 1, + "price_or_product_discount": "Price", + "rate_or_discount": "Discount Percentage", + "discount_percentage": 60, + "has_priority": 1, + "company": "_Test Company", + "apply_multiple_pricing_rules": True, + }, + { + "doctype": "Pricing Rule", + "title": "_Test fixed rate on item code", + "name": "_Test fixed rate on item code", + "apply_on": "Item Code", + "items": [ + { + "item_code": item.name, + } + ], + "selling": 1, + "price_or_product_discount": "Price", + "rate_or_discount": "Rate", + "rate": 25, + "has_priority": 1, + "company": "_Test Company", + "apply_multiple_pricing_rules": False, + }, + ] + + for item_group_priority, item_code_priority in [(2, 4), (4, 2)]: + item_group_rule = frappe.get_doc(test_records[0].copy()) + item_group_rule.priority = item_group_priority + item_group_rule.insert() + + item_code_rule = frappe.get_doc(test_records[1].copy()) + item_code_rule.priority = item_code_priority + item_code_rule.insert() + + si = create_sales_invoice(qty=5, customer="_Test Customer 1", item=item.name, do_not_submit=True) + si.save() + self.assertEqual(len(si.pricing_rules), 1) + # Item Code rule should've applied as it has higher priority + expected_rule = item_group_rule if item_group_priority > item_code_priority else item_code_rule + self.assertEqual(si.pricing_rules[0].pricing_rule, expected_rule.name) + + si.delete() + item_group_rule.delete() + item_code_rule.delete() + test_dependencies = ["Campaign"]