blob: 31abbb304f1f56c050a4ec247b655099ca421f18 [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) {
Anand Doshi78eeacb2014-04-23 19:15:15 +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 };
Anand Doshi78eeacb2014-04-23 19:15:15 +053016 } else if(frm.doc.supplier) {
17 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 }
Anand Doshi78eeacb2014-04-23 19:15:15 +053024 if(!args) return;
25
Rushabh Mehtacc008cc2014-02-03 16:14:56 +053026 args.currency = frm.doc.currency;
27 args.company = frm.doc.company;
Rushabh Mehta793ba6b2014-02-14 15:47:51 +053028 frappe.call({
Rushabh Mehtab09d9da2014-01-02 11:47:23 +053029 method: method,
30 args: args,
31 callback: function(r) {
32 if(r.message) {
Rushabh Mehta49dd7be2014-01-28 17:43:10 +053033 frm.updating_party_details = true;
Rushabh Mehtab09d9da2014-01-02 11:47:23 +053034 frm.set_value(r.message);
Rushabh Mehta49dd7be2014-01-28 17:43:10 +053035 frm.updating_party_details = false;
Rushabh Mehtab09d9da2014-01-02 11:47:23 +053036 }
37 }
38 });
39}
40
Nabin Hait9d1f0772014-02-19 17:43:24 +053041erpnext.utils.get_address_display = function(frm, address_field, display_field) {
Rushabh Mehta49dd7be2014-01-28 17:43:10 +053042 if(frm.updating_party_details) return;
43 if(!address_field) {
44 if(frm.doc.customer) {
45 address_field = "customer_address";
Nabin Hait9d1f0772014-02-19 17:43:24 +053046 } else if(frm.doc.supplier) {
Rushabh Mehta49dd7be2014-01-28 17:43:10 +053047 address_field = "supplier_address";
Nabin Hait9d1f0772014-02-19 17:43:24 +053048 } else return;
Anand Doshi78eeacb2014-04-23 19:15:15 +053049 }
Nabin Hait9d1f0772014-02-19 17:43:24 +053050 if(!display_field) display_field = "address_display";
Nabin Haitb87e9f22014-01-29 19:51:36 +053051 if(frm.doc[address_field]) {
Rushabh Mehta793ba6b2014-02-14 15:47:51 +053052 frappe.call({
Nabin Haitb87e9f22014-01-29 19:51:36 +053053 method: "erpnext.utilities.doctype.address.address.get_address_display",
Nabin Hait9d1f0772014-02-19 17:43:24 +053054 args: {"address_dict": frm.doc[address_field] },
Nabin Haitb87e9f22014-01-29 19:51:36 +053055 callback: function(r) {
56 if(r.message)
Nabin Hait9d1f0772014-02-19 17:43:24 +053057 frm.set_value(display_field, r.message)
Nabin Haitb87e9f22014-01-29 19:51:36 +053058 }
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;
Anand Doshi78eeacb2014-04-23 19:15:15 +053065
Nabin Hait9d1f0772014-02-19 17:43:24 +053066 if(frm.doc["contact_person"]) {
Rushabh Mehta793ba6b2014-02-14 15:47:51 +053067 frappe.call({
Nabin Haitb87e9f22014-01-29 19:51:36 +053068 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 }
Anand Doshi78eeacb2014-04-23 19:15:15 +053076}