blob: 59992ebc04bdaab19637cd2a3ff4fac2a399a141 [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 }
Neil Trini Lasrado810bd352015-08-21 15:04:57 +053023 args.posting_date = frm.doc.transaction_date;
Rushabh Mehta49dd7be2014-01-28 17:43:10 +053024 }
Anand Doshi78eeacb2014-04-23 19:15:15 +053025 if(!args) return;
26
Rushabh Mehtacc008cc2014-02-03 16:14:56 +053027 args.currency = frm.doc.currency;
28 args.company = frm.doc.company;
Nabin Hait4d7c4fc2014-06-18 16:40:27 +053029 args.doctype = frm.doc.doctype;
Rushabh Mehta793ba6b2014-02-14 15:47:51 +053030 frappe.call({
Rushabh Mehtab09d9da2014-01-02 11:47:23 +053031 method: method,
32 args: args,
33 callback: function(r) {
34 if(r.message) {
Rushabh Mehta49dd7be2014-01-28 17:43:10 +053035 frm.updating_party_details = true;
Rushabh Mehtab09d9da2014-01-02 11:47:23 +053036 frm.set_value(r.message);
Rushabh Mehta49dd7be2014-01-28 17:43:10 +053037 frm.updating_party_details = false;
Nabin Haitc1367d92014-05-30 11:43:00 +053038 if(callback) callback();
Rushabh Mehtab09d9da2014-01-02 11:47:23 +053039 }
40 }
41 });
42}
43
Nabin Hait9d1f0772014-02-19 17:43:24 +053044erpnext.utils.get_address_display = function(frm, address_field, display_field) {
Rushabh Mehta49dd7be2014-01-28 17:43:10 +053045 if(frm.updating_party_details) return;
46 if(!address_field) {
47 if(frm.doc.customer) {
48 address_field = "customer_address";
Nabin Hait9d1f0772014-02-19 17:43:24 +053049 } else if(frm.doc.supplier) {
Rushabh Mehta49dd7be2014-01-28 17:43:10 +053050 address_field = "supplier_address";
Nabin Hait9d1f0772014-02-19 17:43:24 +053051 } else return;
Anand Doshi78eeacb2014-04-23 19:15:15 +053052 }
Nabin Hait9d1f0772014-02-19 17:43:24 +053053 if(!display_field) display_field = "address_display";
Nabin Haitb87e9f22014-01-29 19:51:36 +053054 if(frm.doc[address_field]) {
Rushabh Mehta793ba6b2014-02-14 15:47:51 +053055 frappe.call({
Nabin Haitb87e9f22014-01-29 19:51:36 +053056 method: "erpnext.utilities.doctype.address.address.get_address_display",
Nabin Hait9d1f0772014-02-19 17:43:24 +053057 args: {"address_dict": frm.doc[address_field] },
Nabin Haitb87e9f22014-01-29 19:51:36 +053058 callback: function(r) {
59 if(r.message)
Nabin Hait9d1f0772014-02-19 17:43:24 +053060 frm.set_value(display_field, r.message)
Nabin Haitb87e9f22014-01-29 19:51:36 +053061 }
62 })
63 }
Rushabh Mehtab09d9da2014-01-02 11:47:23 +053064}
65
66erpnext.utils.get_contact_details = function(frm) {
Rushabh Mehta49dd7be2014-01-28 17:43:10 +053067 if(frm.updating_party_details) return;
Anand Doshi78eeacb2014-04-23 19:15:15 +053068
Nabin Hait9d1f0772014-02-19 17:43:24 +053069 if(frm.doc["contact_person"]) {
Rushabh Mehta793ba6b2014-02-14 15:47:51 +053070 frappe.call({
Nabin Haitb87e9f22014-01-29 19:51:36 +053071 method: "erpnext.utilities.doctype.contact.contact.get_contact_details",
72 args: {contact: frm.doc.contact_person },
73 callback: function(r) {
74 if(r.message)
75 frm.set_value(r.message);
76 }
77 })
78 }
Anand Doshi78eeacb2014-04-23 19:15:15 +053079}