blob: 9063b0074f88bb2f0cec660d1ea3f7bad6540af6 [file] [log] [blame]
Rushabh Mehtab09d9da2014-01-02 11:47:23 +05301// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
2// License: GNU General Public License v3. See license.txt
3
Rushabh Mehta793ba6b2014-02-14 15:47:51 +05304frappe.provide("erpnext.utils");
Rushabh Mehta49dd7be2014-01-28 17:43:10 +05305erpnext.utils.get_party_details = function(frm, method, args) {
6 if(!method) {
Rushabh Mehtacc008cc2014-02-03 16:14:56 +05307 method = "erpnext.accounts.party.get_party_details";
Rushabh Mehta49dd7be2014-01-28 17:43:10 +05308 }
9 if(!args) {
10 if(frm.doc.customer) {
Rushabh Mehta24da7612014-01-29 15:26:04 +053011 args = {
Rushabh Mehtacc008cc2014-02-03 16:14:56 +053012 party: frm.doc.customer,
13 party_type: "Customer",
Rushabh Mehta24da7612014-01-29 15:26:04 +053014 price_list: frm.doc.selling_price_list
15 };
Rushabh Mehta49dd7be2014-01-28 17:43:10 +053016 } else {
Rushabh Mehta24da7612014-01-29 15:26:04 +053017 args = {
Rushabh Mehtacc008cc2014-02-03 16:14:56 +053018 party: frm.doc.supplier,
19 party_type: "Supplier",
Rushabh Mehta24da7612014-01-29 15:26:04 +053020 price_list: frm.doc.buying_price_list
21 };
Rushabh Mehta49dd7be2014-01-28 17:43:10 +053022 }
23 }
Rushabh Mehtacc008cc2014-02-03 16:14:56 +053024 args.currency = frm.doc.currency;
25 args.company = frm.doc.company;
Rushabh Mehta793ba6b2014-02-14 15:47:51 +053026 frappe.call({
Rushabh Mehtab09d9da2014-01-02 11:47:23 +053027 method: method,
28 args: args,
29 callback: function(r) {
30 if(r.message) {
Rushabh Mehta49dd7be2014-01-28 17:43:10 +053031 frm.updating_party_details = true;
Rushabh Mehtab09d9da2014-01-02 11:47:23 +053032 frm.set_value(r.message);
Rushabh Mehta49dd7be2014-01-28 17:43:10 +053033 frm.updating_party_details = false;
Rushabh Mehtab09d9da2014-01-02 11:47:23 +053034 }
35 }
36 });
37}
38
Nabin Hait9d1f0772014-02-19 17:43:24 +053039erpnext.utils.get_address_display = function(frm, address_field, display_field) {
Rushabh Mehta49dd7be2014-01-28 17:43:10 +053040 if(frm.updating_party_details) return;
41 if(!address_field) {
42 if(frm.doc.customer) {
43 address_field = "customer_address";
Nabin Hait9d1f0772014-02-19 17:43:24 +053044 } else if(frm.doc.supplier) {
Rushabh Mehta49dd7be2014-01-28 17:43:10 +053045 address_field = "supplier_address";
Nabin Hait9d1f0772014-02-19 17:43:24 +053046 } else return;
Rushabh Mehta49dd7be2014-01-28 17:43:10 +053047 }
Nabin Hait9d1f0772014-02-19 17:43:24 +053048 if(!display_field) display_field = "address_display";
Nabin Haitb87e9f22014-01-29 19:51:36 +053049 if(frm.doc[address_field]) {
Rushabh Mehta793ba6b2014-02-14 15:47:51 +053050 frappe.call({
Nabin Haitb87e9f22014-01-29 19:51:36 +053051 method: "erpnext.utilities.doctype.address.address.get_address_display",
Nabin Hait9d1f0772014-02-19 17:43:24 +053052 args: {"address_dict": frm.doc[address_field] },
Nabin Haitb87e9f22014-01-29 19:51:36 +053053 callback: function(r) {
54 if(r.message)
Nabin Hait9d1f0772014-02-19 17:43:24 +053055 frm.set_value(display_field, r.message)
Nabin Haitb87e9f22014-01-29 19:51:36 +053056 }
57 })
58 }
Rushabh Mehtab09d9da2014-01-02 11:47:23 +053059}
60
61erpnext.utils.get_contact_details = function(frm) {
Rushabh Mehta49dd7be2014-01-28 17:43:10 +053062 if(frm.updating_party_details) return;
Nabin Haitb87e9f22014-01-29 19:51:36 +053063
Nabin Hait9d1f0772014-02-19 17:43:24 +053064 if(frm.doc["contact_person"]) {
Rushabh Mehta793ba6b2014-02-14 15:47:51 +053065 frappe.call({
Nabin Haitb87e9f22014-01-29 19:51:36 +053066 method: "erpnext.utilities.doctype.contact.contact.get_contact_details",
67 args: {contact: frm.doc.contact_person },
68 callback: function(r) {
69 if(r.message)
70 frm.set_value(r.message);
71 }
72 })
73 }
Rushabh Mehtab09d9da2014-01-02 11:47:23 +053074}