From bde9e8958205c8afdcd107c75fd680b9dd6b9b65 Mon Sep 17 00:00:00 2001 From: Anand Baburajan Date: Tue, 25 Jul 2023 20:32:57 +0530 Subject: [PATCH] fix: apply discount on item after applying price list (#36125) --- erpnext/public/js/controllers/transaction.js | 13 +++++++++++++ erpnext/selling/sales_common.js | 10 ---------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index a00911540ab7..5ae00c34088c 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -1068,6 +1068,16 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ this.frm.set_df_property("conversion_rate", "read_only", erpnext.stale_rate_allowed() ? 0 : 1); }, + apply_discount_on_item: function(doc, cdt, cdn, field) { + var item = frappe.get_doc(cdt, cdn); + if(!item.price_list_rate) { + item[field] = 0.0; + } else { + this.price_list_rate(doc, cdt, cdn); + } + this.set_gross_profit(item); + }, + shipping_rule: function() { var me = this; if(this.frm.doc.shipping_rule) { @@ -1720,6 +1730,9 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ () => { if(args.items.length) { me._set_values_for_item_list(r.message.children); + $.each(r.message.children || [], function(i, d) { + me.apply_discount_on_item(d, d.doctype, d.name, 'discount_percentage'); + }); } }, () => { me.in_apply_price_list = false; } diff --git a/erpnext/selling/sales_common.js b/erpnext/selling/sales_common.js index cf1d19192a19..f4e5f8a37f75 100644 --- a/erpnext/selling/sales_common.js +++ b/erpnext/selling/sales_common.js @@ -145,16 +145,6 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({ this.apply_discount_on_item(doc, cdt, cdn, 'discount_amount'); }, - apply_discount_on_item: function(doc, cdt, cdn, field) { - var item = frappe.get_doc(cdt, cdn); - if(!item.price_list_rate) { - item[field] = 0.0; - } else { - this.price_list_rate(doc, cdt, cdn); - } - this.set_gross_profit(item); - }, - commission_rate: function() { this.calculate_commission(); },