blob: 9173b717037224b35233834ca5782083cdb8cf71 [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 }
Anand Doshi9a4d1652015-10-12 16:23:51 +053023
24 if (args) {
25 args.posting_date = frm.doc.transaction_date;
26 }
Rushabh Mehta49dd7be2014-01-28 17:43:10 +053027 }
Anand Doshi78eeacb2014-04-23 19:15:15 +053028 if(!args) return;
29
Rushabh Mehtacc008cc2014-02-03 16:14:56 +053030 args.currency = frm.doc.currency;
31 args.company = frm.doc.company;
Nabin Hait4d7c4fc2014-06-18 16:40:27 +053032 args.doctype = frm.doc.doctype;
Rushabh Mehta793ba6b2014-02-14 15:47:51 +053033 frappe.call({
Rushabh Mehtab09d9da2014-01-02 11:47:23 +053034 method: method,
35 args: args,
36 callback: function(r) {
37 if(r.message) {
Rushabh Mehta49dd7be2014-01-28 17:43:10 +053038 frm.updating_party_details = true;
Rushabh Mehtab09d9da2014-01-02 11:47:23 +053039 frm.set_value(r.message);
Rushabh Mehta49dd7be2014-01-28 17:43:10 +053040 frm.updating_party_details = false;
Nabin Haitc1367d92014-05-30 11:43:00 +053041 if(callback) callback();
Rushabh Mehtab09d9da2014-01-02 11:47:23 +053042 }
43 }
44 });
45}
46
Nabin Hait9d1f0772014-02-19 17:43:24 +053047erpnext.utils.get_address_display = function(frm, address_field, display_field) {
Rushabh Mehta49dd7be2014-01-28 17:43:10 +053048 if(frm.updating_party_details) return;
Neil Trini Lasrado09f9c962015-08-26 10:41:31 +053049
Rushabh Mehta49dd7be2014-01-28 17:43:10 +053050 if(!address_field) {
51 if(frm.doc.customer) {
52 address_field = "customer_address";
Nabin Hait9d1f0772014-02-19 17:43:24 +053053 } else if(frm.doc.supplier) {
Rushabh Mehta49dd7be2014-01-28 17:43:10 +053054 address_field = "supplier_address";
Nabin Hait9d1f0772014-02-19 17:43:24 +053055 } else return;
Anand Doshi78eeacb2014-04-23 19:15:15 +053056 }
Neil Trini Lasrado09f9c962015-08-26 10:41:31 +053057
Nabin Hait9d1f0772014-02-19 17:43:24 +053058 if(!display_field) display_field = "address_display";
Nabin Haitb87e9f22014-01-29 19:51:36 +053059 if(frm.doc[address_field]) {
Rushabh Mehta793ba6b2014-02-14 15:47:51 +053060 frappe.call({
Nabin Haitb87e9f22014-01-29 19:51:36 +053061 method: "erpnext.utilities.doctype.address.address.get_address_display",
Nabin Hait9d1f0772014-02-19 17:43:24 +053062 args: {"address_dict": frm.doc[address_field] },
Nabin Haitb87e9f22014-01-29 19:51:36 +053063 callback: function(r) {
Neil Trini Lasrado09f9c962015-08-26 10:41:31 +053064 if(r.message){
Nabin Hait9d1f0772014-02-19 17:43:24 +053065 frm.set_value(display_field, r.message)
Neil Trini Lasrado09f9c962015-08-26 10:41:31 +053066 }
67 frappe.call({
68 method: "erpnext.accounts.party.set_taxes",
69 args: {
70 "party": frm.doc.customer || frm.doc.supplier,
71 "party_type": (frm.doc.customer ? "Customer" : "Supplier"),
72 "posting_date": frm.doc.posting_date || frm.doc.transaction_date,
73 "company": frm.doc.company,
74 "billing_address": ((frm.doc.customer) ? (frm.doc.customer_address) : (frm.doc.supplier_address)),
75 "shipping_address": frm.doc.shipping_address_name
76 },
77 callback: function(r) {
78 if(r.message){
79 frm.set_value("taxes_and_charges", r.message)
80 }
81 }
82 });
Nabin Haitb87e9f22014-01-29 19:51:36 +053083 }
84 })
85 }
Rushabh Mehtab09d9da2014-01-02 11:47:23 +053086}
87
88erpnext.utils.get_contact_details = function(frm) {
Rushabh Mehta49dd7be2014-01-28 17:43:10 +053089 if(frm.updating_party_details) return;
Anand Doshi78eeacb2014-04-23 19:15:15 +053090
Nabin Hait9d1f0772014-02-19 17:43:24 +053091 if(frm.doc["contact_person"]) {
Rushabh Mehta793ba6b2014-02-14 15:47:51 +053092 frappe.call({
Nabin Haitb87e9f22014-01-29 19:51:36 +053093 method: "erpnext.utilities.doctype.contact.contact.get_contact_details",
94 args: {contact: frm.doc.contact_person },
95 callback: function(r) {
96 if(r.message)
97 frm.set_value(r.message);
98 }
99 })
100 }
Anand Doshi78eeacb2014-04-23 19:15:15 +0530101}