Hello dears
I`m planning to make the entire rates in sales order are read only if they are exist
if not exist the user has the ability to put the price manually
i`v tried the following
frappe.ui.form.on(“Sales Order”,“onload”, function(frm, cdt, cdn) {
var df = frappe.meta.get_docfield(“Sales Order Item”,“rate”, cur_frm.doc.name);
if (df){
df.read_only = 1;
}
});
but doesn`t work
any idea about that ??
Try something like below, not tested.
frappe.ui.form.on("Sales Order", "items_on_form_rendered", function(frm, grid_row, cdt, cdn){
var grid_row = cur_frm.open_grid_row();
if(grid_row.doc.price_list_rate){
grid_row.grid_form.fields_dict.rate.df.read_only = true;
grid_row.grid_form.fields_dict.rate.refresh();
}
});
but my above script is working well without if condition
it makes rate field read only but when i use if condition it doesn`t work
use grid_row.doc.rate
and try again
df is always true, it is the metadata of the field, so you are not checking rate value there.
either you need to loop each row to check if rate value if set or use code above to make it readonly on items form load
Strange it works on my machine.
any error? Did you Reload page?
yes cleared cache and reloaded the page
also th price is editable even it has a price in price list
no error in console?
can you show screenshot of Sales Order page?
try again with this change
I think erpnext sales order script is setting rate field to be editable, so added some delay to make it readonly
try this,
function make_rate_readonly(grid_row){
var grid_row = cur_frm.open_grid_row();
var child = grid_row.doc;
setTimeout(function(){
if(child.price_list_rate){
grid_row.toggle_editable("rate", false);
}else{
grid_row.toggle_editable("rate", true);
}
grid_row.grid_form.fields_dict.rate.refresh();
}, 500);
}
frappe.ui.form.on("Sales Order", "items_on_form_rendered", function(doc, grid_row){
make_rate_readonly();
});
frappe.ui.form.on("Sales Order Item", "item_code", function(frm, cdt, cdn){
make_rate_readonly();
});
1 Like
That works great man 
Thank you for your efforts
1 Like