make sensitive fields read only in item master if sle exists

This commit is contained in:
Nabin Hait 2011-07-10 12:48:13 +05:30
parent fe11736995
commit 12b58ec5cc
2 changed files with 22 additions and 2 deletions

View File

@ -1,6 +1,18 @@
cur_frm.cscript.refresh = function(doc) { cur_frm.cscript.refresh = function(doc) {
if(cint(doc.is_local) && doc.has_serial_no) set_field_permlevel('has_serial_no', 1); // make sensitive fields(has_serial_no, is_stock_item, valuation_method)
if(cint(doc.is_local) && doc.is_stock_item) set_field_permlevel('is_stock_item', 1); // read only if any stock ledger entry exists
if ((!doc.__islocal) && (doc.is_stock_item == 'Yes')) {
var callback = function(r, rt) {
if (r.message == 'exists') permlevel = 1;
else permlevel = 0;
set_field_permlevel('has_serial_no', permlevel);
set_field_permlevel('is_stock_item', permlevel);
set_field_permlevel('valuation_method', permlevel);
}
$c_obj(make_doclist(doc.doctype, doc.name),'check_if_sle_exists','',callback);
}
} }

View File

@ -170,3 +170,11 @@ Total Available Qty: %s
} }
return str(ret) return str(ret)
def check_if_sle_exists(self):
"""
checks if any stock ledger entry exists for this item
"""
sle = sql("select name from `tabStock Ledger Entry` where item_code = %s and ifnull(is_cancelled, 'No') = 'No'", self.doc.name)
return sle and 'exists' or 'not exists'