diff --git a/erpnext/accounts/doctype/pricing_rule/pricing_rule.json b/erpnext/accounts/doctype/pricing_rule/pricing_rule.json index 3b743c796af..d1697f10903 100644 --- a/erpnext/accounts/doctype/pricing_rule/pricing_rule.json +++ b/erpnext/accounts/doctype/pricing_rule/pricing_rule.json @@ -53,7 +53,7 @@ "column_break_42", "free_item_uom", "round_free_qty", - "enforce_free_item_qty", + "dont_enforce_free_item_qty", "is_recursive", "recurse_for", "apply_recursion_over", @@ -648,15 +648,15 @@ { "default": "1", "depends_on": "eval:doc.price_or_product_discount == 'Product'", - "fieldname": "enforce_free_item_qty", + "fieldname": "dont_enforce_free_item_qty", "fieldtype": "Check", - "label": "Enforce Free Item Qty" + "label": "Don't Enforce Free Item Qty" } ], "icon": "fa fa-gift", "idx": 1, "links": [], - "modified": "2025-02-05 21:03:22.103044", + "modified": "2025-02-17 18:15:39.824639", "modified_by": "Administrator", "module": "Accounts", "name": "Pricing Rule", diff --git a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py index fa84c4c0e6b..ba52735cf7e 100644 --- a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py +++ b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py @@ -62,7 +62,7 @@ class PricingRule(Document): disable: DF.Check discount_amount: DF.Currency discount_percentage: DF.Float - enforce_free_item_qty: DF.Check + dont_enforce_free_item_qty: DF.Check for_price_list: DF.Link | None free_item: DF.Link | None free_item_rate: DF.Currency @@ -665,7 +665,7 @@ def remove_pricing_rule_for_item(pricing_rules, item_details, item_code=None, ra if pricing_rule.margin_type in ["Percentage", "Amount"]: item_details.margin_rate_or_amount = 0.0 item_details.margin_type = None - elif pricing_rule.get("free_item") and pricing_rule.get("enforce_free_item_qty"): + elif pricing_rule.get("free_item") and not pricing_rule.get("dont_enforce_free_item_qty"): item_details.remove_free_item = ( item_code if pricing_rule.get("same_item") else pricing_rule.get("free_item") ) diff --git a/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py index 8729bd6b81d..d4e39a1315b 100644 --- a/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py +++ b/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py @@ -428,7 +428,7 @@ class TestPricingRule(FrappeTestCase): self.assertEqual(so.items[1].is_free_item, 1) self.assertEqual(so.items[1].item_code, "_Test Item 2") - def test_enforce_free_item_qty(self): + def test_dont_enforce_free_item_qty(self): # this test is only for testing non-enforcement as all other tests in this file already test with enforcement frappe.delete_doc_if_exists("Pricing Rule", "_Test Pricing Rule") test_record = { @@ -467,10 +467,10 @@ class TestPricingRule(FrappeTestCase): self.assertEqual(len(so.items), 2) # Without enforcement - pricing_rule.enforce_free_item_qty = 0 + pricing_rule.dont_enforce_free_item_qty = 1 pricing_rule.save() - # Test 2 : Deleted free item will not be fetched again on save without enfrocement + # Test 2 : Deleted free item will not be fetched again on save without enforcement so.items.pop(1) so.save() so.reload() @@ -1287,7 +1287,7 @@ def make_pricing_rule(**args): "discount_amount": args.discount_amount or 0.0, "apply_multiple_pricing_rules": args.apply_multiple_pricing_rules or 0, "has_priority": args.has_priority or 0, - "enforce_free_item_qty": args.enforce_free_item_qty or 1, + "enforce_free_item_qty": args.dont_enforce_free_item_qty or 0, } ) diff --git a/erpnext/accounts/doctype/pricing_rule/utils.py b/erpnext/accounts/doctype/pricing_rule/utils.py index 7fb26402125..fe81945ad41 100644 --- a/erpnext/accounts/doctype/pricing_rule/utils.py +++ b/erpnext/accounts/doctype/pricing_rule/utils.py @@ -691,8 +691,8 @@ def apply_pricing_rule_for_free_items(doc, pricing_rule_args): args.pop((item.item_code, item.pricing_rules)) for free_item in args.values(): - if doc.is_new() or frappe.get_value( - "Pricing Rule", free_item["pricing_rules"], "enforce_free_item_qty" + if doc.is_new() or not frappe.get_value( + "Pricing Rule", free_item["pricing_rules"], "dont_enforce_free_item_qty" ): doc.append("items", free_item) diff --git a/erpnext/stock/doctype/pick_list/test_pick_list.py b/erpnext/stock/doctype/pick_list/test_pick_list.py index 95a79f6caea..3a043ff9fca 100644 --- a/erpnext/stock/doctype/pick_list/test_pick_list.py +++ b/erpnext/stock/doctype/pick_list/test_pick_list.py @@ -914,7 +914,7 @@ class TestPickList(FrappeTestCase): "is_recursive": 1, "recurse_for": 2, "free_qty": 1, - "enforce_free_item_qty": 1, + "dont_enforce_free_item_qty": 0, "company": "_Test Company", "customer": "_Test Customer", }