From 396727e26f5dbef7e203df9ffdd0f8f8dddee7b0 Mon Sep 17 00:00:00 2001 From: diptanilsaha Date: Tue, 3 Mar 2026 14:08:49 +0530 Subject: [PATCH 1/2] fix(pricing_rule): strict validation of `transaction_type` (cherry picked from commit 7ec0354a79176f858aff3d99dce1c5a06b2cf77d) --- erpnext/accounts/doctype/pricing_rule/pricing_rule.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py index 5a4f3ca3249..c450d080522 100644 --- a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py +++ b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py @@ -346,8 +346,7 @@ def apply_pricing_rule(args, doc=None): args = frappe._dict(args) - if not args.transaction_type: - set_transaction_type(args) + set_transaction_type(args) # list of dictionaries out = [] @@ -684,7 +683,7 @@ def remove_pricing_rules(item_list): def set_transaction_type(args): - if args.transaction_type: + if args.transaction_type in ["buying", "selling"]: return if args.doctype in ("Opportunity", "Quotation", "Sales Order", "Delivery Note", "Sales Invoice"): args.transaction_type = "selling" From e4ce6e4e6ffcbc22841fe58c4ef33a303c63a7a0 Mon Sep 17 00:00:00 2001 From: diptanilsaha Date: Tue, 3 Mar 2026 14:41:30 +0530 Subject: [PATCH 2/2] refactor: renamed `args` to `pricing_ctx` in `set_transaction_type` for clarity (cherry picked from commit 6342e7830546b9a952146eb349534bfb6874d506) --- .../doctype/pricing_rule/pricing_rule.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py index c450d080522..810c50852c5 100644 --- a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py +++ b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py @@ -682,23 +682,23 @@ def remove_pricing_rules(item_list): return out -def set_transaction_type(args): - if args.transaction_type in ["buying", "selling"]: +def set_transaction_type(pricing_ctx: frappe._dict) -> None: + if pricing_ctx.transaction_type in ["buying", "selling"]: return - if args.doctype in ("Opportunity", "Quotation", "Sales Order", "Delivery Note", "Sales Invoice"): - args.transaction_type = "selling" - elif args.doctype in ( + if pricing_ctx.doctype in ("Opportunity", "Quotation", "Sales Order", "Delivery Note", "Sales Invoice"): + pricing_ctx.transaction_type = "selling" + elif pricing_ctx.doctype in ( "Material Request", "Supplier Quotation", "Purchase Order", "Purchase Receipt", "Purchase Invoice", ): - args.transaction_type = "buying" - elif args.customer: - args.transaction_type = "selling" + pricing_ctx.transaction_type = "buying" + elif pricing_ctx.customer: + pricing_ctx.transaction_type = "selling" else: - args.transaction_type = "buying" + pricing_ctx.transaction_type = "buying" @frappe.whitelist()