Rushabh Mehta | 37982a6 | 2013-06-14 13:29:20 +0530 | [diff] [blame] | 1 | cur_frm.cscript.onload = function(doc, cdt, cdn) { |
| 2 | cur_frm.add_fetch('customer', 'customer_name', 'customer_name'); |
| 3 | cur_frm.add_fetch('supplier', 'supplier_name', 'supplier_name'); |
| 4 | |
| 5 | cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query; |
| 6 | cur_frm.fields_dict.supplier.get_query = erpnext.utils.supplier_query; |
| 7 | |
| 8 | if(doc.__islocal) { |
| 9 | var last_route = wn.route_history.slice(-2, -1)[0]; |
| 10 | if(last_route && last_route[0]==="Form") { |
| 11 | if(["Customer", "Quotation", "Sales Order", "Sales Invoice", "Delivery Note", |
| 12 | "Installation Note", "Opportunity", "Customer Issue", "Maintenance Visit", |
| 13 | "Maintenance Schedule"] |
| 14 | .indexOf(last_route[1])!==-1) { |
| 15 | var refdoc = wn.model.get_doc(last_route[1], last_route[2]); |
| 16 | cur_frm.set_value("customer", refdoc.customer || refdoc.name); |
| 17 | cur_frm.set_value("customer_name", refdoc.customer_name); |
| 18 | } |
| 19 | if(["Supplier", "Supplier Quotation", "Purchase Order", "Purchase Invoice", "Purchase Receipt"] |
| 20 | .indexOf(last_route[1])!==-1) { |
| 21 | var customer = wn.model.get_doc(last_route[1], last_route[2]); |
| 22 | cur_frm.set_value("supplier", refdoc.supplier || refdoc.name); |
| 23 | cur_frm.set_value("supplier_name", refdoc.supplier_name); |
| 24 | } |
| 25 | } |
| 26 | } |
| 27 | } |