Merge pull request #4015 from anandpdoshi/use-add-fetch
Use add_fetch in Product Bundle, Maintenance Visit and Maintenance Schedule instead of redundant get_item_details method
This commit is contained in:
		
						commit
						0870b185de
					
				| @ -158,8 +158,13 @@ def get_retirement_date(date_of_birth=None): | ||||
| 	import datetime | ||||
| 	ret = {} | ||||
| 	if date_of_birth: | ||||
| 		try: | ||||
| 			dt = getdate(date_of_birth) + datetime.timedelta(21915) | ||||
| 			ret = {'date_of_retirement': dt.strftime('%Y-%m-%d')} | ||||
| 		except ValueError: | ||||
| 			# invalid date | ||||
| 			ret = {} | ||||
| 
 | ||||
| 	return ret | ||||
| 
 | ||||
| @frappe.whitelist() | ||||
|  | ||||
| @ -1,6 +1,8 @@ | ||||
| import frappe | ||||
| 
 | ||||
| def execute(): | ||||
| 	frappe.reload_doc("projects", "doctype", "activity_cost") | ||||
| 
 | ||||
| 	for cost in frappe.db.get_list("Activity Cost", filters = {"employee": ""}, | ||||
| 		fields = ("name", "activity_type", "costing_rate", "billing_rate")): | ||||
| 		activity_type = frappe.get_doc("Activity Type", cost.activity_type) | ||||
|  | ||||
| @ -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'); | ||||
| } | ||||
|  | ||||
| @ -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 | ||||
| 
 | ||||
|  | ||||
| @ -243,7 +243,7 @@ class StockReconciliation(StockController): | ||||
| @frappe.whitelist() | ||||
| def get_items(warehouse, posting_date, posting_time): | ||||
| 	items = frappe.get_list("Item", fields=["name"], filters= | ||||
| 		{"is_stock_item": 1, "has_serial_no": 0, "has_batch_no": 0}) | ||||
| 		{"is_stock_item": 1, "has_serial_no": 0, "has_batch_no": 0, "has_variants": 0}) | ||||
| 	for item in items: | ||||
| 		item.item_code = item.name | ||||
| 		item.warehouse = warehouse | ||||
|  | ||||
| @ -85,6 +85,11 @@ cur_frm.cscript.onload = function(doc, dt, dn) { | ||||
| 	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'); | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| 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}, | ||||
|  | ||||
| @ -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` | ||||
|  | ||||
| @ -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" } | ||||
| } | ||||
|  | ||||
| @ -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): | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user