From 914f4bffea3446df6753f040c8fffd356406b6bb Mon Sep 17 00:00:00 2001 From: Sanket322 Date: Mon, 20 Jan 2025 18:01:31 +0530 Subject: [PATCH 1/3] fix: use user defined discount amount or default (cherry picked from commit e2a32b72578c2ed3dd54297cca54f293c4131a25) --- erpnext/accounts/doctype/pricing_rule/pricing_rule.py | 4 ++-- erpnext/public/js/controllers/transaction.js | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py index 2f833237763..fce25daf1e1 100644 --- a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py +++ b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py @@ -328,8 +328,8 @@ def get_pricing_rule_for_item(args, doc=None, for_validate=False): "parent": args.parent, "parenttype": args.parenttype, "child_docname": args.get("child_docname"), - "discount_percentage": 0.0, - "discount_amount": 0, + "discount_percentage": args.get("discount_percentage") or 0.0, + "discount_amount": args.get("discount_amount") or 0.0, } ) diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index 9f8aa84f836..49953f3224f 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -1527,7 +1527,9 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe "serial_no": d.serial_no, "batch_no": d.batch_no, "price_list_rate": d.price_list_rate, - "conversion_factor": d.conversion_factor || 1.0 + "conversion_factor": d.conversion_factor || 1.0, + "discount_percentage" : d.discount_percentage, + "discount_amount" : d.discount_amount, }); // if doctype is Quotation Item / Sales Order Iten then add Margin Type and rate in item_list From c484563beacccbd05b50bf02d22e6d30fcf98ed7 Mon Sep 17 00:00:00 2001 From: Sanket322 Date: Thu, 23 Jan 2025 11:55:12 +0530 Subject: [PATCH 2/3] fix: remove applied pricing rule (cherry picked from commit 50223c6bec3e5a497034246945aa0188a415921b) # Conflicts: # erpnext/public/js/controllers/transaction.js --- .../doctype/pricing_rule/pricing_rule.py | 2 - erpnext/public/js/controllers/transaction.js | 46 +++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py index fce25daf1e1..902af5c2a77 100644 --- a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py +++ b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py @@ -328,8 +328,6 @@ def get_pricing_rule_for_item(args, doc=None, for_validate=False): "parent": args.parent, "parenttype": args.parenttype, "child_docname": args.get("child_docname"), - "discount_percentage": args.get("discount_percentage") or 0.0, - "discount_amount": args.get("discount_amount") or 0.0, } ) diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index 49953f3224f..99022e867cc 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -1443,6 +1443,41 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe } } +<<<<<<< HEAD +======= + remove_pricing_rule_for_item(item) { + // capture pricing rule before removing it to delete free items + let removed_pricing_rule = item.pricing_rules; + if (item.pricing_rules){ + let me = this; + return this.frm.call({ + method: "erpnext.accounts.doctype.pricing_rule.pricing_rule.remove_pricing_rule_for_item", + args: { + pricing_rules: item.pricing_rules, + item_details: { + "doctype": item.doctype, + "name": item.name, + "item_code": item.item_code, + "pricing_rules": item.pricing_rules, + "parenttype": item.parenttype, + "parent": item.parent, + "price_list_rate": item.price_list_rate + }, + item_code: item.item_code, + rate: item.price_list_rate, + }, + callback: function(r) { + if (!r.exc && r.message) { + me.remove_pricing_rule(r.message, removed_pricing_rule, item.name); + me.calculate_taxes_and_totals(); + if(me.frm.doc.apply_discount_on) me.frm.trigger("apply_discount_on"); + } + } + }); + } + } + +>>>>>>> 50223c6bec (fix: remove applied pricing rule) apply_pricing_rule(item, calculate_taxes_and_totals) { var me = this; var args = this._get_args(item); @@ -1705,7 +1740,11 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe }); } +<<<<<<< HEAD remove_pricing_rule(item) { +======= + remove_pricing_rule(item, removed_pricing_rule, row_name) { +>>>>>>> 50223c6bec (fix: remove applied pricing rule) let me = this; const fields = ["discount_percentage", "discount_amount", "margin_rate_or_amount", "rate_with_margin"]; @@ -1739,6 +1778,13 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe me.trigger_price_list_rate(); } + else if(!item.is_free_item && row_name){ + me.frm.doc.items.forEach(d => { + if (d.name != row_name) return; + + Object.assign(d, item); + }); + } } trigger_price_list_rate() { From 9eda931b97d422408f60fa96bfbd84b59088acc3 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Wed, 29 Jan 2025 11:54:42 +0530 Subject: [PATCH 3/3] chore: resolve conflicts --- erpnext/public/js/controllers/transaction.js | 48 -------------------- 1 file changed, 48 deletions(-) diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index 99022e867cc..a424d01489d 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -1443,41 +1443,6 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe } } -<<<<<<< HEAD -======= - remove_pricing_rule_for_item(item) { - // capture pricing rule before removing it to delete free items - let removed_pricing_rule = item.pricing_rules; - if (item.pricing_rules){ - let me = this; - return this.frm.call({ - method: "erpnext.accounts.doctype.pricing_rule.pricing_rule.remove_pricing_rule_for_item", - args: { - pricing_rules: item.pricing_rules, - item_details: { - "doctype": item.doctype, - "name": item.name, - "item_code": item.item_code, - "pricing_rules": item.pricing_rules, - "parenttype": item.parenttype, - "parent": item.parent, - "price_list_rate": item.price_list_rate - }, - item_code: item.item_code, - rate: item.price_list_rate, - }, - callback: function(r) { - if (!r.exc && r.message) { - me.remove_pricing_rule(r.message, removed_pricing_rule, item.name); - me.calculate_taxes_and_totals(); - if(me.frm.doc.apply_discount_on) me.frm.trigger("apply_discount_on"); - } - } - }); - } - } - ->>>>>>> 50223c6bec (fix: remove applied pricing rule) apply_pricing_rule(item, calculate_taxes_and_totals) { var me = this; var args = this._get_args(item); @@ -1563,8 +1528,6 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe "batch_no": d.batch_no, "price_list_rate": d.price_list_rate, "conversion_factor": d.conversion_factor || 1.0, - "discount_percentage" : d.discount_percentage, - "discount_amount" : d.discount_amount, }); // if doctype is Quotation Item / Sales Order Iten then add Margin Type and rate in item_list @@ -1740,11 +1703,7 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe }); } -<<<<<<< HEAD remove_pricing_rule(item) { -======= - remove_pricing_rule(item, removed_pricing_rule, row_name) { ->>>>>>> 50223c6bec (fix: remove applied pricing rule) let me = this; const fields = ["discount_percentage", "discount_amount", "margin_rate_or_amount", "rate_with_margin"]; @@ -1778,13 +1737,6 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe me.trigger_price_list_rate(); } - else if(!item.is_free_item && row_name){ - me.frm.doc.items.forEach(d => { - if (d.name != row_name) return; - - Object.assign(d, item); - }); - } } trigger_price_list_rate() {