blob: bda44cea7eaa4822beb06323c89faa0853e38637 [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) {
7 if(frm.doc.customer) {
8 method = "erpnext.selling.doctype.customer.customer.get_customer_details";
Rushabh Mehta24da7612014-01-29 15:26:04 +05309 var price_list_field = "selling_price_list";
Rushabh Mehta49dd7be2014-01-28 17:43:10 +053010 } else {
11 method = "erpnext.buying.doctype.supplier.supplier.get_supplier_details";
Rushabh Mehta24da7612014-01-29 15:26:04 +053012 var price_list_field = "buying_price_list";
Rushabh Mehta49dd7be2014-01-28 17:43:10 +053013 }
14 }
15 if(!args) {
16 if(frm.doc.customer) {
Rushabh Mehta24da7612014-01-29 15:26:04 +053017 args = {
18 customer: frm.doc.customer,
19 price_list: frm.doc.selling_price_list
20 };
Rushabh Mehta49dd7be2014-01-28 17:43:10 +053021 } else {
Rushabh Mehta24da7612014-01-29 15:26:04 +053022 args = {
23 supplier: frm.doc.supplier,
24 price_list: frm.doc.buying_price_list
25 };
Rushabh Mehta49dd7be2014-01-28 17:43:10 +053026 }
Rushabh Mehta24da7612014-01-29 15:26:04 +053027 args.currency = frm.doc.currency;
Rushabh Mehta49dd7be2014-01-28 17:43:10 +053028 }
Rushabh Mehtab09d9da2014-01-02 11:47:23 +053029 wn.call({
30 method: method,
31 args: args,
32 callback: function(r) {
33 if(r.message) {
Rushabh Mehta49dd7be2014-01-28 17:43:10 +053034 frm.updating_party_details = true;
Rushabh Mehtab09d9da2014-01-02 11:47:23 +053035 frm.set_value(r.message);
Rushabh Mehta49dd7be2014-01-28 17:43:10 +053036 frm.updating_party_details = false;
Rushabh Mehtab09d9da2014-01-02 11:47:23 +053037 }
38 }
39 });
40}
41
42erpnext.utils.get_address_display = function(frm, address_field) {
Rushabh Mehta49dd7be2014-01-28 17:43:10 +053043 if(frm.updating_party_details) return;
44 if(!address_field) {
45 if(frm.doc.customer) {
46 address_field = "customer_address";
47 } else {
48 address_field = "supplier_address";
49 }
50 }
Nabin Haitb87e9f22014-01-29 19:51:36 +053051 if(frm.doc[address_field]) {
52 wn.call({
53 method: "erpnext.utilities.doctype.address.address.get_address_display",
54 args: {address: frm.doc[address_field] },
55 callback: function(r) {
56 if(r.message)
57 frm.set_value("address_display", r.message)
58 }
59 })
60 }
Rushabh Mehtab09d9da2014-01-02 11:47:23 +053061}
62
63erpnext.utils.get_contact_details = function(frm) {
Rushabh Mehta49dd7be2014-01-28 17:43:10 +053064 if(frm.updating_party_details) return;
Nabin Haitb87e9f22014-01-29 19:51:36 +053065
66 if(frm.doc[address_field]) {
67 wn.call({
68 method: "erpnext.utilities.doctype.contact.contact.get_contact_details",
69 args: {contact: frm.doc.contact_person },
70 callback: function(r) {
71 if(r.message)
72 frm.set_value(r.message);
73 }
74 })
75 }
Rushabh Mehtab09d9da2014-01-02 11:47:23 +053076}