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 | |
Anand Doshi | 61cad50 | 2013-07-18 13:26:27 +0530 | [diff] [blame] | 5 | cur_frm.fields_dict.customer.get_query = erpnext.queries.customer; |
| 6 | cur_frm.fields_dict.supplier.get_query = erpnext.queries.supplier; |
Rushabh Mehta | 37982a6 | 2013-06-14 13:29:20 +0530 | [diff] [blame] | 7 | |
Anand Doshi | 8f9f8a4 | 2013-06-28 19:18:33 +0530 | [diff] [blame] | 8 | if(cur_frm.fields_dict.lead) { |
Anand Doshi | 61cad50 | 2013-07-18 13:26:27 +0530 | [diff] [blame] | 9 | cur_frm.fields_dict.lead.get_query = erpnext.queries.lead; |
Anand Doshi | 8f9f8a4 | 2013-06-28 19:18:33 +0530 | [diff] [blame] | 10 | cur_frm.add_fetch('lead', 'lead_name', 'lead_name'); |
| 11 | } |
| 12 | |
Rushabh Mehta | 37982a6 | 2013-06-14 13:29:20 +0530 | [diff] [blame] | 13 | if(doc.__islocal) { |
| 14 | var last_route = wn.route_history.slice(-2, -1)[0]; |
| 15 | if(last_route && last_route[0]==="Form") { |
| 16 | if(["Customer", "Quotation", "Sales Order", "Sales Invoice", "Delivery Note", |
| 17 | "Installation Note", "Opportunity", "Customer Issue", "Maintenance Visit", |
| 18 | "Maintenance Schedule"] |
| 19 | .indexOf(last_route[1])!==-1) { |
| 20 | var refdoc = wn.model.get_doc(last_route[1], last_route[2]); |
Anand Doshi | 8f9f8a4 | 2013-06-28 19:18:33 +0530 | [diff] [blame] | 21 | |
| 22 | if(refdoc.doctype == "Quotation" ? refdoc.quotation_to=="Customer" : true) { |
| 23 | cur_frm.set_value("customer", refdoc.customer || refdoc.name); |
| 24 | cur_frm.set_value("customer_name", refdoc.customer_name); |
| 25 | if(cur_frm.doc.doctype==="Address") |
| 26 | cur_frm.set_value("address_title", cur_frm.doc.customer_name); |
| 27 | } |
Rushabh Mehta | 37982a6 | 2013-06-14 13:29:20 +0530 | [diff] [blame] | 28 | } |
| 29 | if(["Supplier", "Supplier Quotation", "Purchase Order", "Purchase Invoice", "Purchase Receipt"] |
| 30 | .indexOf(last_route[1])!==-1) { |
Rushabh Mehta | 65d1292 | 2013-06-26 22:31:22 +0530 | [diff] [blame] | 31 | var refdoc = wn.model.get_doc(last_route[1], last_route[2]); |
Rushabh Mehta | 37982a6 | 2013-06-14 13:29:20 +0530 | [diff] [blame] | 32 | cur_frm.set_value("supplier", refdoc.supplier || refdoc.name); |
| 33 | cur_frm.set_value("supplier_name", refdoc.supplier_name); |
Rushabh Mehta | 65d1292 | 2013-06-26 22:31:22 +0530 | [diff] [blame] | 34 | if(cur_frm.doc.doctype==="Address") |
Anand Doshi | 8f9f8a4 | 2013-06-28 19:18:33 +0530 | [diff] [blame] | 35 | cur_frm.set_value("address_title", cur_frm.doc.supplier_name); |
| 36 | } |
| 37 | if(["Lead", "Quotation"] |
| 38 | .indexOf(last_route[1])!==-1) { |
| 39 | var refdoc = wn.model.get_doc(last_route[1], last_route[2]); |
| 40 | |
| 41 | if(refdoc.doctype == "Quotation" ? refdoc.quotation_to=="Lead" : true) { |
| 42 | cur_frm.set_value("lead", refdoc.lead || refdoc.name); |
| 43 | cur_frm.set_value("lead_name", refdoc.customer_name || refdoc.company_name || refdoc.lead_name); |
| 44 | if(cur_frm.doc.doctype==="Address") |
| 45 | cur_frm.set_value("address_title", cur_frm.doc.lead_name); |
| 46 | } |
Rushabh Mehta | 37982a6 | 2013-06-14 13:29:20 +0530 | [diff] [blame] | 47 | } |
| 48 | } |
| 49 | } |
| 50 | } |