blob: 919225f9a9935c944d2c06c59f899000723a61f1 [file] [log] [blame]
Anand Doshi885e0742015-03-03 14:55:30 +05301// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
Rushabh Mehtab09d9da2014-01-02 11:47:23 +05302// License: GNU General Public License v3. See license.txt
3
Rushabh Mehta793ba6b2014-02-14 15:47:51 +05304frappe.provide("erpnext.utils");
Nabin Haita3dd72a2014-05-28 12:49:20 +05305erpnext.utils.get_party_details = function(frm, method, args, callback) {
Rushabh Mehta49dd7be2014-01-28 17:43:10 +05306 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;
Nabin Hait4d7c4fc2014-06-18 16:40:27 +053028 args.doctype = frm.doc.doctype;
Rushabh Mehta793ba6b2014-02-14 15:47:51 +053029 frappe.call({
Rushabh Mehtab09d9da2014-01-02 11:47:23 +053030 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;
Nabin Haitc1367d92014-05-30 11:43:00 +053037 if(callback) callback();
Rushabh Mehtab09d9da2014-01-02 11:47:23 +053038 }
39 }
40 });
41}
42
Nabin Hait9d1f0772014-02-19 17:43:24 +053043erpnext.utils.get_address_display = function(frm, address_field, display_field) {
Rushabh Mehta49dd7be2014-01-28 17:43:10 +053044 if(frm.updating_party_details) return;
45 if(!address_field) {
46 if(frm.doc.customer) {
47 address_field = "customer_address";
Nabin Hait9d1f0772014-02-19 17:43:24 +053048 } else if(frm.doc.supplier) {
Rushabh Mehta49dd7be2014-01-28 17:43:10 +053049 address_field = "supplier_address";
Nabin Hait9d1f0772014-02-19 17:43:24 +053050 } else return;
Anand Doshi78eeacb2014-04-23 19:15:15 +053051 }
Nabin Hait9d1f0772014-02-19 17:43:24 +053052 if(!display_field) display_field = "address_display";
Nabin Haitb87e9f22014-01-29 19:51:36 +053053 if(frm.doc[address_field]) {
Rushabh Mehta793ba6b2014-02-14 15:47:51 +053054 frappe.call({
Nabin Haitb87e9f22014-01-29 19:51:36 +053055 method: "erpnext.utilities.doctype.address.address.get_address_display",
Nabin Hait9d1f0772014-02-19 17:43:24 +053056 args: {"address_dict": frm.doc[address_field] },
Nabin Haitb87e9f22014-01-29 19:51:36 +053057 callback: function(r) {
58 if(r.message)
Nabin Hait9d1f0772014-02-19 17:43:24 +053059 frm.set_value(display_field, r.message)
Nabin Haitb87e9f22014-01-29 19:51:36 +053060 }
61 })
62 }
Rushabh Mehtab09d9da2014-01-02 11:47:23 +053063}
64
65erpnext.utils.get_contact_details = function(frm) {
Rushabh Mehta49dd7be2014-01-28 17:43:10 +053066 if(frm.updating_party_details) return;
Anand Doshi78eeacb2014-04-23 19:15:15 +053067
Nabin Hait9d1f0772014-02-19 17:43:24 +053068 if(frm.doc["contact_person"]) {
Rushabh Mehta793ba6b2014-02-14 15:47:51 +053069 frappe.call({
Nabin Haitb87e9f22014-01-29 19:51:36 +053070 method: "erpnext.utilities.doctype.contact.contact.get_contact_details",
71 args: {contact: frm.doc.contact_person },
72 callback: function(r) {
73 if(r.message)
74 frm.set_value(r.message);
75 }
76 })
77 }
Anand Doshi78eeacb2014-04-23 19:15:15 +053078}