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 | |
| 4 | wn.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 | b09d9da | 2014-01-02 11:47:23 +0530 | [diff] [blame] | 26 | wn.call({ |
| 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 | |
| 39 | erpnext.utils.get_address_display = function(frm, address_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"; |
| 44 | } else { |
| 45 | address_field = "supplier_address"; |
| 46 | } |
| 47 | } |
Nabin Hait | b87e9f2 | 2014-01-29 19:51:36 +0530 | [diff] [blame] | 48 | if(frm.doc[address_field]) { |
| 49 | wn.call({ |
| 50 | method: "erpnext.utilities.doctype.address.address.get_address_display", |
| 51 | args: {address: frm.doc[address_field] }, |
| 52 | callback: function(r) { |
| 53 | if(r.message) |
| 54 | frm.set_value("address_display", r.message) |
| 55 | } |
| 56 | }) |
| 57 | } |
Rushabh Mehta | b09d9da | 2014-01-02 11:47:23 +0530 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | erpnext.utils.get_contact_details = function(frm) { |
Rushabh Mehta | 49dd7be | 2014-01-28 17:43:10 +0530 | [diff] [blame] | 61 | if(frm.updating_party_details) return; |
Nabin Hait | b87e9f2 | 2014-01-29 19:51:36 +0530 | [diff] [blame] | 62 | |
| 63 | if(frm.doc[address_field]) { |
| 64 | wn.call({ |
| 65 | method: "erpnext.utilities.doctype.contact.contact.get_contact_details", |
| 66 | args: {contact: frm.doc.contact_person }, |
| 67 | callback: function(r) { |
| 68 | if(r.message) |
| 69 | frm.set_value(r.message); |
| 70 | } |
| 71 | }) |
| 72 | } |
Rushabh Mehta | b09d9da | 2014-01-02 11:47:23 +0530 | [diff] [blame] | 73 | } |