blob: 82dad0e83e84baf5c584b2c7afe138ac6df8432b [file] [log] [blame]
Rushabh Mehtae67d1fb2013-08-05 14:59:54 +05301// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
2// 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") {
19 if(["Customer", "Quotation", "Sales Order", "Sales Invoice", "Delivery Note",
20 "Installation Note", "Opportunity", "Customer Issue", "Maintenance Visit",
21 "Maintenance Schedule"]
22 .indexOf(last_route[1])!==-1) {
23 var refdoc = wn.model.get_doc(last_route[1], last_route[2]);
Anand Doshi8f9f8a42013-06-28 19:18:33 +053024
25 if(refdoc.doctype == "Quotation" ? refdoc.quotation_to=="Customer" : true) {
26 cur_frm.set_value("customer", refdoc.customer || refdoc.name);
27 cur_frm.set_value("customer_name", refdoc.customer_name);
28 if(cur_frm.doc.doctype==="Address")
29 cur_frm.set_value("address_title", cur_frm.doc.customer_name);
30 }
Rushabh Mehta37982a62013-06-14 13:29:20 +053031 }
32 if(["Supplier", "Supplier Quotation", "Purchase Order", "Purchase Invoice", "Purchase Receipt"]
33 .indexOf(last_route[1])!==-1) {
Rushabh Mehta65d12922013-06-26 22:31:22 +053034 var refdoc = wn.model.get_doc(last_route[1], last_route[2]);
Rushabh Mehta37982a62013-06-14 13:29:20 +053035 cur_frm.set_value("supplier", refdoc.supplier || refdoc.name);
36 cur_frm.set_value("supplier_name", refdoc.supplier_name);
Rushabh Mehta65d12922013-06-26 22:31:22 +053037 if(cur_frm.doc.doctype==="Address")
Anand Doshi8f9f8a42013-06-28 19:18:33 +053038 cur_frm.set_value("address_title", cur_frm.doc.supplier_name);
39 }
40 if(["Lead", "Quotation"]
41 .indexOf(last_route[1])!==-1) {
42 var refdoc = wn.model.get_doc(last_route[1], last_route[2]);
43
44 if(refdoc.doctype == "Quotation" ? refdoc.quotation_to=="Lead" : true) {
45 cur_frm.set_value("lead", refdoc.lead || refdoc.name);
46 cur_frm.set_value("lead_name", refdoc.customer_name || refdoc.company_name || refdoc.lead_name);
47 if(cur_frm.doc.doctype==="Address")
48 cur_frm.set_value("address_title", cur_frm.doc.lead_name);
49 }
Rushabh Mehta37982a62013-06-14 13:29:20 +053050 }
51 }
52 }
53}