Rushabh Mehta | b09d9da | 2014-01-02 11:47:23 +0530 | [diff] [blame] | 1 | // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors |
| 2 | // License: GNU General Public License v3. See license.txt |
| 3 | |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 4 | frappe.provide("erpnext.utils"); |
Rushabh Mehta | 49dd7be | 2014-01-28 17:43:10 +0530 | [diff] [blame] | 5 | erpnext.utils.get_party_details = function(frm, method, args) { |
| 6 | if(!method) { |
Rushabh Mehta | cc008cc | 2014-02-03 16:14:56 +0530 | [diff] [blame] | 7 | method = "erpnext.accounts.party.get_party_details"; |
Rushabh Mehta | 49dd7be | 2014-01-28 17:43:10 +0530 | [diff] [blame] | 8 | } |
| 9 | if(!args) { |
| 10 | if(frm.doc.customer) { |
Rushabh Mehta | 24da761 | 2014-01-29 15:26:04 +0530 | [diff] [blame] | 11 | args = { |
Rushabh Mehta | cc008cc | 2014-02-03 16:14:56 +0530 | [diff] [blame] | 12 | party: frm.doc.customer, |
| 13 | party_type: "Customer", |
Rushabh Mehta | 24da761 | 2014-01-29 15:26:04 +0530 | [diff] [blame] | 14 | price_list: frm.doc.selling_price_list |
| 15 | }; |
Rushabh Mehta | 49dd7be | 2014-01-28 17:43:10 +0530 | [diff] [blame] | 16 | } else { |
Rushabh Mehta | 24da761 | 2014-01-29 15:26:04 +0530 | [diff] [blame] | 17 | args = { |
Rushabh Mehta | cc008cc | 2014-02-03 16:14:56 +0530 | [diff] [blame] | 18 | party: frm.doc.supplier, |
| 19 | party_type: "Supplier", |
Rushabh Mehta | 24da761 | 2014-01-29 15:26:04 +0530 | [diff] [blame] | 20 | price_list: frm.doc.buying_price_list |
| 21 | }; |
Rushabh Mehta | 49dd7be | 2014-01-28 17:43:10 +0530 | [diff] [blame] | 22 | } |
| 23 | } |
Rushabh Mehta | cc008cc | 2014-02-03 16:14:56 +0530 | [diff] [blame] | 24 | args.currency = frm.doc.currency; |
| 25 | args.company = frm.doc.company; |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 26 | frappe.call({ |
Rushabh Mehta | b09d9da | 2014-01-02 11:47:23 +0530 | [diff] [blame] | 27 | method: method, |
| 28 | args: args, |
| 29 | callback: function(r) { |
| 30 | if(r.message) { |
Rushabh Mehta | 49dd7be | 2014-01-28 17:43:10 +0530 | [diff] [blame] | 31 | frm.updating_party_details = true; |
Rushabh Mehta | b09d9da | 2014-01-02 11:47:23 +0530 | [diff] [blame] | 32 | frm.set_value(r.message); |
Rushabh Mehta | 49dd7be | 2014-01-28 17:43:10 +0530 | [diff] [blame] | 33 | frm.updating_party_details = false; |
Rushabh Mehta | b09d9da | 2014-01-02 11:47:23 +0530 | [diff] [blame] | 34 | } |
| 35 | } |
| 36 | }); |
| 37 | } |
| 38 | |
Nabin Hait | 9d1f077 | 2014-02-19 17:43:24 +0530 | [diff] [blame] | 39 | erpnext.utils.get_address_display = function(frm, address_field, display_field) { |
Rushabh Mehta | 49dd7be | 2014-01-28 17:43:10 +0530 | [diff] [blame] | 40 | if(frm.updating_party_details) return; |
| 41 | if(!address_field) { |
| 42 | if(frm.doc.customer) { |
| 43 | address_field = "customer_address"; |
Nabin Hait | 9d1f077 | 2014-02-19 17:43:24 +0530 | [diff] [blame] | 44 | } else if(frm.doc.supplier) { |
Rushabh Mehta | 49dd7be | 2014-01-28 17:43:10 +0530 | [diff] [blame] | 45 | address_field = "supplier_address"; |
Nabin Hait | 9d1f077 | 2014-02-19 17:43:24 +0530 | [diff] [blame] | 46 | } else return; |
Rushabh Mehta | 49dd7be | 2014-01-28 17:43:10 +0530 | [diff] [blame] | 47 | } |
Nabin Hait | 9d1f077 | 2014-02-19 17:43:24 +0530 | [diff] [blame] | 48 | if(!display_field) display_field = "address_display"; |
Nabin Hait | b87e9f2 | 2014-01-29 19:51:36 +0530 | [diff] [blame] | 49 | if(frm.doc[address_field]) { |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 50 | frappe.call({ |
Nabin Hait | b87e9f2 | 2014-01-29 19:51:36 +0530 | [diff] [blame] | 51 | method: "erpnext.utilities.doctype.address.address.get_address_display", |
Nabin Hait | 9d1f077 | 2014-02-19 17:43:24 +0530 | [diff] [blame] | 52 | args: {"address_dict": frm.doc[address_field] }, |
Nabin Hait | b87e9f2 | 2014-01-29 19:51:36 +0530 | [diff] [blame] | 53 | callback: function(r) { |
| 54 | if(r.message) |
Nabin Hait | 9d1f077 | 2014-02-19 17:43:24 +0530 | [diff] [blame] | 55 | frm.set_value(display_field, r.message) |
Nabin Hait | b87e9f2 | 2014-01-29 19:51:36 +0530 | [diff] [blame] | 56 | } |
| 57 | }) |
| 58 | } |
Rushabh Mehta | b09d9da | 2014-01-02 11:47:23 +0530 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | erpnext.utils.get_contact_details = function(frm) { |
Rushabh Mehta | 49dd7be | 2014-01-28 17:43:10 +0530 | [diff] [blame] | 62 | if(frm.updating_party_details) return; |
Nabin Hait | b87e9f2 | 2014-01-29 19:51:36 +0530 | [diff] [blame] | 63 | |
Nabin Hait | 9d1f077 | 2014-02-19 17:43:24 +0530 | [diff] [blame] | 64 | if(frm.doc["contact_person"]) { |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 65 | frappe.call({ |
Nabin Hait | b87e9f2 | 2014-01-29 19:51:36 +0530 | [diff] [blame] | 66 | method: "erpnext.utilities.doctype.contact.contact.get_contact_details", |
| 67 | args: {contact: frm.doc.contact_person }, |
| 68 | callback: function(r) { |
| 69 | if(r.message) |
| 70 | frm.set_value(r.message); |
| 71 | } |
| 72 | }) |
| 73 | } |
Rushabh Mehta | b09d9da | 2014-01-02 11:47:23 +0530 | [diff] [blame] | 74 | } |