[fix] Use add_fetch in Product Bundle, Maintenance Visit and Maintenance Schedule instead of redundant get_item_details method

This commit is contained in:
Anand Doshi 2015-09-15 11:50:27 +05:30
parent 0fd3347148
commit 86102064a5
6 changed files with 17 additions and 46 deletions

View File

@ -12,9 +12,8 @@ cur_frm.fields_dict.new_item_code.get_query = function() {
}
cur_frm.fields_dict.new_item_code.query_description = __('Please select Item where "Is Stock Item" is "No" and "Is Sales Item" is "Yes" and there is no other Product Bundle');
cur_frm.cscript.item_code = function(doc, dt, dn) {
var d = locals[dt][dn];
if (d.item_code){
return get_server_fields('get_item_details', d.item_code, 'items', doc ,dt, dn, 1);
}
cur_frm.cscript.onload = function() {
// set add fetch for item_code's item_name and description
cur_frm.add_fetch('item_code', 'stock_uom', 'uom');
cur_frm.add_fetch('item_code', 'description', 'description');
}

View File

@ -22,14 +22,6 @@ class ProductBundle(Document):
if frappe.db.get_value("Item", self.new_item_code, "is_stock_item"):
frappe.throw(_("Parent Item {0} must not be a Stock Item").format(self.new_item_code))
def get_item_details(self, name):
det = frappe.db.sql("""select description, stock_uom from `tabItem`
where name = %s""", name)
return {
'description' : det and det[0][0] or '',
'uom': det and det[0][1] or ''
}
def get_new_item_code(doctype, txt, searchfield, start, page_len, filters):
from erpnext.controllers.queries import get_match_cond

View File

@ -80,11 +80,16 @@ erpnext.support.MaintenanceSchedule = frappe.ui.form.Controller.extend({
$.extend(cur_frm.cscript, new erpnext.support.MaintenanceSchedule({frm: cur_frm}));
cur_frm.cscript.onload = function(doc, dt, dn) {
if(!doc.status) set_multiple(dt,dn,{status:'Draft'});
if(!doc.status) set_multiple(dt,dn,{status:'Draft'});
if(doc.__islocal){
set_multiple(dt,dn,{transaction_date:get_today()});
}
// set add fetch for item_code's item_name and description
cur_frm.add_fetch('item_code', 'item_name', 'item_name');
cur_frm.add_fetch('item_code', 'description', 'description');
if(doc.__islocal){
set_multiple(dt,dn,{transaction_date:get_today()});
}
}
cur_frm.fields_dict['customer_address'].get_query = function(doc, cdt, cdn) {
@ -106,14 +111,6 @@ cur_frm.fields_dict['items'].grid.get_field('item_code').get_query = function(do
}
}
cur_frm.cscript.item_code = function(doc, cdt, cdn) {
var d = locals[cdt][cdn];
if (d.item_code) {
return get_server_fields('get_item_details', d.item_code, 'items',
doc, cdt, cdn, 1);
}
}
cur_frm.cscript.generate_schedule = function(doc, cdt, cdn) {
if (!doc.__islocal) {
return $c('runserverobj', args={'method':'generate_schedule', 'docs':doc},

View File

@ -11,16 +11,6 @@ from erpnext.utilities.transaction_base import TransactionBase, delete_events
from erpnext.stock.utils import get_valid_serial_nos
class MaintenanceSchedule(TransactionBase):
def get_item_details(self, item_code):
item = frappe.db.sql("""select item_name, description from `tabItem`
where name=%s""", (item_code), as_dict=1)
ret = {
'item_name': item and item[0]['item_name'] or '',
'description' : item and item[0]['description'] or ''
}
return ret
def generate_schedule(self):
self.set('schedules', [])
frappe.db.sql("""delete from `tabMaintenance Schedule Detail`

View File

@ -61,6 +61,10 @@ $.extend(cur_frm.cscript, new erpnext.support.MaintenanceVisit({frm: cur_frm}));
cur_frm.cscript.onload = function(doc, dt, dn) {
if(!doc.status) set_multiple(dt,dn,{status:'Draft'});
if(doc.__islocal) set_multiple(dt,dn,{mntc_date:get_today()});
// set add fetch for item_code's item_name and description
cur_frm.add_fetch('item_code', 'item_name', 'item_name');
cur_frm.add_fetch('item_code', 'description', 'description');
}
cur_frm.fields_dict['customer_address'].get_query = function(doc, cdt, cdn) {
@ -81,14 +85,6 @@ cur_frm.fields_dict['purposes'].grid.get_field('item_code').get_query = function
}
}
cur_frm.cscript.item_code = function(doc, cdt, cdn) {
var d = locals[cdt][cdn];
if (d.item_code) {
return get_server_fields('get_item_details',d.item_code, 'purposes',doc,cdt,cdn,1);
}
}
cur_frm.fields_dict.customer.get_query = function(doc,cdt,cdn) {
return {query: "erpnext.controllers.queries.customer_query" }
}

View File

@ -11,9 +11,6 @@ class MaintenanceVisit(TransactionBase):
def get_feed(self):
return _("To {0}").format(self.customer_name)
def get_item_details(self, item_code):
return frappe.db.get_value("Item", item_code, ["item_name", "description"], as_dict=1)
def validate_serial_no(self):
for d in self.get('purposes'):
if d.serial_no and not frappe.db.exists("Serial No", d.serial_no):