2014-01-02 06:17:23 +00:00
|
|
|
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
|
|
|
|
// License: GNU General Public License v3. See license.txt
|
|
|
|
|
2014-02-14 10:17:51 +00:00
|
|
|
frappe.provide("erpnext.utils");
|
2014-01-28 12:13:10 +00:00
|
|
|
erpnext.utils.get_party_details = function(frm, method, args) {
|
|
|
|
if(!method) {
|
2014-02-03 10:44:56 +00:00
|
|
|
method = "erpnext.accounts.party.get_party_details";
|
2014-01-28 12:13:10 +00:00
|
|
|
}
|
|
|
|
if(!args) {
|
|
|
|
if(frm.doc.customer) {
|
2014-01-29 09:56:04 +00:00
|
|
|
args = {
|
2014-02-03 10:44:56 +00:00
|
|
|
party: frm.doc.customer,
|
|
|
|
party_type: "Customer",
|
2014-01-29 09:56:04 +00:00
|
|
|
price_list: frm.doc.selling_price_list
|
|
|
|
};
|
2014-01-28 12:13:10 +00:00
|
|
|
} else {
|
2014-01-29 09:56:04 +00:00
|
|
|
args = {
|
2014-02-03 10:44:56 +00:00
|
|
|
party: frm.doc.supplier,
|
|
|
|
party_type: "Supplier",
|
2014-01-29 09:56:04 +00:00
|
|
|
price_list: frm.doc.buying_price_list
|
|
|
|
};
|
2014-01-28 12:13:10 +00:00
|
|
|
}
|
|
|
|
}
|
2014-02-03 10:44:56 +00:00
|
|
|
args.currency = frm.doc.currency;
|
|
|
|
args.company = frm.doc.company;
|
2014-02-14 10:17:51 +00:00
|
|
|
frappe.call({
|
2014-01-02 06:17:23 +00:00
|
|
|
method: method,
|
|
|
|
args: args,
|
|
|
|
callback: function(r) {
|
|
|
|
if(r.message) {
|
2014-01-28 12:13:10 +00:00
|
|
|
frm.updating_party_details = true;
|
2014-01-02 06:17:23 +00:00
|
|
|
frm.set_value(r.message);
|
2014-01-28 12:13:10 +00:00
|
|
|
frm.updating_party_details = false;
|
2014-01-02 06:17:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-02-19 12:13:24 +00:00
|
|
|
erpnext.utils.get_address_display = function(frm, address_field, display_field) {
|
2014-01-28 12:13:10 +00:00
|
|
|
if(frm.updating_party_details) return;
|
|
|
|
if(!address_field) {
|
|
|
|
if(frm.doc.customer) {
|
|
|
|
address_field = "customer_address";
|
2014-02-19 12:13:24 +00:00
|
|
|
} else if(frm.doc.supplier) {
|
2014-01-28 12:13:10 +00:00
|
|
|
address_field = "supplier_address";
|
2014-02-19 12:13:24 +00:00
|
|
|
} else return;
|
2014-01-28 12:13:10 +00:00
|
|
|
}
|
2014-02-19 12:13:24 +00:00
|
|
|
if(!display_field) display_field = "address_display";
|
2014-01-29 14:21:36 +00:00
|
|
|
if(frm.doc[address_field]) {
|
2014-02-14 10:17:51 +00:00
|
|
|
frappe.call({
|
2014-01-29 14:21:36 +00:00
|
|
|
method: "erpnext.utilities.doctype.address.address.get_address_display",
|
2014-02-19 12:13:24 +00:00
|
|
|
args: {"address_dict": frm.doc[address_field] },
|
2014-01-29 14:21:36 +00:00
|
|
|
callback: function(r) {
|
|
|
|
if(r.message)
|
2014-02-19 12:13:24 +00:00
|
|
|
frm.set_value(display_field, r.message)
|
2014-01-29 14:21:36 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2014-01-02 06:17:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
erpnext.utils.get_contact_details = function(frm) {
|
2014-01-28 12:13:10 +00:00
|
|
|
if(frm.updating_party_details) return;
|
2014-01-29 14:21:36 +00:00
|
|
|
|
2014-02-19 12:13:24 +00:00
|
|
|
if(frm.doc["contact_person"]) {
|
2014-02-14 10:17:51 +00:00
|
|
|
frappe.call({
|
2014-01-29 14:21:36 +00:00
|
|
|
method: "erpnext.utilities.doctype.contact.contact.get_contact_details",
|
|
|
|
args: {contact: frm.doc.contact_person },
|
|
|
|
callback: function(r) {
|
|
|
|
if(r.message)
|
|
|
|
frm.set_value(r.message);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2014-01-02 06:17:23 +00:00
|
|
|
}
|