From 233a19a373b76b8ee3fa6327a2b1090d4cc1c1ba Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Fri, 7 Jul 2017 13:05:11 +0530 Subject: [PATCH 1/3] [fix] reset flag after promise --- erpnext/public/js/controllers/transaction.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index c4f9e8a8add..d6f2863ba03 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -69,7 +69,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ if(!frm.doc.apply_discount_on) { frappe.msgprint(__("Please set 'Apply Additional Discount On'")); - return + return; } frm.via_discount_percentage = true; @@ -83,17 +83,15 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ var discount_amount = flt(total*flt(frm.doc.additional_discount_percentage) / 100, precision("discount_amount")); - frm.set_value("discount_amount", discount_amount); - delete frm.via_discount_percentage; + frm.set_value("discount_amount", discount_amount) + .then(() => delete frm.via_discount_percentage); }); frappe.ui.form.on(this.frm.doctype, "discount_amount", function(frm) { frm.cscript.set_dynamic_labels(); if (!frm.via_discount_percentage) { - frm.via_discount_amount = true; - frm.set_value("additional_discount_percentage", 0); - delete frm.via_discount_amount; + frm.doc.additional_discount_percentage = 0; } frm.cscript.calculate_taxes_and_totals(); From 6705ab3eaf2e9fa0b2c3d0c51ca4a6bd4173526c Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Fri, 7 Jul 2017 13:14:08 +0530 Subject: [PATCH 2/3] [fix] discount setting multiple times --- erpnext/public/js/controllers/transaction.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index d6f2863ba03..3defa193fbf 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -76,7 +76,8 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ if(frm.doc.additional_discount_percentage && frm.doc.discount_amount) { // Reset discount amount and net / grand total - frm.set_value("discount_amount", 0); + frm.doc.discount_amount = 0; + frm.cscript.calculate_taxes_and_totals(); } var total = flt(frm.doc[frappe.model.scrub(frm.doc.apply_discount_on)]); From 19d52dc5038c898edee6390af383074698f0e045 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Fri, 7 Jul 2017 13:23:23 +0530 Subject: [PATCH 3/3] [fix] remove extra flag --- erpnext/public/js/controllers/transaction.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index 3defa193fbf..fd91227cb67 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -63,10 +63,6 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ }); frappe.ui.form.on(this.frm.doctype, "additional_discount_percentage", function(frm) { - if (frm.via_discount_amount) { - return; - } - if(!frm.doc.apply_discount_on) { frappe.msgprint(__("Please set 'Apply Additional Discount On'")); return;