Skip to content

Instantly share code, notes, and snippets.

@munir131
Forked from karthikeyan5/Supplier_UID.js
Created October 6, 2022 10:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save munir131/0364950f871a6b169a31c5d09cfa2a76 to your computer and use it in GitHub Desktop.
Save munir131/0364950f871a6b169a31c5d09cfa2a76 to your computer and use it in GitHub Desktop.
Collection of some Frappe framework custom script
frappe.ui.form.on('Quotation Item', {
item_code(frm, cdt, cdn) {
let row = frappe.get_doc(cdt, cdn);
frappe.call({
type: "GET",
method: "erpnext.stock.get_item_details.get_default_bom",
args: {
"item_code": row.item_code
},
callback: function(r) {
if(r) {
setTimeout(function() {
set_item_price_from_bom(frm, cdt, cdn, r.message);
}, 500)
}
}
})
}
})
let set_item_price_from_bom = function(frm, cdt, cdn, bom) {
frappe.db.get_value("BOM", {name:bom}, 'total_cost')
.then((data) => {
frappe.model.set_value(cdt, cdn,'rate',data.message.total_cost)
})
}
// Here, Supplier DocType Contains a custom field (readonly) Called "UID".
// This feild is auto populated with the next number based on the highest UID in the supplier table.
frappe.ui.form.on("Supplier", {
validate: function(frm) {
if(frm.doc.__islocal == '1'){
frappe.db.get_list("Supplier", {fields:'uid', order_by:"uid desc",limit:1}).then((data) => {
frm.set_value("uid",String(parseInt(data[0].uid)+1).padStart(5,'0'));
});
}
}
});
frappe.ui.form.on('Purchase Taxes and Charges', 'account_head', function(frm, cdt, cdn){
if (locals[cdt][cdn].account_head.indexOf("TDS Deduct") != -1){
frappe.run_serially([
() => frappe.model.set_value(cdt, cdn,'charge_type',"On Net Total"),
() => frappe.model.set_value(cdt, cdn,'category',"Total"),
() => frappe.model.set_value(cdt, cdn,'add_deduct_tax',"Deduct"),
() => setTimeout(function() {
frappe.model.set_value(cdt, cdn,'rate',frm.doc.tds_percent)
}, 500)
]);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment