Anand Doshi | 885e074 | 2015-03-03 14:55:30 +0530 | [diff] [blame] | 1 | // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors |
Rushabh Mehta | b09d9da | 2014-01-02 11:47:23 +0530 | [diff] [blame] | 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 | 8bbca6f | 2016-04-12 19:16:33 +0530 | [diff] [blame] | 5 | |
Nabin Hait | a3dd72a | 2014-05-28 12:49:20 +0530 | [diff] [blame] | 6 | erpnext.utils.get_party_details = function(frm, method, args, callback) { |
marination | e27b996 | 2020-07-03 22:03:25 +0530 | [diff] [blame] | 7 | if (!method) { |
Rushabh Mehta | cc008cc | 2014-02-03 16:14:56 +0530 | [diff] [blame] | 8 | method = "erpnext.accounts.party.get_party_details"; |
Rushabh Mehta | 49dd7be | 2014-01-28 17:43:10 +0530 | [diff] [blame] | 9 | } |
Deepesh Garg | 6e2c13f | 2019-12-10 15:55:05 +0530 | [diff] [blame] | 10 | |
| 11 | if (args) { |
| 12 | if (in_list(['Sales Invoice', 'Sales Order', 'Delivery Note'], frm.doc.doctype)) { |
| 13 | if (frm.doc.company_address && (!args.company_address)) { |
| 14 | args.company_address = frm.doc.company_address; |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | if (in_list(['Purchase Invoice', 'Purchase Order', 'Purchase Receipt'], frm.doc.doctype)) { |
| 19 | if (frm.doc.shipping_address && (!args.shipping_address)) { |
| 20 | args.shipping_address = frm.doc.shipping_address; |
| 21 | } |
| 22 | } |
| 23 | } |
| 24 | |
marination | e27b996 | 2020-07-03 22:03:25 +0530 | [diff] [blame] | 25 | if (!args) { |
| 26 | if ((frm.doctype != "Purchase Order" && frm.doc.customer) |
Nabin Hait | 34c551d | 2019-07-03 10:34:31 +0530 | [diff] [blame] | 27 | || (frm.doc.party_name && in_list(['Quotation', 'Opportunity'], frm.doc.doctype))) { |
| 28 | |
| 29 | let party_type = "Customer"; |
marination | e27b996 | 2020-07-03 22:03:25 +0530 | [diff] [blame] | 30 | if (frm.doc.quotation_to && frm.doc.quotation_to === "Lead") { |
Nabin Hait | 34c551d | 2019-07-03 10:34:31 +0530 | [diff] [blame] | 31 | party_type = "Lead"; |
| 32 | } |
| 33 | |
Anand Doshi | 78eeacb | 2014-04-23 19:15:15 +0530 | [diff] [blame] | 34 | args = { |
Nabin Hait | 34c551d | 2019-07-03 10:34:31 +0530 | [diff] [blame] | 35 | party: frm.doc.customer || frm.doc.party_name, |
| 36 | party_type: party_type, |
Rushabh Mehta | 24da761 | 2014-01-29 15:26:04 +0530 | [diff] [blame] | 37 | price_list: frm.doc.selling_price_list |
| 38 | }; |
marination | e27b996 | 2020-07-03 22:03:25 +0530 | [diff] [blame] | 39 | } else if (frm.doc.supplier) { |
Anand Doshi | 78eeacb | 2014-04-23 19:15:15 +0530 | [diff] [blame] | 40 | args = { |
Rushabh Mehta | cc008cc | 2014-02-03 16:14:56 +0530 | [diff] [blame] | 41 | party: frm.doc.supplier, |
| 42 | party_type: "Supplier", |
Shreya Shah | 3a9eec2 | 2018-02-16 13:05:21 +0530 | [diff] [blame] | 43 | bill_date: frm.doc.bill_date, |
Rushabh Mehta | 24da761 | 2014-01-29 15:26:04 +0530 | [diff] [blame] | 44 | price_list: frm.doc.buying_price_list |
| 45 | }; |
Rushabh Mehta | 49dd7be | 2014-01-28 17:43:10 +0530 | [diff] [blame] | 46 | } |
shreyas | 22d26a1 | 2016-02-01 15:32:32 +0530 | [diff] [blame] | 47 | |
Deepesh Garg | 6e2c13f | 2019-12-10 15:55:05 +0530 | [diff] [blame] | 48 | if (in_list(['Sales Invoice', 'Sales Order', 'Delivery Note'], frm.doc.doctype)) { |
| 49 | if (!args) { |
| 50 | args = { |
| 51 | party: frm.doc.customer || frm.doc.party_name, |
| 52 | party_type: 'Customer' |
| 53 | } |
| 54 | } |
| 55 | if (frm.doc.company_address && (!args.company_address)) { |
| 56 | args.company_address = frm.doc.company_address; |
| 57 | } |
| 58 | |
| 59 | if (frm.doc.shipping_address_name &&(!args.shipping_address_name)) { |
| 60 | args.shipping_address_name = frm.doc.shipping_address_name; |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | if (in_list(['Purchase Invoice', 'Purchase Order', 'Purchase Receipt'], frm.doc.doctype)) { |
| 65 | if (!args) { |
| 66 | args = { |
| 67 | party: frm.doc.supplier, |
| 68 | party_type: 'Supplier' |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | if (frm.doc.shipping_address && (!args.shipping_address)) { |
| 73 | args.shipping_address = frm.doc.shipping_address; |
| 74 | } |
| 75 | } |
| 76 | |
Anand Doshi | 9a4d165 | 2015-10-12 16:23:51 +0530 | [diff] [blame] | 77 | if (args) { |
Nabin Hait | 83e68bb | 2015-10-26 17:40:31 +0530 | [diff] [blame] | 78 | args.posting_date = frm.doc.posting_date || frm.doc.transaction_date; |
Anand Doshi | 9a4d165 | 2015-10-12 16:23:51 +0530 | [diff] [blame] | 79 | } |
Rushabh Mehta | 49dd7be | 2014-01-28 17:43:10 +0530 | [diff] [blame] | 80 | } |
marination | e27b996 | 2020-07-03 22:03:25 +0530 | [diff] [blame] | 81 | if (!args || !args.party) return; |
shreyas | 22d26a1 | 2016-02-01 15:32:32 +0530 | [diff] [blame] | 82 | |
marination | e27b996 | 2020-07-03 22:03:25 +0530 | [diff] [blame] | 83 | if (frappe.meta.get_docfield(frm.doc.doctype, "taxes")) { |
| 84 | if (!erpnext.utils.validate_mandatory(frm, "Posting / Transaction Date", |
Nabin Hait | 00818bf | 2015-10-23 16:10:56 +0530 | [diff] [blame] | 85 | args.posting_date, args.party_type=="Customer" ? "customer": "supplier")) return; |
| 86 | } |
shreyas | 22d26a1 | 2016-02-01 15:32:32 +0530 | [diff] [blame] | 87 | |
marination | e27b996 | 2020-07-03 22:03:25 +0530 | [diff] [blame] | 88 | if (!erpnext.utils.validate_mandatory(frm, "Company", frm.doc.company, args.party_type=="Customer" ? "customer": "supplier")) { |
| 89 | return; |
| 90 | } |
| 91 | |
Rushabh Mehta | cc008cc | 2014-02-03 16:14:56 +0530 | [diff] [blame] | 92 | args.currency = frm.doc.currency; |
| 93 | args.company = frm.doc.company; |
Nabin Hait | 4d7c4fc | 2014-06-18 16:40:27 +0530 | [diff] [blame] | 94 | args.doctype = frm.doc.doctype; |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 95 | frappe.call({ |
Rushabh Mehta | b09d9da | 2014-01-02 11:47:23 +0530 | [diff] [blame] | 96 | method: method, |
| 97 | args: args, |
| 98 | callback: function(r) { |
marination | e27b996 | 2020-07-03 22:03:25 +0530 | [diff] [blame] | 99 | if (r.message) { |
Zarrar | 7f8024c | 2018-08-01 17:45:05 +0530 | [diff] [blame] | 100 | frm.supplier_tds = r.message.supplier_tds; |
Rushabh Mehta | 49dd7be | 2014-01-28 17:43:10 +0530 | [diff] [blame] | 101 | frm.updating_party_details = true; |
Rushabh Mehta | dab1172 | 2017-07-17 15:31:17 +0530 | [diff] [blame] | 102 | frappe.run_serially([ |
| 103 | () => frm.set_value(r.message), |
| 104 | () => { |
| 105 | frm.updating_party_details = false; |
marination | e27b996 | 2020-07-03 22:03:25 +0530 | [diff] [blame] | 106 | if (callback) callback(); |
Rushabh Mehta | dab1172 | 2017-07-17 15:31:17 +0530 | [diff] [blame] | 107 | frm.refresh(); |
| 108 | erpnext.utils.add_item(frm); |
| 109 | } |
| 110 | ]); |
Rushabh Mehta | b09d9da | 2014-01-02 11:47:23 +0530 | [diff] [blame] | 111 | } |
| 112 | } |
| 113 | }); |
| 114 | } |
| 115 | |
Rushabh Mehta | 5095437 | 2017-02-23 17:03:46 +0530 | [diff] [blame] | 116 | erpnext.utils.add_item = function(frm) { |
marination | e27b996 | 2020-07-03 22:03:25 +0530 | [diff] [blame] | 117 | if (frm.is_new()) { |
Rushabh Mehta | 5095437 | 2017-02-23 17:03:46 +0530 | [diff] [blame] | 118 | var prev_route = frappe.get_prev_route(); |
marination | e27b996 | 2020-07-03 22:03:25 +0530 | [diff] [blame] | 119 | if (prev_route[1]==='Item' && !(frm.doc.items && frm.doc.items.length)) { |
Rushabh Mehta | 5095437 | 2017-02-23 17:03:46 +0530 | [diff] [blame] | 120 | // add row |
Faris Ansari | ab74ca7 | 2017-05-30 12:54:42 +0530 | [diff] [blame] | 121 | var item = frm.add_child('items'); |
Rushabh Mehta | 5095437 | 2017-02-23 17:03:46 +0530 | [diff] [blame] | 122 | frm.refresh_field('items'); |
| 123 | |
| 124 | // set item |
| 125 | frappe.model.set_value(item.doctype, item.name, 'item_code', prev_route[2]); |
| 126 | } |
| 127 | } |
| 128 | } |
| 129 | |
Nabin Hait | 6221117 | 2016-03-16 16:22:03 +0530 | [diff] [blame] | 130 | erpnext.utils.get_address_display = function(frm, address_field, display_field, is_your_company_address) { |
marination | e27b996 | 2020-07-03 22:03:25 +0530 | [diff] [blame] | 131 | if (frm.updating_party_details) return; |
shreyas | 22d26a1 | 2016-02-01 15:32:32 +0530 | [diff] [blame] | 132 | |
marination | e27b996 | 2020-07-03 22:03:25 +0530 | [diff] [blame] | 133 | if (!address_field) { |
| 134 | if (frm.doctype != "Purchase Order" && frm.doc.customer) { |
Rushabh Mehta | 49dd7be | 2014-01-28 17:43:10 +0530 | [diff] [blame] | 135 | address_field = "customer_address"; |
marination | e27b996 | 2020-07-03 22:03:25 +0530 | [diff] [blame] | 136 | } else if (frm.doc.supplier) { |
Rushabh Mehta | 49dd7be | 2014-01-28 17:43:10 +0530 | [diff] [blame] | 137 | address_field = "supplier_address"; |
Nabin Hait | 9d1f077 | 2014-02-19 17:43:24 +0530 | [diff] [blame] | 138 | } else return; |
Anand Doshi | 78eeacb | 2014-04-23 19:15:15 +0530 | [diff] [blame] | 139 | } |
shreyas | 22d26a1 | 2016-02-01 15:32:32 +0530 | [diff] [blame] | 140 | |
marination | e27b996 | 2020-07-03 22:03:25 +0530 | [diff] [blame] | 141 | if (!display_field) display_field = "address_display"; |
| 142 | if (frm.doc[address_field]) { |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 143 | frappe.call({ |
KanchanChauhan | 1dc26b1 | 2017-06-13 15:26:35 +0530 | [diff] [blame] | 144 | method: "frappe.contacts.doctype.address.address.get_address_display", |
Nabin Hait | 9d1f077 | 2014-02-19 17:43:24 +0530 | [diff] [blame] | 145 | args: {"address_dict": frm.doc[address_field] }, |
Nabin Hait | b87e9f2 | 2014-01-29 19:51:36 +0530 | [diff] [blame] | 146 | callback: function(r) { |
marination | e27b996 | 2020-07-03 22:03:25 +0530 | [diff] [blame] | 147 | if (r.message) { |
Nabin Hait | 9d1f077 | 2014-02-19 17:43:24 +0530 | [diff] [blame] | 148 | frm.set_value(display_field, r.message) |
Neil Trini Lasrado | 09f9c96 | 2015-08-26 10:41:31 +0530 | [diff] [blame] | 149 | } |
Nabin Hait | b87e9f2 | 2014-01-29 19:51:36 +0530 | [diff] [blame] | 150 | } |
| 151 | }) |
Nabin Hait | 6221117 | 2016-03-16 16:22:03 +0530 | [diff] [blame] | 152 | } else { |
mbauskar | 8a2e6f4 | 2017-04-14 17:50:32 +0530 | [diff] [blame] | 153 | frm.set_value(display_field, ''); |
Nabin Hait | b87e9f2 | 2014-01-29 19:51:36 +0530 | [diff] [blame] | 154 | } |
Anand Doshi | 2f957f2 | 2016-04-08 17:36:10 +0530 | [diff] [blame] | 155 | }; |
Rushabh Mehta | 5d0e8de | 2016-04-11 17:34:25 +0530 | [diff] [blame] | 156 | |
Saif Ur Rehman | fd531a6 | 2018-12-29 01:49:11 +0500 | [diff] [blame] | 157 | erpnext.utils.set_taxes_from_address = function(frm, triggered_from_field, billing_address_field, shipping_address_field) { |
marination | e27b996 | 2020-07-03 22:03:25 +0530 | [diff] [blame] | 158 | if (frm.updating_party_details) return; |
Saif Ur Rehman | fd531a6 | 2018-12-29 01:49:11 +0500 | [diff] [blame] | 159 | |
marination | e27b996 | 2020-07-03 22:03:25 +0530 | [diff] [blame] | 160 | if (frappe.meta.get_docfield(frm.doc.doctype, "taxes")) { |
| 161 | if (!erpnext.utils.validate_mandatory(frm, "Lead / Customer / Supplier", |
Nabin Hait | 34c551d | 2019-07-03 10:34:31 +0530 | [diff] [blame] | 162 | frm.doc.customer || frm.doc.supplier || frm.doc.lead || frm.doc.party_name, triggered_from_field)) { |
Saif Ur Rehman | fd531a6 | 2018-12-29 01:49:11 +0500 | [diff] [blame] | 163 | return; |
| 164 | } |
| 165 | |
marination | e27b996 | 2020-07-03 22:03:25 +0530 | [diff] [blame] | 166 | if (!erpnext.utils.validate_mandatory(frm, "Posting / Transaction Date", |
Saif Ur Rehman | fd531a6 | 2018-12-29 01:49:11 +0500 | [diff] [blame] | 167 | frm.doc.posting_date || frm.doc.transaction_date, triggered_from_field)) { |
| 168 | return; |
| 169 | } |
| 170 | } else { |
| 171 | return; |
| 172 | } |
| 173 | |
| 174 | frappe.call({ |
| 175 | method: "erpnext.accounts.party.get_address_tax_category", |
| 176 | args: { |
| 177 | "tax_category": frm.doc.tax_category, |
| 178 | "billing_address": frm.doc[billing_address_field], |
| 179 | "shipping_address": frm.doc[shipping_address_field] |
| 180 | }, |
| 181 | callback: function(r) { |
marination | e27b996 | 2020-07-03 22:03:25 +0530 | [diff] [blame] | 182 | if (!r.exc){ |
| 183 | if (frm.doc.tax_category != r.message) { |
Saif Ur Rehman | fd531a6 | 2018-12-29 01:49:11 +0500 | [diff] [blame] | 184 | frm.set_value("tax_category", r.message); |
| 185 | } else { |
| 186 | erpnext.utils.set_taxes(frm, triggered_from_field); |
| 187 | } |
| 188 | } |
| 189 | } |
| 190 | }); |
| 191 | }; |
| 192 | |
Saif Ur Rehman | 6778668 | 2018-12-27 02:11:07 +0500 | [diff] [blame] | 193 | erpnext.utils.set_taxes = function(frm, triggered_from_field) { |
marination | e27b996 | 2020-07-03 22:03:25 +0530 | [diff] [blame] | 194 | if (frappe.meta.get_docfield(frm.doc.doctype, "taxes")) { |
| 195 | if (!erpnext.utils.validate_mandatory(frm, "Company", frm.doc.company, triggered_from_field)) { |
| 196 | return; |
| 197 | } |
| 198 | |
| 199 | if (!erpnext.utils.validate_mandatory(frm, "Lead / Customer / Supplier", |
deepeshgarg007 | d5fcab5 | 2019-07-15 12:44:11 +0530 | [diff] [blame] | 200 | frm.doc.customer || frm.doc.supplier || frm.doc.lead || frm.doc.party_name, triggered_from_field)) { |
Faris Ansari | ab74ca7 | 2017-05-30 12:54:42 +0530 | [diff] [blame] | 201 | return; |
| 202 | } |
Anand Doshi | 2f957f2 | 2016-04-08 17:36:10 +0530 | [diff] [blame] | 203 | |
marination | e27b996 | 2020-07-03 22:03:25 +0530 | [diff] [blame] | 204 | if (!erpnext.utils.validate_mandatory(frm, "Posting / Transaction Date", |
Saif Ur Rehman | 6778668 | 2018-12-27 02:11:07 +0500 | [diff] [blame] | 205 | frm.doc.posting_date || frm.doc.transaction_date, triggered_from_field)) { |
Anand Doshi | 2f957f2 | 2016-04-08 17:36:10 +0530 | [diff] [blame] | 206 | return; |
| 207 | } |
| 208 | } else { |
| 209 | return; |
| 210 | } |
| 211 | |
| 212 | var party_type, party; |
| 213 | if (frm.doc.lead) { |
| 214 | party_type = 'Lead'; |
| 215 | party = frm.doc.lead; |
| 216 | } else if (frm.doc.customer) { |
| 217 | party_type = 'Customer'; |
| 218 | party = frm.doc.customer; |
| 219 | } else if (frm.doc.supplier) { |
| 220 | party_type = 'Supplier'; |
| 221 | party = frm.doc.supplier; |
Nabin Hait | 34c551d | 2019-07-03 10:34:31 +0530 | [diff] [blame] | 222 | } else if (frm.doc.quotation_to){ |
| 223 | party_type = frm.doc.quotation_to; |
| 224 | party = frm.doc.party_name; |
Anand Doshi | 2f957f2 | 2016-04-08 17:36:10 +0530 | [diff] [blame] | 225 | } |
| 226 | |
Rohit Waghchaure | 4f3b7da | 2020-09-15 14:47:36 +0530 | [diff] [blame] | 227 | if (!frm.doc.company) { |
Deepesh Garg | 0aff6d8 | 2020-09-19 18:05:58 +0530 | [diff] [blame] | 228 | frappe.throw(__("Kindly select the company first")); |
Rohit Waghchaure | 4f3b7da | 2020-09-15 14:47:36 +0530 | [diff] [blame] | 229 | } |
| 230 | |
Anand Doshi | 2f957f2 | 2016-04-08 17:36:10 +0530 | [diff] [blame] | 231 | frappe.call({ |
| 232 | method: "erpnext.accounts.party.set_taxes", |
| 233 | args: { |
| 234 | "party": party, |
| 235 | "party_type": party_type, |
| 236 | "posting_date": frm.doc.posting_date || frm.doc.transaction_date, |
| 237 | "company": frm.doc.company, |
Saif Ur Rehman | 13a6c0a | 2019-01-06 18:14:18 +0500 | [diff] [blame] | 238 | "customer_group": frm.doc.customer_group, |
| 239 | "supplier_group": frm.doc.supplier_group, |
Saif Ur Rehman | 6778668 | 2018-12-27 02:11:07 +0500 | [diff] [blame] | 240 | "tax_category": frm.doc.tax_category, |
Anand Doshi | 2f957f2 | 2016-04-08 17:36:10 +0530 | [diff] [blame] | 241 | "billing_address": ((frm.doc.customer || frm.doc.lead) ? (frm.doc.customer_address) : (frm.doc.supplier_address)), |
| 242 | "shipping_address": frm.doc.shipping_address_name |
| 243 | }, |
| 244 | callback: function(r) { |
marination | e27b996 | 2020-07-03 22:03:25 +0530 | [diff] [blame] | 245 | if (r.message){ |
Anand Doshi | 2f957f2 | 2016-04-08 17:36:10 +0530 | [diff] [blame] | 246 | frm.set_value("taxes_and_charges", r.message) |
| 247 | } |
| 248 | } |
| 249 | }); |
Saif Ur Rehman | 6778668 | 2018-12-27 02:11:07 +0500 | [diff] [blame] | 250 | }; |
Rushabh Mehta | b09d9da | 2014-01-02 11:47:23 +0530 | [diff] [blame] | 251 | |
| 252 | erpnext.utils.get_contact_details = function(frm) { |
marination | e27b996 | 2020-07-03 22:03:25 +0530 | [diff] [blame] | 253 | if (frm.updating_party_details) return; |
Anand Doshi | 78eeacb | 2014-04-23 19:15:15 +0530 | [diff] [blame] | 254 | |
marination | e27b996 | 2020-07-03 22:03:25 +0530 | [diff] [blame] | 255 | if (frm.doc["contact_person"]) { |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 256 | frappe.call({ |
KanchanChauhan | 1dc26b1 | 2017-06-13 15:26:35 +0530 | [diff] [blame] | 257 | method: "frappe.contacts.doctype.contact.contact.get_contact_details", |
Nabin Hait | b87e9f2 | 2014-01-29 19:51:36 +0530 | [diff] [blame] | 258 | args: {contact: frm.doc.contact_person }, |
| 259 | callback: function(r) { |
marination | e27b996 | 2020-07-03 22:03:25 +0530 | [diff] [blame] | 260 | if (r.message) |
Nabin Hait | b87e9f2 | 2014-01-29 19:51:36 +0530 | [diff] [blame] | 261 | frm.set_value(r.message); |
| 262 | } |
| 263 | }) |
| 264 | } |
Anand Doshi | 78eeacb | 2014-04-23 19:15:15 +0530 | [diff] [blame] | 265 | } |
Nabin Hait | 00818bf | 2015-10-23 16:10:56 +0530 | [diff] [blame] | 266 | |
| 267 | erpnext.utils.validate_mandatory = function(frm, label, value, trigger_on) { |
marination | e27b996 | 2020-07-03 22:03:25 +0530 | [diff] [blame] | 268 | if (!value) { |
Nabin Hait | 00818bf | 2015-10-23 16:10:56 +0530 | [diff] [blame] | 269 | frm.doc[trigger_on] = ""; |
| 270 | refresh_field(trigger_on); |
marination | e27b996 | 2020-07-03 22:03:25 +0530 | [diff] [blame] | 271 | frappe.throw({message:__("Please enter {0} first", [label]), title:__("Mandatory")}); |
Nabin Hait | 00818bf | 2015-10-23 16:10:56 +0530 | [diff] [blame] | 272 | return false; |
| 273 | } |
| 274 | return true; |
shreyas | 22d26a1 | 2016-02-01 15:32:32 +0530 | [diff] [blame] | 275 | } |
| 276 | |
Rohit Waghchaure | b2e7a1f | 2016-04-11 12:10:20 +0530 | [diff] [blame] | 277 | erpnext.utils.get_shipping_address = function(frm, callback){ |
Maxwell Morais | a2c1d92 | 2018-08-27 03:35:41 -0300 | [diff] [blame] | 278 | if (frm.doc.company) { |
Deepesh Garg | b4be292 | 2021-01-28 13:09:56 +0530 | [diff] [blame] | 279 | if (!(frm.doc.inter_com_order_reference || frm.doc.internal_invoice_reference || |
| 280 | frm.doc.internal_order_reference)) { |
| 281 | if (callback) { |
| 282 | return callback(); |
| 283 | } |
| 284 | } |
rohitwaghchaure | 5ecc26b | 2018-06-04 11:00:24 +0530 | [diff] [blame] | 285 | frappe.call({ |
Abhishek Balam | 89419c9 | 2020-10-14 20:09:05 +0530 | [diff] [blame] | 286 | method: "erpnext.accounts.custom.address.get_shipping_address", |
rohitwaghchaure | 5ecc26b | 2018-06-04 11:00:24 +0530 | [diff] [blame] | 287 | args: { |
| 288 | company: frm.doc.company, |
| 289 | address: frm.doc.shipping_address |
| 290 | }, |
| 291 | callback: function(r){ |
marination | e27b996 | 2020-07-03 22:03:25 +0530 | [diff] [blame] | 292 | if (r.message){ |
rohitwaghchaure | 5ecc26b | 2018-06-04 11:00:24 +0530 | [diff] [blame] | 293 | frm.set_value("shipping_address", r.message[0]) //Address title or name |
| 294 | frm.set_value("shipping_address_display", r.message[1]) //Address to be displayed on the page |
| 295 | } |
Rohit Waghchaure | b2e7a1f | 2016-04-11 12:10:20 +0530 | [diff] [blame] | 296 | |
marination | e27b996 | 2020-07-03 22:03:25 +0530 | [diff] [blame] | 297 | if (callback){ |
rohitwaghchaure | 5ecc26b | 2018-06-04 11:00:24 +0530 | [diff] [blame] | 298 | return callback(); |
| 299 | } |
Rohit Waghchaure | b2e7a1f | 2016-04-11 12:10:20 +0530 | [diff] [blame] | 300 | } |
rohitwaghchaure | 5ecc26b | 2018-06-04 11:00:24 +0530 | [diff] [blame] | 301 | }); |
| 302 | } else { |
| 303 | frappe.msgprint(__("Select company first")); |
| 304 | } |
Deepesh Garg | 0aff6d8 | 2020-09-19 18:05:58 +0530 | [diff] [blame] | 305 | } |