blob: 7c938d7ae1160c19aff0977b3217dea783144d52 [file] [log] [blame]
Rushabh Mehtaad45e312013-11-20 12:59:58 +05301// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
Rushabh Mehtae67d1fb2013-08-05 14:59:54 +05302// License: GNU General Public License v3. See license.txt
3
Rushabh Mehta37982a62013-06-14 13:29:20 +05304cur_frm.cscript.onload = function(doc, cdt, cdn) {
5 cur_frm.add_fetch('customer', 'customer_name', 'customer_name');
6 cur_frm.add_fetch('supplier', 'supplier_name', 'supplier_name');
7
Anand Doshi61cad502013-07-18 13:26:27 +05308 cur_frm.fields_dict.customer.get_query = erpnext.queries.customer;
9 cur_frm.fields_dict.supplier.get_query = erpnext.queries.supplier;
Rushabh Mehta37982a62013-06-14 13:29:20 +053010
Anand Doshi8f9f8a42013-06-28 19:18:33 +053011 if(cur_frm.fields_dict.lead) {
Anand Doshi61cad502013-07-18 13:26:27 +053012 cur_frm.fields_dict.lead.get_query = erpnext.queries.lead;
Anand Doshi8f9f8a42013-06-28 19:18:33 +053013 cur_frm.add_fetch('lead', 'lead_name', 'lead_name');
14 }
15
Rushabh Mehta37982a62013-06-14 13:29:20 +053016 if(doc.__islocal) {
17 var last_route = wn.route_history.slice(-2, -1)[0];
18 if(last_route && last_route[0]==="Form") {
Anand Doshi3d1ecf52013-08-14 17:22:14 +053019 var doctype = last_route[1],
20 docname = last_route.slice(2).join("/");
21
Rushabh Mehta37982a62013-06-14 13:29:20 +053022 if(["Customer", "Quotation", "Sales Order", "Sales Invoice", "Delivery Note",
23 "Installation Note", "Opportunity", "Customer Issue", "Maintenance Visit",
24 "Maintenance Schedule"]
Anand Doshi3d1ecf52013-08-14 17:22:14 +053025 .indexOf(doctype)!==-1) {
26 var refdoc = wn.model.get_doc(doctype, docname);
Anand Doshi8f9f8a42013-06-28 19:18:33 +053027
28 if(refdoc.doctype == "Quotation" ? refdoc.quotation_to=="Customer" : true) {
29 cur_frm.set_value("customer", refdoc.customer || refdoc.name);
30 cur_frm.set_value("customer_name", refdoc.customer_name);
31 if(cur_frm.doc.doctype==="Address")
32 cur_frm.set_value("address_title", cur_frm.doc.customer_name);
33 }
Rushabh Mehta37982a62013-06-14 13:29:20 +053034 }
35 if(["Supplier", "Supplier Quotation", "Purchase Order", "Purchase Invoice", "Purchase Receipt"]
Anand Doshi3d1ecf52013-08-14 17:22:14 +053036 .indexOf(doctype)!==-1) {
37 var refdoc = wn.model.get_doc(doctype, docname);
Rushabh Mehta37982a62013-06-14 13:29:20 +053038 cur_frm.set_value("supplier", refdoc.supplier || refdoc.name);
39 cur_frm.set_value("supplier_name", refdoc.supplier_name);
Rushabh Mehta65d12922013-06-26 22:31:22 +053040 if(cur_frm.doc.doctype==="Address")
Anand Doshi8f9f8a42013-06-28 19:18:33 +053041 cur_frm.set_value("address_title", cur_frm.doc.supplier_name);
42 }
43 if(["Lead", "Quotation"]
Anand Doshi3d1ecf52013-08-14 17:22:14 +053044 .indexOf(doctype)!==-1) {
45 var refdoc = wn.model.get_doc(doctype, docname);
Anand Doshi8f9f8a42013-06-28 19:18:33 +053046
47 if(refdoc.doctype == "Quotation" ? refdoc.quotation_to=="Lead" : true) {
48 cur_frm.set_value("lead", refdoc.lead || refdoc.name);
49 cur_frm.set_value("lead_name", refdoc.customer_name || refdoc.company_name || refdoc.lead_name);
50 if(cur_frm.doc.doctype==="Address")
51 cur_frm.set_value("address_title", cur_frm.doc.lead_name);
52 }
Rushabh Mehta37982a62013-06-14 13:29:20 +053053 }
54 }
55 }
56}