blob: de1ab3478ff218b503b5a118b04f45bf23170947 [file] [log] [blame]
Rushabh Mehta37982a62013-06-14 13:29:20 +05301cur_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
Anand Doshi8f9f8a42013-06-28 19:18:33 +05308 if(cur_frm.fields_dict.lead) {
9 cur_frm.fields_dict.lead.get_query = erpnext.utils.lead_query;
10 cur_frm.add_fetch('lead', 'lead_name', 'lead_name');
11 }
12
Rushabh Mehta37982a62013-06-14 13:29:20 +053013 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 Doshi8f9f8a42013-06-28 19:18:33 +053021
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 Mehta37982a62013-06-14 13:29:20 +053028 }
29 if(["Supplier", "Supplier Quotation", "Purchase Order", "Purchase Invoice", "Purchase Receipt"]
30 .indexOf(last_route[1])!==-1) {
Rushabh Mehta65d12922013-06-26 22:31:22 +053031 var refdoc = wn.model.get_doc(last_route[1], last_route[2]);
Rushabh Mehta37982a62013-06-14 13:29:20 +053032 cur_frm.set_value("supplier", refdoc.supplier || refdoc.name);
33 cur_frm.set_value("supplier_name", refdoc.supplier_name);
Rushabh Mehta65d12922013-06-26 22:31:22 +053034 if(cur_frm.doc.doctype==="Address")
Anand Doshi8f9f8a42013-06-28 19:18:33 +053035 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 Mehta37982a62013-06-14 13:29:20 +053047 }
48 }
49 }
50}