Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added option to enforce free item qty in pricing rule #45750

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

mihir-kandoi
Copy link
Contributor

@mihir-kandoi mihir-kandoi commented Feb 5, 2025

Reference support ticket 20447

Currently ERPNext forces user to mandatorily supply free items from pricing rule. This is done by fetching free items and adding it into child table whenever a document with pricing rule is saved. Normally, free items are at discretion of seller.

This PR adds a new option in Pricing Rule called Enforce Free Item Qty which will keep the behaviour same as before. However, upon disabling this checkbox, free items won't be fetched when document is saved.

Free items will now only be fetched when user adds an item with a free items pricing rule in the child table, not when document is saved, allowing the user to delete the free item as they wish.

This PR is incomplete. DO NOT MERGE.

@github-actions github-actions bot added the needs-tests This PR needs automated unit-tests. label Feb 5, 2025
@mihir-kandoi
Copy link
Contributor Author

@rohitwaghchaure please note some things:

  1. I am setting enforcement default value as 1 so as to not mess with user sites that are actively using the old flow for a long time
  2. There is a slight problem with this approach, using the REST API with enforcement off, user will not be able to fetch free items. Not sure what can be the fix here.
  3. Once you approve the work, I will add in documentation link so the Documentation test failing is expected for now

@@ -645,7 +646,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"):
elif pricing_rule.get("free_item") and pricing_rule.get("enforce_free_item_qty"):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is called only on the frontend. It prevents free item being deleted on change of qty of that free item.

@@ -713,7 +713,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():
doc.append("items", free_item)
if frappe.get_value("Pricing Rule", free_item["pricing_rules"], "enforce_free_item_qty"):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This if condition will prevent free items being fetched on document save if enforcement is off

@mihir-kandoi
Copy link
Contributor Author

@rohitwaghchaure Can we create a whitelisted functions that will fetch free items? User can call that function through REST API right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-tests This PR needs automated unit-tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant