Last active
October 6, 2022 10:47
-
-
Save karthikeyan5/c0fb0f60ce9b92bbd41bc83a8d4b264e to your computer and use it in GitHub Desktop.
Collection of some Frappe framework custom script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
}) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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')); | |
}); | |
} | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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