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) { |
| 7 | if(frm.doc.customer) { |
| 8 | method = "erpnext.selling.doctype.customer.customer.get_customer_details"; |
Rushabh Mehta | 24da761 | 2014-01-29 15:26:04 +0530 | [diff] [blame] | 9 | var price_list_field = "selling_price_list"; |
Rushabh Mehta | 49dd7be | 2014-01-28 17:43:10 +0530 | [diff] [blame] | 10 | } else { |
| 11 | method = "erpnext.buying.doctype.supplier.supplier.get_supplier_details"; |
Rushabh Mehta | 24da761 | 2014-01-29 15:26:04 +0530 | [diff] [blame] | 12 | var price_list_field = "buying_price_list"; |
Rushabh Mehta | 49dd7be | 2014-01-28 17:43:10 +0530 | [diff] [blame] | 13 | } |
| 14 | } |
| 15 | if(!args) { |
| 16 | if(frm.doc.customer) { |
Rushabh Mehta | 24da761 | 2014-01-29 15:26:04 +0530 | [diff] [blame] | 17 | args = { |
| 18 | customer: frm.doc.customer, |
| 19 | price_list: frm.doc.selling_price_list |
| 20 | }; |
Rushabh Mehta | 49dd7be | 2014-01-28 17:43:10 +0530 | [diff] [blame] | 21 | } else { |
Rushabh Mehta | 24da761 | 2014-01-29 15:26:04 +0530 | [diff] [blame] | 22 | args = { |
| 23 | supplier: frm.doc.supplier, |
| 24 | price_list: frm.doc.buying_price_list |
| 25 | }; |
Rushabh Mehta | 49dd7be | 2014-01-28 17:43:10 +0530 | [diff] [blame] | 26 | } |
Rushabh Mehta | 24da761 | 2014-01-29 15:26:04 +0530 | [diff] [blame] | 27 | args.currency = frm.doc.currency; |
Rushabh Mehta | 49dd7be | 2014-01-28 17:43:10 +0530 | [diff] [blame] | 28 | } |
Rushabh Mehta | b09d9da | 2014-01-02 11:47:23 +0530 | [diff] [blame] | 29 | wn.call({ |
| 30 | method: method, |
| 31 | args: args, |
| 32 | callback: function(r) { |
| 33 | if(r.message) { |
Rushabh Mehta | 49dd7be | 2014-01-28 17:43:10 +0530 | [diff] [blame] | 34 | frm.updating_party_details = true; |
Rushabh Mehta | b09d9da | 2014-01-02 11:47:23 +0530 | [diff] [blame] | 35 | frm.set_value(r.message); |
Rushabh Mehta | 49dd7be | 2014-01-28 17:43:10 +0530 | [diff] [blame] | 36 | frm.updating_party_details = false; |
Rushabh Mehta | b09d9da | 2014-01-02 11:47:23 +0530 | [diff] [blame] | 37 | } |
| 38 | } |
| 39 | }); |
| 40 | } |
| 41 | |
| 42 | erpnext.utils.get_address_display = function(frm, address_field) { |
Rushabh Mehta | 49dd7be | 2014-01-28 17:43:10 +0530 | [diff] [blame] | 43 | if(frm.updating_party_details) return; |
| 44 | if(!address_field) { |
| 45 | if(frm.doc.customer) { |
| 46 | address_field = "customer_address"; |
| 47 | } else { |
| 48 | address_field = "supplier_address"; |
| 49 | } |
| 50 | } |
Nabin Hait | b87e9f2 | 2014-01-29 19:51:36 +0530 | [diff] [blame] | 51 | if(frm.doc[address_field]) { |
| 52 | wn.call({ |
| 53 | method: "erpnext.utilities.doctype.address.address.get_address_display", |
| 54 | args: {address: frm.doc[address_field] }, |
| 55 | callback: function(r) { |
| 56 | if(r.message) |
| 57 | frm.set_value("address_display", r.message) |
| 58 | } |
| 59 | }) |
| 60 | } |
Rushabh Mehta | b09d9da | 2014-01-02 11:47:23 +0530 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | erpnext.utils.get_contact_details = function(frm) { |
Rushabh Mehta | 49dd7be | 2014-01-28 17:43:10 +0530 | [diff] [blame] | 64 | if(frm.updating_party_details) return; |
Nabin Hait | b87e9f2 | 2014-01-29 19:51:36 +0530 | [diff] [blame] | 65 | |
| 66 | if(frm.doc[address_field]) { |
| 67 | wn.call({ |
| 68 | method: "erpnext.utilities.doctype.contact.contact.get_contact_details", |
| 69 | args: {contact: frm.doc.contact_person }, |
| 70 | callback: function(r) { |
| 71 | if(r.message) |
| 72 | frm.set_value(r.message); |
| 73 | } |
| 74 | }) |
| 75 | } |
Rushabh Mehta | b09d9da | 2014-01-02 11:47:23 +0530 | [diff] [blame] | 76 | } |