2015-03-03 09:25:30 +00:00
|
|
|
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
2013-08-05 09:29:54 +00:00
|
|
|
// License: GNU General Public License v3. See license.txt
|
|
|
|
|
2014-05-02 06:12:24 +00:00
|
|
|
cur_frm.cscript.onload = function(doc, cdt, cdn) {
|
2013-06-14 07:59:20 +00:00
|
|
|
cur_frm.add_fetch('customer', 'customer_name', 'customer_name');
|
|
|
|
cur_frm.add_fetch('supplier', 'supplier_name', 'supplier_name');
|
|
|
|
|
2013-07-18 07:56:27 +00:00
|
|
|
cur_frm.fields_dict.customer.get_query = erpnext.queries.customer;
|
|
|
|
cur_frm.fields_dict.supplier.get_query = erpnext.queries.supplier;
|
2014-05-02 06:12:24 +00:00
|
|
|
|
2013-06-28 13:48:33 +00:00
|
|
|
if(cur_frm.fields_dict.lead) {
|
2013-07-18 07:56:27 +00:00
|
|
|
cur_frm.fields_dict.lead.get_query = erpnext.queries.lead;
|
2013-06-28 13:48:33 +00:00
|
|
|
cur_frm.add_fetch('lead', 'lead_name', 'lead_name');
|
|
|
|
}
|
2014-05-02 06:12:24 +00:00
|
|
|
|
2013-06-14 07:59:20 +00:00
|
|
|
if(doc.__islocal) {
|
2014-02-14 10:17:51 +00:00
|
|
|
var last_route = frappe.route_history.slice(-2, -1)[0];
|
2013-06-14 07:59:20 +00:00
|
|
|
if(last_route && last_route[0]==="Form") {
|
2013-08-14 11:52:14 +00:00
|
|
|
var doctype = last_route[1],
|
|
|
|
docname = last_route.slice(2).join("/");
|
2014-05-02 06:12:24 +00:00
|
|
|
|
2013-06-14 07:59:20 +00:00
|
|
|
if(["Customer", "Quotation", "Sales Order", "Sales Invoice", "Delivery Note",
|
2015-02-17 05:15:50 +00:00
|
|
|
"Installation Note", "Opportunity", "Warranty Claim", "Maintenance Visit",
|
2013-06-14 07:59:20 +00:00
|
|
|
"Maintenance Schedule"]
|
2013-08-14 11:52:14 +00:00
|
|
|
.indexOf(doctype)!==-1) {
|
2014-03-27 08:47:33 +00:00
|
|
|
var refdoc = frappe.get_doc(doctype, docname);
|
2014-05-02 06:12:24 +00:00
|
|
|
if((refdoc.doctype == "Quotation" && refdoc.quotation_to=="Customer") ||
|
|
|
|
(refdoc.doctype == "Opportunity" && refdoc.enquiry_from=="Customer") ||
|
|
|
|
!in_list(["Opportunity", "Quotation"], doctype)) {
|
|
|
|
cur_frm.set_value("customer", refdoc.customer || refdoc.name);
|
|
|
|
cur_frm.set_value("customer_name", refdoc.customer_name);
|
|
|
|
if(cur_frm.doc.doctype==="Address")
|
|
|
|
cur_frm.set_value("address_title", cur_frm.doc.customer_name);
|
2013-06-28 13:48:33 +00:00
|
|
|
}
|
2013-06-14 07:59:20 +00:00
|
|
|
}
|
|
|
|
if(["Supplier", "Supplier Quotation", "Purchase Order", "Purchase Invoice", "Purchase Receipt"]
|
2013-08-14 11:52:14 +00:00
|
|
|
.indexOf(doctype)!==-1) {
|
2014-03-27 08:47:33 +00:00
|
|
|
var refdoc = frappe.get_doc(doctype, docname);
|
2013-06-14 07:59:20 +00:00
|
|
|
cur_frm.set_value("supplier", refdoc.supplier || refdoc.name);
|
|
|
|
cur_frm.set_value("supplier_name", refdoc.supplier_name);
|
2013-06-26 17:01:22 +00:00
|
|
|
if(cur_frm.doc.doctype==="Address")
|
2013-06-28 13:48:33 +00:00
|
|
|
cur_frm.set_value("address_title", cur_frm.doc.supplier_name);
|
|
|
|
}
|
2014-05-02 06:12:24 +00:00
|
|
|
if(["Lead", "Opportunity", "Quotation"]
|
2013-08-14 11:52:14 +00:00
|
|
|
.indexOf(doctype)!==-1) {
|
2014-03-27 08:47:33 +00:00
|
|
|
var refdoc = frappe.get_doc(doctype, docname);
|
2014-05-02 06:12:24 +00:00
|
|
|
|
|
|
|
if((refdoc.doctype == "Quotation" && refdoc.quotation_to=="Lead") ||
|
|
|
|
(refdoc.doctype == "Opportunity" && refdoc.enquiry_from=="Lead") || (doctype=="Lead")) {
|
|
|
|
cur_frm.set_value("lead", refdoc.lead || refdoc.name);
|
|
|
|
cur_frm.set_value("lead_name", refdoc.customer_name || refdoc.company_name || refdoc.lead_name);
|
|
|
|
if(cur_frm.doc.doctype==="Address")
|
|
|
|
cur_frm.set_value("address_title", cur_frm.doc.lead_name);
|
2013-06-28 13:48:33 +00:00
|
|
|
}
|
2013-06-14 07:59:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|