Skip to content

Instantly share code, notes, and snippets.

@vijaywm
Last active December 11, 2019 00:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vijaywm/c5f0897bc7bf1b953a1e21a151537857 to your computer and use it in GitHub Desktop.
Save vijaywm/c5f0897bc7bf1b953a1e21a151537857 to your computer and use it in GitHub Desktop.
frappe snippets
frappe.ui.form.on("Quotation Item", "item_code", function(frm, cdt, cdn) {
ct = locals[cdt][cdn]
frappe.after_ajax(function() {
frappe.call({
method: "multilingual_extension.item_description.fetch_item_description",
args:{
customer_code: frm.doc.customer,
item_code: ct.item_code,
},
callback: function(r) {
frappe.model.set_value(cdt, cdn, "description", r.message);
}
})
});
});
//Replace "DocType" with the source DocType
frappe.ui.form.on("DocType", {
//The trigger can be changed, but refresh must be used to use a button
refresh: function(frm) {
//The following line creates a button.
frm.add_custom_button(__("Update"),
//The function below is triggered when the button is pressed.
function() {
frappe.call({
"method": "frappe.client.set_value",
"args": {
//replace "Target DocType" with the actual target doctype
"doctype": "Target DocType",
//replace target_doctype_link with a link to the document to be changed
"name": frm.doc.target_doctype_link,
"fieldname": {
//You can update as many fields as you want.
"target_field_1": frm.doc.source_field_1,
"target_field_2": frm.doc.source_field_2,
"target_field_3": frm.doc.source_field_3,
"target_field_4": frm.doc.source_field_4,
"target_field_5": frm.doc.source_field_5 //Make sure that you do not put a comma over the last value
},
}
});
});
}
});
Now for the non system users, we can set a home page when they login via hooks.py based on the role.
To when library members sign in, they must be redirected to the article page, to set this open library_management/hooks.py and add this:
role_home_page = {
"Library Member": "article"
}
frm.set_query("state", function(doc) {
return {
query: "ambavideo.ambavideo.controllers.queries.states_query",
filters: { "country": doc.country }
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment