blob: 1a86b2b620e8bf58090848d16525530e30d79754 [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;
Neil Trini Lasrado09f9c962015-08-26 10:41:31 +053046
Rushabh Mehta49dd7be2014-01-28 17:43:10 +053047 if(!address_field) {
48 if(frm.doc.customer) {
49 address_field = "customer_address";
Nabin Hait9d1f0772014-02-19 17:43:24 +053050 } else if(frm.doc.supplier) {
Rushabh Mehta49dd7be2014-01-28 17:43:10 +053051 address_field = "supplier_address";
Nabin Hait9d1f0772014-02-19 17:43:24 +053052 } else return;
Anand Doshi78eeacb2014-04-23 19:15:15 +053053 }
Neil Trini Lasrado09f9c962015-08-26 10:41:31 +053054
Nabin Hait9d1f0772014-02-19 17:43:24 +053055 if(!display_field) display_field = "address_display";
Nabin Haitb87e9f22014-01-29 19:51:36 +053056 if(frm.doc[address_field]) {
Rushabh Mehta793ba6b2014-02-14 15:47:51 +053057 frappe.call({
Nabin Haitb87e9f22014-01-29 19:51:36 +053058 method: "erpnext.utilities.doctype.address.address.get_address_display",
Nabin Hait9d1f0772014-02-19 17:43:24 +053059 args: {"address_dict": frm.doc[address_field] },
Nabin Haitb87e9f22014-01-29 19:51:36 +053060 callback: function(r) {
Neil Trini Lasrado09f9c962015-08-26 10:41:31 +053061 if(r.message){
Nabin Hait9d1f0772014-02-19 17:43:24 +053062 frm.set_value(display_field, r.message)
Neil Trini Lasrado09f9c962015-08-26 10:41:31 +053063 }
64 frappe.call({
65 method: "erpnext.accounts.party.set_taxes",
66 args: {
67 "party": frm.doc.customer || frm.doc.supplier,
68 "party_type": (frm.doc.customer ? "Customer" : "Supplier"),
69 "posting_date": frm.doc.posting_date || frm.doc.transaction_date,
70 "company": frm.doc.company,
71 "billing_address": ((frm.doc.customer) ? (frm.doc.customer_address) : (frm.doc.supplier_address)),
72 "shipping_address": frm.doc.shipping_address_name
73 },
74 callback: function(r) {
75 if(r.message){
76 frm.set_value("taxes_and_charges", r.message)
77 }
78 }
79 });
Nabin Haitb87e9f22014-01-29 19:51:36 +053080 }
81 })
82 }
Rushabh Mehtab09d9da2014-01-02 11:47:23 +053083}
84
85erpnext.utils.get_contact_details = function(frm) {
Rushabh Mehta49dd7be2014-01-28 17:43:10 +053086 if(frm.updating_party_details) return;
Anand Doshi78eeacb2014-04-23 19:15:15 +053087
Nabin Hait9d1f0772014-02-19 17:43:24 +053088 if(frm.doc["contact_person"]) {
Rushabh Mehta793ba6b2014-02-14 15:47:51 +053089 frappe.call({
Nabin Haitb87e9f22014-01-29 19:51:36 +053090 method: "erpnext.utilities.doctype.contact.contact.get_contact_details",
91 args: {contact: frm.doc.contact_person },
92 callback: function(r) {
93 if(r.message)
94 frm.set_value(r.message);
95 }
96 })
97 }
Anand Doshi78eeacb2014-04-23 19:15:15 +053098}