Pn 31 apply discount in pos next invoices only#176
Pn 31 apply discount in pos next invoices only#176MostafaKadry wants to merge 10 commits intodevelopfrom
Conversation
…filtering get_promotions by `Promotion Scheme POS Profile`
…y_offers funciton
…oice API to the pricing rule override, now using the passed POS profile.
…and improve filtering efficiency.
Deep Code Review — PR #176Files changed: 8 | +188 / -15 | 6 commits Overall AssessmentThis PR adds POS Profile-specific filtering for Promotional Schemes — letting admins restrict which promotions apply to which POS Profile. It uses a child table on the Promotional Scheme doctype and filters at both the API level ( Issues1. Correlated subqueries in AND (
`tabPricing Rule`.promotional_scheme IS NULL
OR `tabPricing Rule`.promotional_scheme = ''
OR NOT EXISTS (
SELECT 1 FROM `tabPromotion Scheme POS Profile`
WHERE parent = `tabPricing Rule`.promotional_scheme
)
OR EXISTS (
SELECT 1 FROM `tabPromotion Scheme POS Profile`
WHERE parent = `tabPricing Rule`.promotional_scheme
AND pos_profile = %(pos_profile)s
)
)This adds two correlated subqueries per pricing rule evaluation. ERPNext calls The Suggestion: Consider adding a composite index, or pre-filtering promotion scheme names and injecting an 2. The new POS Profile filtering in 3. Custom field uses The custom field JSON defines: "fieldname": "pos_profiles",
"name": "Promotional Scheme-custom_pos_profiles"In Frappe, custom fields are accessed with the 4. The monkey-patch applies to ALL calls to
For the per-item path, However, if ERPNext internally calls 5. scheme_names = [s["name"] for s in schemes]
rows = frappe.get_all(
"Promotion Scheme POS Profile",
filters={"parent": ["in", scheme_names]},
...
)If 6. Removed comment in The PR removes this comment: # No Frappe hook exists for non-whitelisted module-level functions (override_whitelisted_methods
# only works for @frappe.whitelist() HTTP endpoints, override_doctype_class only for DocType
# classes). This is the standard Python module init approach — runs once at import.This comment explained why monkey-patching is used instead of a Frappe hook — which is valuable context for anyone reading the code. The same explanation exists in Code Quality7. Frappe auto-generates the actual fieldname as 8. The This PR uses Frappe's 9. Missing newline at end of JSON files Both Risk Assessment
VerdictLooks good overall — minor issues only. The core mechanism (monkey-patched SQL condition + API-level filtering) is correct and the |
…plementing request-level caching and using IN clauses to improve query efficiency.
…t-in-pos-next-invoices-only' into PN-31-apply-discount-in-pos-next-invoices-only
No description provided.