[fixed] frappe.require is now async 💥
This commit is contained in:
@@ -1,13 +1,85 @@
|
||||
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
||||
// License: GNU General Public License v3. See license.txt
|
||||
|
||||
frappe.provide("erpnext");
|
||||
frappe.require([
|
||||
"assets/erpnext/js/controllers/taxes_and_totals.js",
|
||||
"assets/erpnext/js/utils.js",
|
||||
"assets/erpnext/js/utils/item_selector.js"]);
|
||||
|
||||
erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
||||
setup: function() {
|
||||
frappe.ui.form.on(this.frm.doctype + " Item", "rate", function(frm, cdt, cdn) {
|
||||
var item = frappe.get_doc(cdt, cdn);
|
||||
frappe.model.round_floats_in(item, ["rate", "price_list_rate"]);
|
||||
|
||||
if(item.price_list_rate) {
|
||||
item.discount_percentage = flt((1 - item.rate / item.price_list_rate) * 100.0, precision("discount_percentage", item));
|
||||
} else {
|
||||
item.discount_percentage = 0.0;
|
||||
}
|
||||
|
||||
cur_frm.cscript.set_gross_profit(item);
|
||||
cur_frm.cscript.calculate_taxes_and_totals();
|
||||
})
|
||||
|
||||
frappe.ui.form.on(this.frm.cscript.tax_table, "rate", function(frm, cdt, cdn) {
|
||||
cur_frm.cscript.calculate_taxes_and_totals();
|
||||
})
|
||||
|
||||
frappe.ui.form.on(this.frm.cscript.tax_table, "tax_amount", function(frm, cdt, cdn) {
|
||||
cur_frm.cscript.calculate_taxes_and_totals();
|
||||
})
|
||||
|
||||
frappe.ui.form.on(this.frm.cscript.tax_table, "row_id", function(frm, cdt, cdn) {
|
||||
cur_frm.cscript.calculate_taxes_and_totals();
|
||||
})
|
||||
|
||||
frappe.ui.form.on(this.frm.cscript.tax_table, "included_in_print_rate", function(frm, cdt, cdn) {
|
||||
cur_frm.cscript.set_dynamic_labels();
|
||||
cur_frm.cscript.calculate_taxes_and_totals();
|
||||
})
|
||||
|
||||
frappe.ui.form.on(this.frm.doctype, "apply_discount_on", function(frm) {
|
||||
if(frm.doc.additional_discount_percentage) {
|
||||
frm.trigger("additional_discount_percentage");
|
||||
} else {
|
||||
cur_frm.cscript.calculate_taxes_and_totals();
|
||||
}
|
||||
})
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
frm.via_discount_percentage = true;
|
||||
|
||||
if(frm.doc.additional_discount_percentage && frm.doc.discount_amount) {
|
||||
// Reset discount amount and net / grand total
|
||||
frm.set_value("discount_amount", 0);
|
||||
}
|
||||
|
||||
var total = flt(frm.doc[frappe.model.scrub(frm.doc.apply_discount_on)]);
|
||||
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;
|
||||
});
|
||||
|
||||
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.cscript.calculate_taxes_and_totals();
|
||||
});
|
||||
|
||||
},
|
||||
onload: function() {
|
||||
var me = this;
|
||||
//this.frm.show_print_first = true;
|
||||
@@ -128,7 +200,6 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
||||
},
|
||||
|
||||
send_sms: function() {
|
||||
frappe.require("assets/erpnext/js/sms_manager.js");
|
||||
var sms_man = new SMSManager(this.frm.doc);
|
||||
},
|
||||
|
||||
@@ -911,80 +982,4 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
frappe.ui.form.on(cur_frm.doctype + " Item", "rate", function(frm, cdt, cdn) {
|
||||
var item = frappe.get_doc(cdt, cdn);
|
||||
frappe.model.round_floats_in(item, ["rate", "price_list_rate"]);
|
||||
|
||||
if(item.price_list_rate) {
|
||||
item.discount_percentage = flt((1 - item.rate / item.price_list_rate) * 100.0, precision("discount_percentage", item));
|
||||
} else {
|
||||
item.discount_percentage = 0.0;
|
||||
}
|
||||
|
||||
cur_frm.cscript.set_gross_profit(item);
|
||||
cur_frm.cscript.calculate_taxes_and_totals();
|
||||
})
|
||||
|
||||
frappe.ui.form.on(cur_frm.cscript.tax_table, "rate", function(frm, cdt, cdn) {
|
||||
cur_frm.cscript.calculate_taxes_and_totals();
|
||||
})
|
||||
|
||||
frappe.ui.form.on(cur_frm.cscript.tax_table, "tax_amount", function(frm, cdt, cdn) {
|
||||
cur_frm.cscript.calculate_taxes_and_totals();
|
||||
})
|
||||
|
||||
frappe.ui.form.on(cur_frm.cscript.tax_table, "row_id", function(frm, cdt, cdn) {
|
||||
cur_frm.cscript.calculate_taxes_and_totals();
|
||||
})
|
||||
|
||||
frappe.ui.form.on(cur_frm.cscript.tax_table, "included_in_print_rate", function(frm, cdt, cdn) {
|
||||
cur_frm.cscript.set_dynamic_labels();
|
||||
cur_frm.cscript.calculate_taxes_and_totals();
|
||||
})
|
||||
|
||||
frappe.ui.form.on(cur_frm.doctype, "apply_discount_on", function(frm) {
|
||||
if(frm.doc.additional_discount_percentage) {
|
||||
frm.trigger("additional_discount_percentage");
|
||||
} else {
|
||||
cur_frm.cscript.calculate_taxes_and_totals();
|
||||
}
|
||||
})
|
||||
|
||||
frappe.ui.form.on(cur_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
|
||||
}
|
||||
|
||||
frm.via_discount_percentage = true;
|
||||
|
||||
if(frm.doc.additional_discount_percentage && frm.doc.discount_amount) {
|
||||
// Reset discount amount and net / grand total
|
||||
frm.set_value("discount_amount", 0);
|
||||
}
|
||||
|
||||
var total = flt(frm.doc[frappe.model.scrub(frm.doc.apply_discount_on)]);
|
||||
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;
|
||||
});
|
||||
|
||||
frappe.ui.form.on(cur_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.cscript.calculate_taxes_and_totals();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user