blob: c01dee6b1f3b94e5609c265eaf22ab8910613265 [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
4wn.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 Mehtab09d9da2014-01-02 11:47:23 +053026 wn.call({
27 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
39erpnext.utils.get_address_display = function(frm, address_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";
44 } else {
45 address_field = "supplier_address";
46 }
47 }
Nabin Haitb87e9f22014-01-29 19:51:36 +053048 if(frm.doc[address_field]) {
49 wn.call({
50 method: "erpnext.utilities.doctype.address.address.get_address_display",
51 args: {address: frm.doc[address_field] },
52 callback: function(r) {
53 if(r.message)
54 frm.set_value("address_display", r.message)
55 }
56 })
57 }
Rushabh Mehtab09d9da2014-01-02 11:47:23 +053058}
59
60erpnext.utils.get_contact_details = function(frm) {
Rushabh Mehta49dd7be2014-01-28 17:43:10 +053061 if(frm.updating_party_details) return;
Nabin Haitb87e9f22014-01-29 19:51:36 +053062
63 if(frm.doc[address_field]) {
64 wn.call({
65 method: "erpnext.utilities.doctype.contact.contact.get_contact_details",
66 args: {contact: frm.doc.contact_person },
67 callback: function(r) {
68 if(r.message)
69 frm.set_value(r.message);
70 }
71 })
72 }
Rushabh Mehtab09d9da2014-01-02 11:47:23 +053073}