Anand Doshi | 885e074 | 2015-03-03 14:55:30 +0530 | [diff] [blame] | 1 | // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors |
Rushabh Mehta | e67d1fb | 2013-08-05 14:59:54 +0530 | [diff] [blame] | 2 | // License: GNU General Public License v3. See license.txt |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 3 | frappe.provide("erpnext"); |
Nabin Hait | b072c74 | 2014-12-16 12:49:13 +0530 | [diff] [blame] | 4 | frappe.provide("erpnext.utils"); |
rohitwaghchaure | 0da19a4 | 2024-03-12 12:27:21 +0530 | [diff] [blame] | 5 | frappe.provide("erpnext.stock.utils"); |
Anand Doshi | e65e621 | 2012-11-19 15:43:18 +0530 | [diff] [blame] | 6 | |
Anand Doshi | bdee6e0 | 2013-07-09 13:03:39 +0530 | [diff] [blame] | 7 | $.extend(erpnext, { |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 8 | get_currency: function (company) { |
| 9 | if (!company && cur_frm) company = cur_frm.doc.company; |
| 10 | if (company) |
ruthra kumar | fa2d33c | 2023-12-12 15:43:39 +0530 | [diff] [blame] | 11 | return frappe.get_doc(":Company", company)?.default_currency || frappe.boot.sysdefaults.currency; |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 12 | else return frappe.boot.sysdefaults.currency; |
Anand Doshi | bdee6e0 | 2013-07-09 13:03:39 +0530 | [diff] [blame] | 13 | }, |
Rushabh Mehta | c38fc71 | 2014-04-16 17:21:25 +0530 | [diff] [blame] | 14 | |
tundebabzy | c897825 | 2018-02-12 10:34:50 +0100 | [diff] [blame] | 15 | get_presentation_currency_list: () => { |
| 16 | const docs = frappe.boot.docs; |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 17 | let currency_list = docs.filter((d) => d.doctype === ":Currency").map((d) => d.name); |
Zarrar | e25dcd2 | 2018-06-21 10:53:12 +0530 | [diff] [blame] | 18 | currency_list.unshift(""); |
tundebabzy | c897825 | 2018-02-12 10:34:50 +0100 | [diff] [blame] | 19 | return currency_list; |
| 20 | }, |
| 21 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 22 | toggle_naming_series: function () { |
| 23 | if (cur_frm && cur_frm.fields_dict.naming_series) { |
| 24 | cur_frm.toggle_display("naming_series", cur_frm.doc.__islocal ? true : false); |
Anand Doshi | bdee6e0 | 2013-07-09 13:03:39 +0530 | [diff] [blame] | 25 | } |
| 26 | }, |
Rushabh Mehta | c38fc71 | 2014-04-16 17:21:25 +0530 | [diff] [blame] | 27 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 28 | hide_company: function (frm) { |
| 29 | if (frm?.fields_dict.company) { |
Rushabh Mehta | 8941841 | 2013-10-07 18:22:29 +0530 | [diff] [blame] | 30 | var companies = Object.keys(locals[":Company"] || {}); |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 31 | if (companies.length === 1) { |
| 32 | if (!frm.doc.company) frm.set_value("company", companies[0]); |
Gursheen Anand | ceeb8fc | 2024-02-27 13:05:29 +0530 | [diff] [blame] | 33 | frm.toggle_display("company", false); |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 34 | } else if (erpnext.last_selected_company) { |
| 35 | if (!frm.doc.company) frm.set_value("company", erpnext.last_selected_company); |
Anand Doshi | bdee6e0 | 2013-07-09 13:03:39 +0530 | [diff] [blame] | 36 | } |
| 37 | } |
Anand Doshi | 1ffc5b5 | 2013-07-15 18:09:43 +0530 | [diff] [blame] | 38 | }, |
Rushabh Mehta | c38fc71 | 2014-04-16 17:21:25 +0530 | [diff] [blame] | 39 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 40 | is_perpetual_inventory_enabled: function (company) { |
| 41 | if (company) { |
Rohit Waghchaure | 44ed52c | 2024-02-24 15:33:59 +0530 | [diff] [blame] | 42 | let company_local = locals[":Company"] && locals[":Company"][company]; |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 43 | if (company_local) { |
Rohit Waghchaure | 44ed52c | 2024-02-24 15:33:59 +0530 | [diff] [blame] | 44 | return cint(company_local.enable_perpetual_inventory); |
| 45 | } |
Rohit Waghchaure | e9ff191 | 2017-06-19 12:54:59 +0530 | [diff] [blame] | 46 | } |
| 47 | }, |
| 48 | |
Makarand Bauskar | e6712c1 | 2017-10-25 12:17:40 +0530 | [diff] [blame] | 49 | stale_rate_allowed: () => { |
rohitwaghchaure | 7677ff0 | 2017-11-02 18:12:14 +0530 | [diff] [blame] | 50 | return cint(frappe.boot.sysdefaults.allow_stale); |
Makarand Bauskar | e6712c1 | 2017-10-25 12:17:40 +0530 | [diff] [blame] | 51 | }, |
| 52 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 53 | setup_serial_or_batch_no: function () { |
Rohit Waghchaure | 732b6e1 | 2024-04-17 12:43:31 +0530 | [diff] [blame^] | 54 | // Deprecated in v15 |
deepeshgarg007 | e64c357 | 2019-05-14 08:50:45 +0530 | [diff] [blame] | 55 | }, |
Nabin Hait | 1ed1c4e | 2019-11-25 12:33:40 +0530 | [diff] [blame] | 56 | |
| 57 | route_to_adjustment_jv: (args) => { |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 58 | frappe.model.with_doctype("Journal Entry", () => { |
Nabin Hait | 1ed1c4e | 2019-11-25 12:33:40 +0530 | [diff] [blame] | 59 | // route to adjustment Journal Entry to handle Account Balance and Stock Value mismatch |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 60 | let journal_entry = frappe.model.get_new_doc("Journal Entry"); |
Nabin Hait | 1ed1c4e | 2019-11-25 12:33:40 +0530 | [diff] [blame] | 61 | |
| 62 | args.accounts.forEach((je_account) => { |
| 63 | let child_row = frappe.model.add_child(journal_entry, "accounts"); |
| 64 | child_row.account = je_account.account; |
| 65 | child_row.debit_in_account_currency = je_account.debit_in_account_currency; |
| 66 | child_row.credit_in_account_currency = je_account.credit_in_account_currency; |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 67 | child_row.party_type = ""; |
Nabin Hait | 1ed1c4e | 2019-11-25 12:33:40 +0530 | [diff] [blame] | 68 | }); |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 69 | frappe.set_route("Form", "Journal Entry", journal_entry.name); |
Nabin Hait | 1ed1c4e | 2019-11-25 12:33:40 +0530 | [diff] [blame] | 70 | }); |
Frappe PR Bot | 255b99e | 2021-08-24 20:19:22 +0530 | [diff] [blame] | 71 | }, |
| 72 | |
Ankush Menat | d37541d | 2021-12-10 12:04:10 +0530 | [diff] [blame] | 73 | route_to_pending_reposts: (args) => { |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 74 | frappe.set_route("List", "Repost Item Valuation", args); |
Ankush Menat | d37541d | 2021-12-10 12:04:10 +0530 | [diff] [blame] | 75 | }, |
Rushabh Mehta | c38fc71 | 2014-04-16 17:21:25 +0530 | [diff] [blame] | 76 | }); |
Rushabh Mehta | 7d36875 | 2014-11-24 14:16:47 +0530 | [diff] [blame] | 77 | |
Nabin Hait | b072c74 | 2014-12-16 12:49:13 +0530 | [diff] [blame] | 78 | $.extend(erpnext.utils, { |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 79 | set_party_dashboard_indicators: function (frm) { |
| 80 | if (frm.doc.__onload && frm.doc.__onload.dashboard_info) { |
deepeshgarg007 | 920dc14 | 2018-11-23 10:17:28 +0530 | [diff] [blame] | 81 | var company_wise_info = frm.doc.__onload.dashboard_info; |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 82 | if (company_wise_info.length > 1) { |
| 83 | company_wise_info.forEach(function (info) { |
deepeshgarg007 | 12f5cef | 2018-12-25 16:06:19 +0530 | [diff] [blame] | 84 | erpnext.utils.add_indicator_for_multicompany(frm, info); |
deepeshgarg007 | a1cffc3 | 2018-11-23 16:51:35 +0530 | [diff] [blame] | 85 | }); |
deepeshgarg007 | 12f5cef | 2018-12-25 16:06:19 +0530 | [diff] [blame] | 86 | } else if (company_wise_info.length === 1) { |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 87 | frm.dashboard.add_indicator( |
| 88 | __("Annual Billing: {0}", [ |
| 89 | format_currency( |
| 90 | company_wise_info[0].billing_this_year, |
| 91 | company_wise_info[0].currency |
| 92 | ), |
| 93 | ]), |
| 94 | "blue" |
| 95 | ); |
| 96 | frm.dashboard.add_indicator( |
| 97 | __("Total Unpaid: {0}", [ |
| 98 | format_currency(company_wise_info[0].total_unpaid, company_wise_info[0].currency), |
| 99 | ]), |
| 100 | company_wise_info[0].total_unpaid ? "orange" : "green" |
| 101 | ); |
deepeshgarg007 | 12f5cef | 2018-12-25 16:06:19 +0530 | [diff] [blame] | 102 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 103 | if (company_wise_info[0].loyalty_points) { |
| 104 | frm.dashboard.add_indicator( |
| 105 | __("Loyalty Points: {0}", [company_wise_info[0].loyalty_points]), |
| 106 | "blue" |
| 107 | ); |
deepeshgarg007 | 64238ee | 2018-12-25 16:28:39 +0530 | [diff] [blame] | 108 | } |
deepeshgarg007 | f31caff | 2018-11-27 15:04:12 +0530 | [diff] [blame] | 109 | } |
Rushabh Mehta | 559aa3a | 2016-09-19 16:04:58 +0530 | [diff] [blame] | 110 | } |
| 111 | }, |
| 112 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 113 | view_serial_batch_nos: function (frm) { |
rohitwaghchaure | 3c15fea | 2023-08-24 17:24:44 +0530 | [diff] [blame] | 114 | if (!frm.doc?.items) { |
| 115 | return; |
| 116 | } |
| 117 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 118 | let bundle_ids = frm.doc.items.filter((d) => d.serial_and_batch_bundle); |
Rohit Waghchaure | 708eefb | 2023-07-10 16:54:55 +0530 | [diff] [blame] | 119 | |
| 120 | if (bundle_ids?.length) { |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 121 | frm.add_custom_button( |
| 122 | __("Serial / Batch Nos"), |
| 123 | () => { |
| 124 | frappe.route_options = { |
| 125 | voucher_no: frm.doc.name, |
| 126 | voucher_type: frm.doc.doctype, |
| 127 | from_date: frm.doc.posting_date || frm.doc.transaction_date, |
| 128 | to_date: frm.doc.posting_date || frm.doc.transaction_date, |
| 129 | company: frm.doc.company, |
| 130 | }; |
| 131 | frappe.set_route("query-report", "Serial and Batch Summary"); |
| 132 | }, |
| 133 | __("View") |
| 134 | ); |
Rohit Waghchaure | 708eefb | 2023-07-10 16:54:55 +0530 | [diff] [blame] | 135 | } |
| 136 | }, |
| 137 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 138 | add_indicator_for_multicompany: function (frm, info) { |
Deepak | 867f2c6 | 2022-05-17 11:52:52 +0530 | [diff] [blame] | 139 | frm.dashboard.stats_area.show(); |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 140 | frm.dashboard.stats_area_row.addClass("flex"); |
| 141 | frm.dashboard.stats_area_row.css("flex-wrap", "wrap"); |
deepeshgarg007 | 12f5cef | 2018-12-25 16:06:19 +0530 | [diff] [blame] | 142 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 143 | var color = info.total_unpaid ? "orange" : "green"; |
deepeshgarg007 | 12f5cef | 2018-12-25 16:06:19 +0530 | [diff] [blame] | 144 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 145 | var indicator = $( |
| 146 | '<div class="flex-column col-xs-6">' + |
| 147 | '<div style="margin-top:10px"><h6>' + |
| 148 | info.company + |
| 149 | "</h6></div>" + |
| 150 | '<div class="badge-link small" style="margin-bottom:10px"><span class="indicator blue">' + |
| 151 | "Annual Billing: " + |
| 152 | format_currency(info.billing_this_year, info.currency) + |
| 153 | "</span></div>" + |
| 154 | '<div class="badge-link small" style="margin-bottom:10px">' + |
| 155 | '<span class="indicator ' + |
| 156 | color + |
| 157 | '">Total Unpaid: ' + |
| 158 | format_currency(info.total_unpaid, info.currency) + |
| 159 | "</span></div>" + |
| 160 | "</div>" |
| 161 | ).appendTo(frm.dashboard.stats_area_row); |
deepeshgarg007 | 12f5cef | 2018-12-25 16:06:19 +0530 | [diff] [blame] | 162 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 163 | if (info.loyalty_points) { |
| 164 | $( |
| 165 | '<div class="badge-link small" style="margin-bottom:10px"><span class="indicator blue">' + |
| 166 | "Loyalty Points: " + |
| 167 | info.loyalty_points + |
| 168 | "</span></div>" |
| 169 | ).appendTo(indicator); |
deepeshgarg007 | 12f5cef | 2018-12-25 16:06:19 +0530 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | return indicator; |
| 173 | }, |
| 174 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 175 | get_party_name: function (party_type) { |
| 176 | var dict = { |
| 177 | Customer: "customer_name", |
| 178 | Supplier: "supplier_name", |
| 179 | Employee: "employee_name", |
| 180 | Member: "member_name", |
| 181 | }; |
Shreya Shah | 149f7ee | 2018-03-27 11:29:25 +0530 | [diff] [blame] | 182 | return dict[party_type]; |
| 183 | }, |
| 184 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 185 | copy_value_in_all_rows: function (doc, dt, dn, table_fieldname, fieldname) { |
Neil Trini Lasrado | fe2ffae | 2015-07-08 18:16:51 +0530 | [diff] [blame] | 186 | var d = locals[dt][dn]; |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 187 | if (d[fieldname]) { |
Neil Trini Lasrado | fe2ffae | 2015-07-08 18:16:51 +0530 | [diff] [blame] | 188 | var cl = doc[table_fieldname] || []; |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 189 | for (var i = 0; i < cl.length; i++) { |
| 190 | if (!cl[i][fieldname]) cl[i][fieldname] = d[fieldname]; |
Neil Trini Lasrado | fe2ffae | 2015-07-08 18:16:51 +0530 | [diff] [blame] | 191 | } |
| 192 | } |
| 193 | refresh_field(table_fieldname); |
Makarand Bauskar | 157c334 | 2017-05-26 21:32:33 +0530 | [diff] [blame] | 194 | }, |
| 195 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 196 | get_terms: function (tc_name, doc, callback) { |
| 197 | if (tc_name) { |
Makarand Bauskar | 157c334 | 2017-05-26 21:32:33 +0530 | [diff] [blame] | 198 | return frappe.call({ |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 199 | method: "erpnext.setup.doctype.terms_and_conditions.terms_and_conditions.get_terms_and_conditions", |
Makarand Bauskar | 157c334 | 2017-05-26 21:32:33 +0530 | [diff] [blame] | 200 | args: { |
| 201 | template_name: tc_name, |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 202 | doc: doc, |
Makarand Bauskar | 157c334 | 2017-05-26 21:32:33 +0530 | [diff] [blame] | 203 | }, |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 204 | callback: function (r) { |
| 205 | callback(r); |
| 206 | }, |
Makarand Bauskar | 157c334 | 2017-05-26 21:32:33 +0530 | [diff] [blame] | 207 | }); |
| 208 | } |
tundebabzy | 1a947db | 2017-08-29 13:48:27 +0100 | [diff] [blame] | 209 | }, |
| 210 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 211 | make_bank_account: function (doctype, docname) { |
rohitwaghchaure | 713cfc7 | 2018-09-11 17:40:37 +0530 | [diff] [blame] | 212 | frappe.call({ |
| 213 | method: "erpnext.accounts.doctype.bank_account.bank_account.make_bank_account", |
| 214 | args: { |
| 215 | doctype: doctype, |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 216 | docname: docname, |
rohitwaghchaure | 713cfc7 | 2018-09-11 17:40:37 +0530 | [diff] [blame] | 217 | }, |
| 218 | freeze: true, |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 219 | callback: function (r) { |
rohitwaghchaure | 713cfc7 | 2018-09-11 17:40:37 +0530 | [diff] [blame] | 220 | var doclist = frappe.model.sync(r.message); |
| 221 | frappe.set_route("Form", doclist[0].doctype, doclist[0].name); |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 222 | }, |
| 223 | }); |
rohitwaghchaure | 713cfc7 | 2018-09-11 17:40:37 +0530 | [diff] [blame] | 224 | }, |
| 225 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 226 | add_dimensions: function (report_name, index) { |
Deepesh Garg | 11ea0b1 | 2020-05-26 19:23:45 +0530 | [diff] [blame] | 227 | let filters = frappe.query_reports[report_name].filters; |
| 228 | |
Deepesh Garg | 7b2d518 | 2020-12-04 11:28:26 +0530 | [diff] [blame] | 229 | frappe.call({ |
| 230 | method: "erpnext.accounts.doctype.accounting_dimension.accounting_dimension.get_dimensions", |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 231 | callback: function (r) { |
Deepesh Garg | 7b2d518 | 2020-12-04 11:28:26 +0530 | [diff] [blame] | 232 | let accounting_dimensions = r.message[0]; |
| 233 | accounting_dimensions.forEach((dimension) => { |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 234 | let found = filters.some((el) => el.fieldname === dimension["fieldname"]); |
Deepesh Garg | 11ea0b1 | 2020-05-26 19:23:45 +0530 | [diff] [blame] | 235 | |
Deepesh Garg | 7b2d518 | 2020-12-04 11:28:26 +0530 | [diff] [blame] | 236 | if (!found) { |
Deepesh Garg | 23ab5c5 | 2020-12-31 11:29:06 +0530 | [diff] [blame] | 237 | filters.splice(index, 0, { |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 238 | fieldname: dimension["fieldname"], |
| 239 | label: __(dimension["label"]), |
| 240 | fieldtype: "MultiSelectList", |
| 241 | get_data: function (txt) { |
Rohit Waghchaure | 69be22b | 2022-05-14 17:19:34 +0530 | [diff] [blame] | 242 | return frappe.db.get_link_options(dimension["document_type"], txt); |
| 243 | }, |
Deepesh Garg | 7b2d518 | 2020-12-04 11:28:26 +0530 | [diff] [blame] | 244 | }); |
| 245 | } |
Deepesh Garg | 11ea0b1 | 2020-05-26 19:23:45 +0530 | [diff] [blame] | 246 | }); |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 247 | }, |
Deepesh Garg | 11ea0b1 | 2020-05-26 19:23:45 +0530 | [diff] [blame] | 248 | }); |
| 249 | }, |
| 250 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 251 | add_inventory_dimensions: function (report_name, index) { |
Rohit Waghchaure | dbec5cf | 2022-06-22 12:24:08 +0530 | [diff] [blame] | 252 | let filters = frappe.query_reports[report_name].filters; |
| 253 | |
| 254 | frappe.call({ |
| 255 | method: "erpnext.stock.doctype.inventory_dimension.inventory_dimension.get_inventory_dimensions", |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 256 | callback: function (r) { |
Rohit Waghchaure | dbec5cf | 2022-06-22 12:24:08 +0530 | [diff] [blame] | 257 | if (r.message && r.message.length) { |
| 258 | r.message.forEach((dimension) => { |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 259 | let existing_filter = filters.filter((el) => el.fieldname === dimension["fieldname"]); |
Rohit Waghchaure | dbec5cf | 2022-06-22 12:24:08 +0530 | [diff] [blame] | 260 | |
Rohit Waghchaure | 0e388ba | 2023-02-20 12:20:03 +0530 | [diff] [blame] | 261 | if (!existing_filter.length) { |
Rohit Waghchaure | dbec5cf | 2022-06-22 12:24:08 +0530 | [diff] [blame] | 262 | filters.splice(index, 0, { |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 263 | fieldname: dimension["fieldname"], |
| 264 | label: __(dimension["doctype"]), |
| 265 | fieldtype: "MultiSelectList", |
| 266 | get_data: function (txt) { |
Rohit Waghchaure | dbec5cf | 2022-06-22 12:24:08 +0530 | [diff] [blame] | 267 | return frappe.db.get_link_options(dimension["doctype"], txt); |
| 268 | }, |
| 269 | }); |
Rohit Waghchaure | 0e388ba | 2023-02-20 12:20:03 +0530 | [diff] [blame] | 270 | } else { |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 271 | existing_filter[0]["fieldtype"] = "MultiSelectList"; |
| 272 | existing_filter[0]["get_data"] = function (txt) { |
Rohit Waghchaure | 0e388ba | 2023-02-20 12:20:03 +0530 | [diff] [blame] | 273 | return frappe.db.get_link_options(dimension["doctype"], txt); |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 274 | }; |
Rohit Waghchaure | dbec5cf | 2022-06-22 12:24:08 +0530 | [diff] [blame] | 275 | } |
| 276 | }); |
| 277 | } |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 278 | }, |
Rohit Waghchaure | dbec5cf | 2022-06-22 12:24:08 +0530 | [diff] [blame] | 279 | }); |
| 280 | }, |
| 281 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 282 | make_subscription: function (doctype, docname) { |
rohitwaghchaure | 166b78f | 2017-09-07 16:14:22 +0530 | [diff] [blame] | 283 | frappe.call({ |
Rucha Mahabal | 65a627c | 2019-07-17 13:50:32 +0530 | [diff] [blame] | 284 | method: "frappe.automation.doctype.auto_repeat.auto_repeat.make_auto_repeat", |
rohitwaghchaure | 166b78f | 2017-09-07 16:14:22 +0530 | [diff] [blame] | 285 | args: { |
| 286 | doctype: doctype, |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 287 | docname: docname, |
rohitwaghchaure | 166b78f | 2017-09-07 16:14:22 +0530 | [diff] [blame] | 288 | }, |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 289 | callback: function (r) { |
rohitwaghchaure | 166b78f | 2017-09-07 16:14:22 +0530 | [diff] [blame] | 290 | var doclist = frappe.model.sync(r.message); |
| 291 | frappe.set_route("Form", doclist[0].doctype, doclist[0].name); |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 292 | }, |
| 293 | }); |
rohitwaghchaure | 166b78f | 2017-09-07 16:14:22 +0530 | [diff] [blame] | 294 | }, |
| 295 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 296 | make_pricing_rule: function (doctype, docname) { |
Saif | 90cf2dd | 2018-09-30 21:46:31 +0500 | [diff] [blame] | 297 | frappe.call({ |
| 298 | method: "erpnext.accounts.doctype.pricing_rule.pricing_rule.make_pricing_rule", |
| 299 | args: { |
| 300 | doctype: doctype, |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 301 | docname: docname, |
Saif | 90cf2dd | 2018-09-30 21:46:31 +0500 | [diff] [blame] | 302 | }, |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 303 | callback: function (r) { |
Saif | 90cf2dd | 2018-09-30 21:46:31 +0500 | [diff] [blame] | 304 | var doclist = frappe.model.sync(r.message); |
| 305 | frappe.set_route("Form", doclist[0].doctype, doclist[0].name); |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 306 | }, |
| 307 | }); |
Saif | 90cf2dd | 2018-09-30 21:46:31 +0500 | [diff] [blame] | 308 | }, |
| 309 | |
tundebabzy | 1a947db | 2017-08-29 13:48:27 +0100 | [diff] [blame] | 310 | /** |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 311 | * Checks if the first row of a given child table is empty |
| 312 | * @param child_table - Child table Doctype |
| 313 | * @return {Boolean} |
| 314 | **/ |
| 315 | first_row_is_empty: function (child_table) { |
| 316 | if ($.isArray(child_table) && child_table.length > 0) { |
tundebabzy | 1a947db | 2017-08-29 13:48:27 +0100 | [diff] [blame] | 317 | return !child_table[0].item_code; |
| 318 | } |
| 319 | return false; |
| 320 | }, |
| 321 | |
| 322 | /** |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 323 | * Removes the first row of a child table if it is empty |
| 324 | * @param {_Frm} frm - The current form |
| 325 | * @param {String} child_table_name - The child table field name |
| 326 | * @return {Boolean} |
| 327 | **/ |
| 328 | remove_empty_first_row: function (frm, child_table_name) { |
| 329 | const rows = frm["doc"][child_table_name]; |
| 330 | if (this.first_row_is_empty(rows)) { |
| 331 | frm["doc"][child_table_name] = rows.splice(1); |
tundebabzy | 1a947db | 2017-08-29 13:48:27 +0100 | [diff] [blame] | 332 | } |
| 333 | return rows; |
| 334 | }, |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 335 | get_tree_options: function (option) { |
Zarrar | 6ffdf94 | 2018-06-14 12:24:16 +0530 | [diff] [blame] | 336 | // get valid options for tree based on user permission & locals dict |
| 337 | let unscrub_option = frappe.model.unscrub(option); |
| 338 | let user_permission = frappe.defaults.get_user_permissions(); |
deepeshgarg007 | 0d64d62 | 2019-02-20 17:55:14 +0530 | [diff] [blame] | 339 | let options; |
| 340 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 341 | if (user_permission && user_permission[unscrub_option]) { |
| 342 | options = user_permission[unscrub_option].map((perm) => perm.doc); |
Zarrar | 6ffdf94 | 2018-06-14 12:24:16 +0530 | [diff] [blame] | 343 | } else { |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 344 | options = $.map(locals[`:${unscrub_option}`], function (c) { |
| 345 | return c.name; |
| 346 | }).sort(); |
Zarrar | 6ffdf94 | 2018-06-14 12:24:16 +0530 | [diff] [blame] | 347 | } |
deepeshgarg007 | 0d64d62 | 2019-02-20 17:55:14 +0530 | [diff] [blame] | 348 | |
| 349 | // filter unique values, as there may be multiple user permissions for any value |
| 350 | return options.filter((value, index, self) => self.indexOf(value) === index); |
Zarrar | 6ffdf94 | 2018-06-14 12:24:16 +0530 | [diff] [blame] | 351 | }, |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 352 | get_tree_default: function (option) { |
Zarrar | 6ffdf94 | 2018-06-14 12:24:16 +0530 | [diff] [blame] | 353 | // set default for a field based on user permission |
| 354 | let options = this.get_tree_options(option); |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 355 | if (options.includes(frappe.defaults.get_default(option))) { |
Zarrar | 6ffdf94 | 2018-06-14 12:24:16 +0530 | [diff] [blame] | 356 | return frappe.defaults.get_default(option); |
| 357 | } else { |
| 358 | return options[0]; |
| 359 | } |
Sanjay Kumar | 1b49f3a | 2018-09-06 13:09:35 +0400 | [diff] [blame] | 360 | }, |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 361 | overrides_parent_value_in_all_rows: function (doc, dt, dn, table_fieldname, fieldname, parent_fieldname) { |
Marica | 24e4516 | 2021-04-14 18:53:15 +0530 | [diff] [blame] | 362 | if (doc[parent_fieldname]) { |
Andy Zhu | bffe933 | 2021-04-12 22:49:26 +1200 | [diff] [blame] | 363 | let cl = doc[table_fieldname] || []; |
Marica | 24e4516 | 2021-04-14 18:53:15 +0530 | [diff] [blame] | 364 | for (let i = 0; i < cl.length; i++) { |
Sanjay Kumar | 1b49f3a | 2018-09-06 13:09:35 +0400 | [diff] [blame] | 365 | cl[i][fieldname] = doc[parent_fieldname]; |
| 366 | } |
Andy Zhu | bffe933 | 2021-04-12 22:49:26 +1200 | [diff] [blame] | 367 | frappe.refresh_field(table_fieldname); |
Sanjay Kumar | 1b49f3a | 2018-09-06 13:09:35 +0400 | [diff] [blame] | 368 | } |
Sanjay Kumar | 1b49f3a | 2018-09-06 13:09:35 +0400 | [diff] [blame] | 369 | }, |
Nabin Hait | 34c551d | 2019-07-03 10:34:31 +0530 | [diff] [blame] | 370 | create_new_doc: function (doctype, update_fields) { |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 371 | frappe.model.with_doctype(doctype, function () { |
Nabin Hait | 34c551d | 2019-07-03 10:34:31 +0530 | [diff] [blame] | 372 | var new_doc = frappe.model.get_new_doc(doctype); |
| 373 | for (let [key, value] of Object.entries(update_fields)) { |
| 374 | new_doc[key] = value; |
| 375 | } |
| 376 | frappe.ui.form.make_quick_entry(doctype, null, null, new_doc); |
| 377 | }); |
Ankush Menat | 0b86b1b | 2022-12-08 16:40:13 +0530 | [diff] [blame] | 378 | }, |
Nabin Hait | 34c551d | 2019-07-03 10:34:31 +0530 | [diff] [blame] | 379 | |
Ankush Menat | 0b86b1b | 2022-12-08 16:40:13 +0530 | [diff] [blame] | 380 | // check if payments app is installed on site, if not warn user. |
| 381 | check_payments_app: () => { |
| 382 | if (frappe.boot.versions && !frappe.boot.versions.payments) { |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 383 | const marketplace_link = |
| 384 | '<a href="https://frappecloud.com/marketplace/apps/payments">Marketplace</a>'; |
| 385 | const github_link = '<a href="https://github.com/frappe/payments/">GitHub</a>'; |
| 386 | const msg = __("payments app is not installed. Please install it from {0} or {1}", [ |
| 387 | marketplace_link, |
| 388 | github_link, |
| 389 | ]); |
Ankush Menat | 0b86b1b | 2022-12-08 16:40:13 +0530 | [diff] [blame] | 390 | frappe.msgprint(msg); |
| 391 | } |
Ankush Menat | 0b86b1b | 2022-12-08 16:40:13 +0530 | [diff] [blame] | 392 | }, |
Rohit Waghchaure | 1c2fe08 | 2023-06-15 12:54:43 +0530 | [diff] [blame] | 393 | |
| 394 | pick_serial_and_batch_bundle(frm, cdt, cdn, type_of_transaction, warehouse_field) { |
| 395 | let item_row = frappe.get_doc(cdt, cdn); |
| 396 | item_row.type_of_transaction = type_of_transaction; |
| 397 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 398 | frappe.db.get_value("Item", item_row.item_code, ["has_batch_no", "has_serial_no"]).then((r) => { |
| 399 | item_row.has_batch_no = r.message.has_batch_no; |
| 400 | item_row.has_serial_no = r.message.has_serial_no; |
Rohit Waghchaure | 1c2fe08 | 2023-06-15 12:54:43 +0530 | [diff] [blame] | 401 | |
Rohit Waghchaure | 0d9d42a | 2024-03-27 11:52:06 +0530 | [diff] [blame] | 402 | new erpnext.SerialBatchPackageSelector(frm, item_row, (r) => { |
| 403 | if (r) { |
| 404 | let update_values = { |
| 405 | serial_and_batch_bundle: r.name, |
| 406 | qty: Math.abs(r.total_qty), |
| 407 | }; |
Rohit Waghchaure | 1c2fe08 | 2023-06-15 12:54:43 +0530 | [diff] [blame] | 408 | |
Rohit Waghchaure | 0d9d42a | 2024-03-27 11:52:06 +0530 | [diff] [blame] | 409 | if (!warehouse_field) { |
| 410 | warehouse_field = "warehouse"; |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 411 | } |
Rohit Waghchaure | 0d9d42a | 2024-03-27 11:52:06 +0530 | [diff] [blame] | 412 | |
| 413 | if (r.warehouse) { |
| 414 | update_values[warehouse_field] = r.warehouse; |
| 415 | } |
| 416 | |
| 417 | frappe.model.set_value(item_row.doctype, item_row.name, update_values); |
| 418 | } |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 419 | }); |
Rohit Waghchaure | 1c2fe08 | 2023-06-15 12:54:43 +0530 | [diff] [blame] | 420 | }); |
Deepesh Garg | 6270607 | 2023-07-16 12:58:42 +0530 | [diff] [blame] | 421 | }, |
| 422 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 423 | get_fiscal_year: function (date, with_dates = false, boolean = false) { |
Corentin Flr | c203faf | 2024-04-09 14:59:58 +0200 | [diff] [blame] | 424 | if (!frappe.boot.setup_complete) { |
| 425 | return; |
| 426 | } |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 427 | if (!date) { |
Deepesh Garg | 3759a41 | 2023-07-19 13:17:12 +0530 | [diff] [blame] | 428 | date = frappe.datetime.get_today(); |
| 429 | } |
| 430 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 431 | let fiscal_year = ""; |
Deepesh Garg | 6270607 | 2023-07-16 12:58:42 +0530 | [diff] [blame] | 432 | frappe.call({ |
| 433 | method: "erpnext.accounts.utils.get_fiscal_year", |
| 434 | args: { |
ruthra kumar | c31ee8e | 2023-11-14 06:44:49 +0530 | [diff] [blame] | 435 | date: date, |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 436 | boolean: boolean, |
Deepesh Garg | 6270607 | 2023-07-16 12:58:42 +0530 | [diff] [blame] | 437 | }, |
| 438 | async: false, |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 439 | callback: function (r) { |
Deepesh Garg | 6270607 | 2023-07-16 12:58:42 +0530 | [diff] [blame] | 440 | if (r.message) { |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 441 | if (with_dates) fiscal_year = r.message; |
| 442 | else fiscal_year = r.message[0]; |
Deepesh Garg | 6270607 | 2023-07-16 12:58:42 +0530 | [diff] [blame] | 443 | } |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 444 | }, |
Deepesh Garg | 6270607 | 2023-07-16 12:58:42 +0530 | [diff] [blame] | 445 | }); |
| 446 | return fiscal_year; |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 447 | }, |
Rushabh Mehta | 95b995b | 2015-05-28 12:10:55 +0530 | [diff] [blame] | 448 | }); |
| 449 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 450 | erpnext.utils.select_alternate_items = function (opts) { |
rohitwaghchaure | a3c3dec | 2018-03-28 11:51:44 +0530 | [diff] [blame] | 451 | const frm = opts.frm; |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 452 | const warehouse_field = opts.warehouse_field || "warehouse"; |
| 453 | const item_field = opts.item_field || "item_code"; |
rohitwaghchaure | a3c3dec | 2018-03-28 11:51:44 +0530 | [diff] [blame] | 454 | |
| 455 | this.data = []; |
| 456 | const dialog = new frappe.ui.Dialog({ |
| 457 | title: __("Select Alternate Item"), |
| 458 | fields: [ |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 459 | { fieldtype: "Section Break", label: __("Items") }, |
rohitwaghchaure | a3c3dec | 2018-03-28 11:51:44 +0530 | [diff] [blame] | 460 | { |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 461 | fieldname: "alternative_items", |
| 462 | fieldtype: "Table", |
| 463 | cannot_add_rows: true, |
| 464 | in_place_edit: true, |
| 465 | data: this.data, |
rohitwaghchaure | a3c3dec | 2018-03-28 11:51:44 +0530 | [diff] [blame] | 466 | get_data: () => { |
| 467 | return this.data; |
| 468 | }, |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 469 | fields: [ |
| 470 | { |
| 471 | fieldtype: "Data", |
| 472 | fieldname: "docname", |
| 473 | hidden: 1, |
rohitwaghchaure | a3c3dec | 2018-03-28 11:51:44 +0530 | [diff] [blame] | 474 | }, |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 475 | { |
| 476 | fieldtype: "Link", |
| 477 | fieldname: "item_code", |
| 478 | options: "Item", |
| 479 | in_list_view: 1, |
| 480 | read_only: 1, |
| 481 | label: __("Item Code"), |
| 482 | }, |
| 483 | { |
| 484 | fieldtype: "Link", |
| 485 | fieldname: "alternate_item", |
| 486 | options: "Item", |
| 487 | default: "", |
| 488 | in_list_view: 1, |
| 489 | label: __("Alternate Item"), |
| 490 | onchange: function () { |
| 491 | const item_code = this.get_value(); |
| 492 | const warehouse = this.grid_row.on_grid_fields_dict.warehouse.get_value(); |
| 493 | if (item_code && warehouse) { |
| 494 | frappe.call({ |
| 495 | method: "erpnext.stock.utils.get_latest_stock_qty", |
| 496 | args: { |
| 497 | item_code: item_code, |
| 498 | warehouse: warehouse, |
| 499 | }, |
| 500 | callback: (r) => { |
| 501 | this.grid_row.on_grid_fields_dict.actual_qty.set_value( |
| 502 | r.message || 0 |
| 503 | ); |
| 504 | }, |
| 505 | }); |
rohitwaghchaure | a3c3dec | 2018-03-28 11:51:44 +0530 | [diff] [blame] | 506 | } |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 507 | }, |
| 508 | get_query: (e) => { |
| 509 | return { |
| 510 | query: "erpnext.stock.doctype.item_alternative.item_alternative.get_alternative_items", |
| 511 | filters: { |
| 512 | item_code: e.item_code, |
rohitwaghchaure | a3c3dec | 2018-03-28 11:51:44 +0530 | [diff] [blame] | 513 | }, |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 514 | }; |
| 515 | }, |
rohitwaghchaure | a3c3dec | 2018-03-28 11:51:44 +0530 | [diff] [blame] | 516 | }, |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 517 | { |
| 518 | fieldtype: "Link", |
| 519 | fieldname: "warehouse", |
| 520 | options: "Warehouse", |
| 521 | default: "", |
| 522 | in_list_view: 1, |
| 523 | label: __("Warehouse"), |
| 524 | onchange: function () { |
| 525 | const warehouse = this.get_value(); |
| 526 | const item_code = this.grid_row.on_grid_fields_dict.item_code.get_value(); |
| 527 | if (item_code && warehouse) { |
| 528 | frappe.call({ |
| 529 | method: "erpnext.stock.utils.get_latest_stock_qty", |
| 530 | args: { |
| 531 | item_code: item_code, |
| 532 | warehouse: warehouse, |
| 533 | }, |
| 534 | callback: (r) => { |
| 535 | this.grid_row.on_grid_fields_dict.actual_qty.set_value( |
| 536 | r.message || 0 |
| 537 | ); |
| 538 | }, |
| 539 | }); |
| 540 | } |
| 541 | }, |
| 542 | }, |
| 543 | { |
| 544 | fieldtype: "Float", |
| 545 | fieldname: "actual_qty", |
| 546 | default: 0, |
| 547 | read_only: 1, |
| 548 | in_list_view: 1, |
| 549 | label: __("Available Qty"), |
| 550 | }, |
| 551 | ], |
rohitwaghchaure | a3c3dec | 2018-03-28 11:51:44 +0530 | [diff] [blame] | 552 | }, |
| 553 | ], |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 554 | primary_action: function () { |
rohitwaghchaure | a3c3dec | 2018-03-28 11:51:44 +0530 | [diff] [blame] | 555 | const args = this.get_values()["alternative_items"]; |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 556 | const alternative_items = args.filter((d) => { |
rohitwaghchaure | a3c3dec | 2018-03-28 11:51:44 +0530 | [diff] [blame] | 557 | if (d.alternate_item && d.item_code != d.alternate_item) { |
| 558 | return true; |
| 559 | } |
| 560 | }); |
| 561 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 562 | alternative_items.forEach((d) => { |
rohitwaghchaure | a3c3dec | 2018-03-28 11:51:44 +0530 | [diff] [blame] | 563 | let row = frappe.get_doc(opts.child_doctype, d.docname); |
Doridel Cahanap | e42192b | 2018-05-16 13:28:39 +0800 | [diff] [blame] | 564 | let qty = null; |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 565 | if (row.doctype === "Work Order Item") { |
Doridel Cahanap | e42192b | 2018-05-16 13:28:39 +0800 | [diff] [blame] | 566 | qty = row.required_qty; |
| 567 | } else { |
| 568 | qty = row.qty; |
| 569 | } |
rohitwaghchaure | a3c3dec | 2018-03-28 11:51:44 +0530 | [diff] [blame] | 570 | row[item_field] = d.alternate_item; |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 571 | frappe.model.set_value(row.doctype, row.name, "qty", qty); |
mergify[bot] | c1a0f64 | 2021-12-17 19:06:19 +0530 | [diff] [blame] | 572 | frappe.model.set_value(row.doctype, row.name, opts.original_item_field, d.item_code); |
| 573 | frm.trigger(item_field, row.doctype, row.name); |
rohitwaghchaure | a3c3dec | 2018-03-28 11:51:44 +0530 | [diff] [blame] | 574 | }); |
| 575 | |
| 576 | refresh_field(opts.child_docname); |
| 577 | this.hide(); |
| 578 | }, |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 579 | primary_action_label: __("Update"), |
rohitwaghchaure | a3c3dec | 2018-03-28 11:51:44 +0530 | [diff] [blame] | 580 | }); |
| 581 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 582 | frm.doc[opts.child_docname].forEach((d) => { |
rohitwaghchaure | a3c3dec | 2018-03-28 11:51:44 +0530 | [diff] [blame] | 583 | if (!opts.condition || opts.condition(d)) { |
| 584 | dialog.fields_dict.alternative_items.df.data.push({ |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 585 | docname: d.name, |
| 586 | item_code: d[item_field], |
| 587 | warehouse: d[warehouse_field], |
| 588 | actual_qty: d.actual_qty, |
rohitwaghchaure | a3c3dec | 2018-03-28 11:51:44 +0530 | [diff] [blame] | 589 | }); |
| 590 | } |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 591 | }); |
rohitwaghchaure | a3c3dec | 2018-03-28 11:51:44 +0530 | [diff] [blame] | 592 | |
| 593 | this.data = dialog.fields_dict.alternative_items.df.data; |
| 594 | dialog.fields_dict.alternative_items.grid.refresh(); |
| 595 | dialog.show(); |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 596 | }; |
rohitwaghchaure | a3c3dec | 2018-03-28 11:51:44 +0530 | [diff] [blame] | 597 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 598 | erpnext.utils.update_child_items = function (opts) { |
Doridel Cahanap | 6f06cc2 | 2018-05-17 16:28:58 +0800 | [diff] [blame] | 599 | const frm = opts.frm; |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 600 | const cannot_add_row = typeof opts.cannot_add_row === "undefined" ? true : opts.cannot_add_row; |
| 601 | const child_docname = typeof opts.cannot_add_row === "undefined" ? "items" : opts.child_docname; |
Saqib | 56fea7d | 2020-10-09 21:19:25 +0530 | [diff] [blame] | 602 | const child_meta = frappe.get_meta(`${frm.doc.doctype} Item`); |
s-aga-r | 2d8363a | 2023-09-02 11:02:24 +0530 | [diff] [blame] | 603 | const has_reserved_stock = opts.has_reserved_stock ? true : false; |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 604 | const get_precision = (fieldname) => child_meta.fields.find((f) => f.fieldname == fieldname).precision; |
Saqib | 56fea7d | 2020-10-09 21:19:25 +0530 | [diff] [blame] | 605 | |
Devin Slauenwhite | a835c1a | 2023-01-26 16:53:05 -0500 | [diff] [blame] | 606 | this.data = frm.doc[opts.child_docname].map((d) => { |
| 607 | return { |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 608 | docname: d.name, |
| 609 | name: d.name, |
| 610 | item_code: d.item_code, |
| 611 | delivery_date: d.delivery_date, |
| 612 | schedule_date: d.schedule_date, |
| 613 | conversion_factor: d.conversion_factor, |
| 614 | qty: d.qty, |
| 615 | rate: d.rate, |
| 616 | uom: d.uom, |
| 617 | fg_item: d.fg_item, |
| 618 | fg_item_qty: d.fg_item_qty, |
| 619 | }; |
Devin Slauenwhite | a835c1a | 2023-01-26 16:53:05 -0500 | [diff] [blame] | 620 | }); |
| 621 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 622 | const fields = [ |
| 623 | { |
| 624 | fieldtype: "Data", |
| 625 | fieldname: "docname", |
| 626 | read_only: 1, |
| 627 | hidden: 1, |
| 628 | }, |
| 629 | { |
| 630 | fieldtype: "Link", |
| 631 | fieldname: "item_code", |
| 632 | options: "Item", |
Saqib Ansari | f53299e | 2020-04-15 22:08:12 +0530 | [diff] [blame] | 633 | in_list_view: 1, |
s-aga-r | faf9f13 | 2023-08-21 15:51:57 +0530 | [diff] [blame] | 634 | read_only: 0, |
| 635 | disabled: 0, |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 636 | label: __("Item Code"), |
| 637 | get_query: function () { |
| 638 | let filters; |
| 639 | if (frm.doc.doctype == "Sales Order") { |
| 640 | filters = { is_sales_item: 1 }; |
| 641 | } else if (frm.doc.doctype == "Purchase Order") { |
| 642 | if (frm.doc.is_subcontracted) { |
| 643 | if (frm.doc.is_old_subcontracting_flow) { |
| 644 | filters = { is_sub_contracted_item: 1 }; |
| 645 | } else { |
| 646 | filters = { is_stock_item: 0 }; |
| 647 | } |
| 648 | } else { |
| 649 | filters = { is_purchase_item: 1 }; |
s-aga-r | faf9f13 | 2023-08-21 15:51:57 +0530 | [diff] [blame] | 650 | } |
| 651 | } |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 652 | return { |
| 653 | query: "erpnext.controllers.queries.item_query", |
| 654 | filters: filters, |
| 655 | }; |
s-aga-r | faf9f13 | 2023-08-21 15:51:57 +0530 | [diff] [blame] | 656 | }, |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 657 | }, |
| 658 | { |
| 659 | fieldtype: "Link", |
| 660 | fieldname: "uom", |
| 661 | options: "UOM", |
| 662 | read_only: 0, |
| 663 | label: __("UOM"), |
s-aga-r | faf9f13 | 2023-08-21 15:51:57 +0530 | [diff] [blame] | 664 | reqd: 1, |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 665 | onchange: function () { |
| 666 | frappe.call({ |
| 667 | method: "erpnext.stock.get_item_details.get_conversion_factor", |
| 668 | args: { item_code: this.doc.item_code, uom: this.value }, |
| 669 | callback: (r) => { |
| 670 | if (!r.exc) { |
| 671 | if (this.doc.conversion_factor == r.message.conversion_factor) return; |
| 672 | |
| 673 | const docname = this.doc.docname; |
| 674 | dialog.fields_dict.trans_items.df.data.some((doc) => { |
| 675 | if (doc.docname == docname) { |
| 676 | doc.conversion_factor = r.message.conversion_factor; |
| 677 | dialog.fields_dict.trans_items.grid.refresh(); |
| 678 | return true; |
| 679 | } |
| 680 | }); |
| 681 | } |
| 682 | }, |
| 683 | }); |
| 684 | }, |
| 685 | }, |
| 686 | { |
| 687 | fieldtype: "Float", |
| 688 | fieldname: "qty", |
s-aga-r | faf9f13 | 2023-08-21 15:51:57 +0530 | [diff] [blame] | 689 | default: 0, |
| 690 | read_only: 0, |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 691 | in_list_view: 1, |
| 692 | label: __("Qty"), |
| 693 | precision: get_precision("qty"), |
| 694 | }, |
| 695 | { |
| 696 | fieldtype: "Currency", |
| 697 | fieldname: "rate", |
| 698 | options: "currency", |
| 699 | default: 0, |
| 700 | read_only: 0, |
| 701 | in_list_view: 1, |
| 702 | label: __("Rate"), |
| 703 | precision: get_precision("rate"), |
| 704 | }, |
| 705 | ]; |
| 706 | |
| 707 | if (frm.doc.doctype == "Sales Order" || frm.doc.doctype == "Purchase Order") { |
| 708 | fields.splice(2, 0, { |
| 709 | fieldtype: "Date", |
| 710 | fieldname: frm.doc.doctype == "Sales Order" ? "delivery_date" : "schedule_date", |
| 711 | in_list_view: 1, |
| 712 | label: frm.doc.doctype == "Sales Order" ? __("Delivery Date") : __("Reqd by date"), |
| 713 | default: frm.doc.doctype == "Sales Order" ? frm.doc.delivery_date : frm.doc.schedule_date, |
| 714 | reqd: 1, |
| 715 | }); |
| 716 | fields.splice(3, 0, { |
| 717 | fieldtype: "Float", |
| 718 | fieldname: "conversion_factor", |
| 719 | label: __("Conversion Factor"), |
| 720 | precision: get_precision("conversion_factor"), |
| 721 | }); |
| 722 | } |
| 723 | |
| 724 | if ( |
| 725 | frm.doc.doctype == "Purchase Order" && |
| 726 | frm.doc.is_subcontracted && |
| 727 | !frm.doc.is_old_subcontracting_flow |
| 728 | ) { |
| 729 | fields.push( |
| 730 | { |
| 731 | fieldtype: "Link", |
| 732 | fieldname: "fg_item", |
| 733 | options: "Item", |
| 734 | reqd: 1, |
| 735 | in_list_view: 0, |
| 736 | read_only: 0, |
| 737 | disabled: 0, |
| 738 | label: __("Finished Good Item"), |
| 739 | get_query: () => { |
| 740 | return { |
| 741 | filters: { |
| 742 | is_stock_item: 1, |
| 743 | is_sub_contracted_item: 1, |
| 744 | default_bom: ["!=", ""], |
| 745 | }, |
| 746 | }; |
| 747 | }, |
| 748 | }, |
| 749 | { |
| 750 | fieldtype: "Float", |
| 751 | fieldname: "fg_item_qty", |
| 752 | reqd: 1, |
| 753 | default: 0, |
| 754 | read_only: 0, |
| 755 | in_list_view: 0, |
| 756 | label: __("Finished Good Item Qty"), |
| 757 | precision: get_precision("fg_item_qty"), |
| 758 | } |
| 759 | ); |
s-aga-r | faf9f13 | 2023-08-21 15:51:57 +0530 | [diff] [blame] | 760 | } |
| 761 | |
Deepesh Garg | 4077254 | 2023-07-22 23:07:18 +0530 | [diff] [blame] | 762 | let dialog = new frappe.ui.Dialog({ |
Doridel Cahanap | 6f06cc2 | 2018-05-17 16:28:58 +0800 | [diff] [blame] | 763 | title: __("Update Items"), |
Raffael Meyer | d5fe143 | 2023-07-14 08:57:35 +0200 | [diff] [blame] | 764 | size: "extra-large", |
Doridel Cahanap | 6f06cc2 | 2018-05-17 16:28:58 +0800 | [diff] [blame] | 765 | fields: [ |
Doridel Cahanap | 6f06cc2 | 2018-05-17 16:28:58 +0800 | [diff] [blame] | 766 | { |
Stavros Anastasiadis | 3d82b74 | 2018-12-10 13:00:55 +0100 | [diff] [blame] | 767 | fieldname: "trans_items", |
| 768 | fieldtype: "Table", |
Marica | fc96c1a | 2020-03-06 10:57:59 +0530 | [diff] [blame] | 769 | label: "Items", |
Stavros Anastasiadis | 3d82b74 | 2018-12-10 13:00:55 +0100 | [diff] [blame] | 770 | cannot_add_rows: cannot_add_row, |
Saqib | bc919e2 | 2020-11-05 17:38:35 +0530 | [diff] [blame] | 771 | in_place_edit: false, |
Marica | fc96c1a | 2020-03-06 10:57:59 +0530 | [diff] [blame] | 772 | reqd: 1, |
Stavros Anastasiadis | 3d82b74 | 2018-12-10 13:00:55 +0100 | [diff] [blame] | 773 | data: this.data, |
Doridel Cahanap | 6f06cc2 | 2018-05-17 16:28:58 +0800 | [diff] [blame] | 774 | get_data: () => { |
| 775 | return this.data; |
| 776 | }, |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 777 | fields: fields, |
Doridel Cahanap | 6f06cc2 | 2018-05-17 16:28:58 +0800 | [diff] [blame] | 778 | }, |
| 779 | ], |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 780 | primary_action: function () { |
s-aga-r | 2d8363a | 2023-09-02 11:02:24 +0530 | [diff] [blame] | 781 | if (frm.doctype == "Sales Order" && has_reserved_stock) { |
| 782 | this.hide(); |
| 783 | frappe.confirm( |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 784 | __( |
| 785 | "The reserved stock will be released when you update items. Are you certain you wish to proceed?" |
| 786 | ), |
| 787 | () => this.update_items() |
| 788 | ); |
s-aga-r | 2d8363a | 2023-09-02 11:02:24 +0530 | [diff] [blame] | 789 | } else { |
| 790 | this.update_items(); |
| 791 | } |
| 792 | }, |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 793 | update_items: function () { |
Ankush Menat | 6de7b8e | 2021-08-24 12:18:40 +0530 | [diff] [blame] | 794 | const trans_items = this.get_values()["trans_items"].filter((item) => !!item.item_code); |
Doridel Cahanap | 6f06cc2 | 2018-05-17 16:28:58 +0800 | [diff] [blame] | 795 | frappe.call({ |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 796 | method: "erpnext.controllers.accounts_controller.update_child_qty_rate", |
Stavros Anastasiadis | 3d82b74 | 2018-12-10 13:00:55 +0100 | [diff] [blame] | 797 | freeze: true, |
Doridel Cahanap | 6f06cc2 | 2018-05-17 16:28:58 +0800 | [diff] [blame] | 798 | args: { |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 799 | parent_doctype: frm.doc.doctype, |
| 800 | trans_items: trans_items, |
| 801 | parent_doctype_name: frm.doc.name, |
| 802 | child_docname: child_docname, |
Doridel Cahanap | 6f06cc2 | 2018-05-17 16:28:58 +0800 | [diff] [blame] | 803 | }, |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 804 | callback: function () { |
Doridel Cahanap | 6f06cc2 | 2018-05-17 16:28:58 +0800 | [diff] [blame] | 805 | frm.reload_doc(); |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 806 | }, |
Doridel Cahanap | 6f06cc2 | 2018-05-17 16:28:58 +0800 | [diff] [blame] | 807 | }); |
| 808 | this.hide(); |
| 809 | refresh_field("items"); |
| 810 | }, |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 811 | primary_action_label: __("Update"), |
| 812 | }); |
Deepesh Garg | 4077254 | 2023-07-22 23:07:18 +0530 | [diff] [blame] | 813 | |
| 814 | dialog.show(); |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 815 | }; |
Doridel Cahanap | 6f06cc2 | 2018-05-17 16:28:58 +0800 | [diff] [blame] | 816 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 817 | erpnext.utils.map_current_doc = function (opts) { |
Sagar Vora | 78777d6 | 2021-03-09 20:35:08 +0530 | [diff] [blame] | 818 | function _map() { |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 819 | if ($.isArray(cur_frm.doc.items) && cur_frm.doc.items.length > 0) { |
Prateeksha Singh | edeb4dc | 2017-05-15 11:32:06 +0530 | [diff] [blame] | 820 | // remove first item row if empty |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 821 | if (!cur_frm.doc.items[0].item_code) { |
Rushabh Mehta | 176b63b | 2016-07-14 17:43:48 +0530 | [diff] [blame] | 822 | cur_frm.doc.items = cur_frm.doc.items.splice(1); |
| 823 | } |
bhupen | 3c7e70f | 2016-11-30 14:32:11 +0530 | [diff] [blame] | 824 | |
| 825 | // find the doctype of the items table |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 826 | var items_doctype = frappe.meta.get_docfield(cur_frm.doctype, "items").options; |
Prateeksha Singh | edeb4dc | 2017-05-15 11:32:06 +0530 | [diff] [blame] | 827 | |
bhupen | 3c7e70f | 2016-11-30 14:32:11 +0530 | [diff] [blame] | 828 | // find the link fieldname from items table for the given |
| 829 | // source_doctype |
| 830 | var link_fieldname = null; |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 831 | frappe.get_meta(items_doctype).fields.forEach(function (d) { |
| 832 | if (d.options === opts.source_doctype) link_fieldname = d.fieldname; |
| 833 | }); |
bhupen | 3c7e70f | 2016-11-30 14:32:11 +0530 | [diff] [blame] | 834 | |
Nabin Hait | 802b435 | 2017-01-09 15:32:20 +0530 | [diff] [blame] | 835 | // search in existing items if the source_name is already set and full qty fetched |
bhupen | 3c7e70f | 2016-11-30 14:32:11 +0530 | [diff] [blame] | 836 | var already_set = false; |
Nabin Hait | 802b435 | 2017-01-09 15:32:20 +0530 | [diff] [blame] | 837 | var item_qty_map = {}; |
bhupen | 3c7e70f | 2016-11-30 14:32:11 +0530 | [diff] [blame] | 838 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 839 | $.each(cur_frm.doc.items, function (i, d) { |
| 840 | opts.source_name.forEach(function (src) { |
| 841 | if (d[link_fieldname] == src) { |
Prateeksha Singh | edeb4dc | 2017-05-15 11:32:06 +0530 | [diff] [blame] | 842 | already_set = true; |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 843 | if (item_qty_map[d.item_code]) item_qty_map[d.item_code] += flt(d.qty); |
| 844 | else item_qty_map[d.item_code] = flt(d.qty); |
Prateeksha Singh | edeb4dc | 2017-05-15 11:32:06 +0530 | [diff] [blame] | 845 | } |
| 846 | }); |
| 847 | }); |
| 848 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 849 | if (already_set) { |
| 850 | opts.source_name.forEach(function (src) { |
| 851 | frappe.model.with_doc(opts.source_doctype, src, function (r) { |
Prateeksha Singh | edeb4dc | 2017-05-15 11:32:06 +0530 | [diff] [blame] | 852 | var source_doc = frappe.model.get_doc(opts.source_doctype, src); |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 853 | $.each(source_doc.items || [], function (i, row) { |
| 854 | if (row.qty > flt(item_qty_map[row.item_code])) { |
Prateeksha Singh | edeb4dc | 2017-05-15 11:32:06 +0530 | [diff] [blame] | 855 | already_set = false; |
| 856 | return false; |
| 857 | } |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 858 | }); |
| 859 | }); |
Prateeksha Singh | edeb4dc | 2017-05-15 11:32:06 +0530 | [diff] [blame] | 860 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 861 | if (already_set) { |
| 862 | frappe.msgprint( |
| 863 | __("You have already selected items from {0} {1}", [opts.source_doctype, src]) |
| 864 | ); |
Prateeksha Singh | edeb4dc | 2017-05-15 11:32:06 +0530 | [diff] [blame] | 865 | return; |
| 866 | } |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 867 | }); |
Nabin Hait | 802b435 | 2017-01-09 15:32:20 +0530 | [diff] [blame] | 868 | } |
Rushabh Mehta | 176b63b | 2016-07-14 17:43:48 +0530 | [diff] [blame] | 869 | } |
| 870 | |
| 871 | return frappe.call({ |
| 872 | // Sometimes we hit the limit for URL length of a GET request |
| 873 | // as we send the full target_doc. Hence this is a POST request. |
| 874 | type: "POST", |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 875 | method: "frappe.model.mapper.map_docs", |
Rushabh Mehta | 176b63b | 2016-07-14 17:43:48 +0530 | [diff] [blame] | 876 | args: { |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 877 | method: opts.method, |
| 878 | source_names: opts.source_name, |
| 879 | target_doc: cur_frm.doc, |
| 880 | args: opts.args, |
Rushabh Mehta | 176b63b | 2016-07-14 17:43:48 +0530 | [diff] [blame] | 881 | }, |
s-aga-r | 2d8363a | 2023-09-02 11:02:24 +0530 | [diff] [blame] | 882 | freeze: true, |
| 883 | freeze_message: __("Mapping {0} ...", [opts.source_doctype]), |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 884 | callback: function (r) { |
| 885 | if (!r.exc) { |
Deepesh Garg | 9b1c222 | 2023-12-27 22:37:01 +0530 | [diff] [blame] | 886 | frappe.model.sync(r.message); |
Vishal Dhayagude | f06c281 | 2017-12-26 16:22:40 +0530 | [diff] [blame] | 887 | cur_frm.dirty(); |
Rushabh Mehta | 176b63b | 2016-07-14 17:43:48 +0530 | [diff] [blame] | 888 | cur_frm.refresh(); |
| 889 | } |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 890 | }, |
Rushabh Mehta | 176b63b | 2016-07-14 17:43:48 +0530 | [diff] [blame] | 891 | }); |
| 892 | } |
Sagar Vora | 78777d6 | 2021-03-09 20:35:08 +0530 | [diff] [blame] | 893 | |
| 894 | let query_args = {}; |
| 895 | if (opts.get_query_filters) { |
| 896 | query_args.filters = opts.get_query_filters; |
| 897 | } |
| 898 | |
| 899 | if (opts.get_query_method) { |
| 900 | query_args.query = opts.get_query_method; |
| 901 | } |
| 902 | |
| 903 | if (query_args.filters || query_args.query) { |
| 904 | opts.get_query = () => query_args; |
| 905 | } |
| 906 | |
| 907 | if (opts.source_doctype) { |
ruthra kumar | 7da9ffa | 2024-01-03 17:59:15 +0530 | [diff] [blame] | 908 | let data_fields = []; |
ruthra kumar | 550cbbd | 2024-04-01 16:25:35 +0530 | [diff] [blame] | 909 | if (["Purchase Receipt", "Delivery Note"].includes(opts.source_doctype)) { |
ruthra kumar | 7da9ffa | 2024-01-03 17:59:15 +0530 | [diff] [blame] | 910 | data_fields.push({ |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 911 | fieldname: "merge_taxes", |
| 912 | fieldtype: "Check", |
| 913 | label: __("Merge taxes from multiple documents"), |
ruthra kumar | 7da9ffa | 2024-01-03 17:59:15 +0530 | [diff] [blame] | 914 | }); |
| 915 | } |
Sagar Vora | 78777d6 | 2021-03-09 20:35:08 +0530 | [diff] [blame] | 916 | const d = new frappe.ui.form.MultiSelectDialog({ |
Prateeksha Singh | edeb4dc | 2017-05-15 11:32:06 +0530 | [diff] [blame] | 917 | doctype: opts.source_doctype, |
| 918 | target: opts.target, |
| 919 | date_field: opts.date_field || undefined, |
| 920 | setters: opts.setters, |
ruthra kumar | 7da9ffa | 2024-01-03 17:59:15 +0530 | [diff] [blame] | 921 | data_fields: data_fields, |
Prateeksha Singh | edeb4dc | 2017-05-15 11:32:06 +0530 | [diff] [blame] | 922 | get_query: opts.get_query, |
marination | 4f395cc | 2020-09-24 12:43:41 +0530 | [diff] [blame] | 923 | add_filters_group: 1, |
Saqib | 7292f54 | 2021-09-13 12:13:43 +0530 | [diff] [blame] | 924 | allow_child_item_selection: opts.allow_child_item_selection, |
gn306029 | 2a619fd | 2022-06-29 17:15:21 +0800 | [diff] [blame] | 925 | child_fieldname: opts.child_fieldname, |
Saqib | 7292f54 | 2021-09-13 12:13:43 +0530 | [diff] [blame] | 926 | child_columns: opts.child_columns, |
Rohit Waghchaure | 69ffddf | 2021-10-07 17:33:58 +0530 | [diff] [blame] | 927 | size: opts.size, |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 928 | action: function (selections, args) { |
Prateeksha Singh | edeb4dc | 2017-05-15 11:32:06 +0530 | [diff] [blame] | 929 | let values = selections; |
Saqib | e03d9aa | 2021-09-17 13:03:27 +0530 | [diff] [blame] | 930 | if (values.length === 0) { |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 931 | frappe.msgprint(__("Please select {0}", [opts.source_doctype])); |
Prateeksha Singh | edeb4dc | 2017-05-15 11:32:06 +0530 | [diff] [blame] | 932 | return; |
| 933 | } |
| 934 | opts.source_name = values; |
ruthra kumar | 550cbbd | 2024-04-01 16:25:35 +0530 | [diff] [blame] | 935 | if ( |
| 936 | opts.allow_child_item_selection || |
| 937 | ["Purchase Receipt", "Delivery Note"].includes(opts.source_doctype) |
| 938 | ) { |
ruthra kumar | 7da9ffa | 2024-01-03 17:59:15 +0530 | [diff] [blame] | 939 | // args contains filtered child docnames |
| 940 | opts.args = args; |
| 941 | } |
Prateeksha Singh | edeb4dc | 2017-05-15 11:32:06 +0530 | [diff] [blame] | 942 | d.dialog.hide(); |
| 943 | _map(); |
| 944 | }, |
Rushabh Mehta | 176b63b | 2016-07-14 17:43:48 +0530 | [diff] [blame] | 945 | }); |
Sagar Vora | 78777d6 | 2021-03-09 20:35:08 +0530 | [diff] [blame] | 946 | |
| 947 | return d; |
| 948 | } |
| 949 | |
| 950 | if (opts.source_name) { |
Prateeksha Singh | edeb4dc | 2017-05-15 11:32:06 +0530 | [diff] [blame] | 951 | opts.source_name = [opts.source_name]; |
Rushabh Mehta | 176b63b | 2016-07-14 17:43:48 +0530 | [diff] [blame] | 952 | _map(); |
| 953 | } |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 954 | }; |
Rushabh Mehta | 176b63b | 2016-07-14 17:43:48 +0530 | [diff] [blame] | 955 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 956 | frappe.form.link_formatters["Item"] = function (value, doc) { |
Alan | 157b388 | 2021-04-21 21:00:22 +0530 | [diff] [blame] | 957 | if (doc && value && doc.item_name && doc.item_name !== value && doc.item_code === value) { |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 958 | return value + ": " + doc.item_name; |
marination | 824f48f | 2020-10-12 20:08:03 +0530 | [diff] [blame] | 959 | } else if (!value && doc.doctype && doc.item_name) { |
| 960 | // format blank value in child table |
| 961 | return doc.item_name; |
Rushabh Mehta | 180e435 | 2016-07-26 17:57:42 +0530 | [diff] [blame] | 962 | } else { |
marination | 824f48f | 2020-10-12 20:08:03 +0530 | [diff] [blame] | 963 | // if value is blank in report view or item code and name are the same, return as is |
Rushabh Mehta | 180e435 | 2016-07-26 17:57:42 +0530 | [diff] [blame] | 964 | return value; |
| 965 | } |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 966 | }; |
Rushabh Mehta | 180e435 | 2016-07-26 17:57:42 +0530 | [diff] [blame] | 967 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 968 | frappe.form.link_formatters["Employee"] = function (value, doc) { |
Rucha Mahabal | 5ba1bc1 | 2021-11-23 09:30:30 +0530 | [diff] [blame] | 969 | if (doc && value && doc.employee_name && doc.employee_name !== value && doc.employee === value) { |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 970 | return value + ": " + doc.employee_name; |
Rucha Mahabal | 5ba1bc1 | 2021-11-23 09:30:30 +0530 | [diff] [blame] | 971 | } else if (!value && doc.doctype && doc.employee_name) { |
| 972 | // format blank value in child table |
| 973 | return doc.employee; |
Rushabh Mehta | 180e435 | 2016-07-26 17:57:42 +0530 | [diff] [blame] | 974 | } else { |
Rucha Mahabal | 5ba1bc1 | 2021-11-23 09:30:30 +0530 | [diff] [blame] | 975 | // if value is blank in report view or project name and name are the same, return as is |
Rushabh Mehta | 180e435 | 2016-07-26 17:57:42 +0530 | [diff] [blame] | 976 | return value; |
| 977 | } |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 978 | }; |
Rushabh Mehta | 180e435 | 2016-07-26 17:57:42 +0530 | [diff] [blame] | 979 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 980 | frappe.form.link_formatters["Project"] = function (value, doc) { |
Rucha Mahabal | 59961f7 | 2021-05-20 23:43:19 +0530 | [diff] [blame] | 981 | if (doc && value && doc.project_name && doc.project_name !== value && doc.project === value) { |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 982 | return value + ": " + doc.project_name; |
Rucha Mahabal | 59961f7 | 2021-05-20 23:43:19 +0530 | [diff] [blame] | 983 | } else if (!value && doc.doctype && doc.project_name) { |
| 984 | // format blank value in child table |
| 985 | return doc.project; |
| 986 | } else { |
| 987 | // if value is blank in report view or project name and name are the same, return as is |
| 988 | return value; |
| 989 | } |
| 990 | }; |
| 991 | |
Rushabh Mehta | 95b995b | 2015-05-28 12:10:55 +0530 | [diff] [blame] | 992 | // add description on posting time |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 993 | $(document).on("app_ready", function () { |
| 994 | if (!frappe.datetime.is_timezone_same()) { |
| 995 | $.each( |
| 996 | [ |
| 997 | "Stock Reconciliation", |
| 998 | "Stock Entry", |
| 999 | "Stock Ledger Entry", |
| 1000 | "Delivery Note", |
| 1001 | "Purchase Receipt", |
| 1002 | "Sales Invoice", |
| 1003 | ], |
| 1004 | function (i, d) { |
| 1005 | frappe.ui.form.on(d, "onload", function (frm) { |
| 1006 | cur_frm.set_df_property("posting_time", "description", frappe.sys_defaults.time_zone); |
| 1007 | }); |
| 1008 | } |
| 1009 | ); |
Rushabh Mehta | 95b995b | 2015-05-28 12:10:55 +0530 | [diff] [blame] | 1010 | } |
akshay | 14384c2 | 2016-07-28 13:53:17 +0530 | [diff] [blame] | 1011 | }); |
Alan | c6dc9ea | 2021-05-07 20:30:04 +0530 | [diff] [blame] | 1012 | |
Himanshu | ec25d59 | 2021-06-14 19:05:52 +0530 | [diff] [blame] | 1013 | // Show SLA dashboard |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 1014 | $(document).on("app_ready", function () { |
| 1015 | $.each(frappe.boot.service_level_agreement_doctypes, function (_i, d) { |
Ankush Menat | bd9ef74 | 2023-07-16 11:34:42 +0530 | [diff] [blame] | 1016 | frappe.ui.form.on(d, { |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 1017 | onload: function (frm) { |
| 1018 | if (!frm.doc.service_level_agreement) return; |
Himanshu | ec25d59 | 2021-06-14 19:05:52 +0530 | [diff] [blame] | 1019 | |
Ankush Menat | bd9ef74 | 2023-07-16 11:34:42 +0530 | [diff] [blame] | 1020 | frappe.call({ |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 1021 | method: "erpnext.support.doctype.service_level_agreement.service_level_agreement.get_service_level_agreement_filters", |
Ankush Menat | bd9ef74 | 2023-07-16 11:34:42 +0530 | [diff] [blame] | 1022 | args: { |
| 1023 | doctype: frm.doc.doctype, |
| 1024 | name: frm.doc.service_level_agreement, |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 1025 | customer: frm.doc.customer, |
Himanshu | ec25d59 | 2021-06-14 19:05:52 +0530 | [diff] [blame] | 1026 | }, |
Ankush Menat | bd9ef74 | 2023-07-16 11:34:42 +0530 | [diff] [blame] | 1027 | callback: function (r) { |
| 1028 | if (r && r.message) { |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 1029 | frm.set_query("priority", function () { |
Ankush Menat | bd9ef74 | 2023-07-16 11:34:42 +0530 | [diff] [blame] | 1030 | return { |
| 1031 | filters: { |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 1032 | name: ["in", r.message.priority], |
| 1033 | }, |
Ankush Menat | bd9ef74 | 2023-07-16 11:34:42 +0530 | [diff] [blame] | 1034 | }; |
Himanshu | ec25d59 | 2021-06-14 19:05:52 +0530 | [diff] [blame] | 1035 | }); |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 1036 | frm.set_query("service_level_agreement", function () { |
Ankush Menat | bd9ef74 | 2023-07-16 11:34:42 +0530 | [diff] [blame] | 1037 | return { |
| 1038 | filters: { |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 1039 | name: ["in", r.message.service_level_agreements], |
| 1040 | }, |
Ankush Menat | bd9ef74 | 2023-07-16 11:34:42 +0530 | [diff] [blame] | 1041 | }; |
| 1042 | }); |
Himanshu | ec25d59 | 2021-06-14 19:05:52 +0530 | [diff] [blame] | 1043 | } |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 1044 | }, |
Himanshu | ec25d59 | 2021-06-14 19:05:52 +0530 | [diff] [blame] | 1045 | }); |
Ankush Menat | bd9ef74 | 2023-07-16 11:34:42 +0530 | [diff] [blame] | 1046 | }, |
| 1047 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 1048 | refresh: function (frm) { |
| 1049 | if ( |
| 1050 | frm.doc.status !== "Closed" && |
| 1051 | frm.doc.service_level_agreement && |
| 1052 | ["First Response Due", "Resolution Due"].includes(frm.doc.agreement_status) |
| 1053 | ) { |
Ankush Menat | bd9ef74 | 2023-07-16 11:34:42 +0530 | [diff] [blame] | 1054 | frappe.call({ |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 1055 | method: "frappe.client.get", |
Ankush Menat | bd9ef74 | 2023-07-16 11:34:42 +0530 | [diff] [blame] | 1056 | args: { |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 1057 | doctype: "Service Level Agreement", |
| 1058 | name: frm.doc.service_level_agreement, |
Ankush Menat | bd9ef74 | 2023-07-16 11:34:42 +0530 | [diff] [blame] | 1059 | }, |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 1060 | callback: function (data) { |
Ankush Menat | bd9ef74 | 2023-07-16 11:34:42 +0530 | [diff] [blame] | 1061 | let statuses = data.message.pause_sla_on; |
| 1062 | const hold_statuses = []; |
| 1063 | $.each(statuses, (_i, entry) => { |
| 1064 | hold_statuses.push(entry.status); |
| 1065 | }); |
| 1066 | if (hold_statuses.includes(frm.doc.status)) { |
| 1067 | frm.dashboard.clear_headline(); |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 1068 | let message = { |
| 1069 | indicator: "orange", |
| 1070 | msg: __("SLA is on hold since {0}", [ |
| 1071 | moment(frm.doc.on_hold_since).fromNow(true), |
| 1072 | ]), |
| 1073 | }; |
Ankush Menat | bd9ef74 | 2023-07-16 11:34:42 +0530 | [diff] [blame] | 1074 | frm.dashboard.set_headline_alert( |
| 1075 | '<div class="row">' + |
| 1076 | '<div class="col-xs-12">' + |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 1077 | '<span class="indicator whitespace-nowrap ' + |
| 1078 | message.indicator + |
| 1079 | '"><span>' + |
| 1080 | message.msg + |
| 1081 | "</span></span> " + |
| 1082 | "</div>" + |
| 1083 | "</div>" |
Ankush Menat | bd9ef74 | 2023-07-16 11:34:42 +0530 | [diff] [blame] | 1084 | ); |
| 1085 | } else { |
| 1086 | set_time_to_resolve_and_response(frm, data.message.apply_sla_for_resolution); |
| 1087 | } |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 1088 | }, |
Ankush Menat | bd9ef74 | 2023-07-16 11:34:42 +0530 | [diff] [blame] | 1089 | }); |
| 1090 | } else if (frm.doc.service_level_agreement) { |
| 1091 | frm.dashboard.clear_headline(); |
| 1092 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 1093 | let agreement_status = |
| 1094 | frm.doc.agreement_status == "Fulfilled" |
| 1095 | ? { indicator: "green", msg: "Service Level Agreement has been fulfilled" } |
| 1096 | : { indicator: "red", msg: "Service Level Agreement Failed" }; |
Ankush Menat | bd9ef74 | 2023-07-16 11:34:42 +0530 | [diff] [blame] | 1097 | |
| 1098 | frm.dashboard.set_headline_alert( |
| 1099 | '<div class="row">' + |
| 1100 | '<div class="col-xs-12">' + |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 1101 | '<span class="indicator whitespace-nowrap ' + |
| 1102 | agreement_status.indicator + |
| 1103 | '"><span class="hidden-xs">' + |
| 1104 | agreement_status.msg + |
| 1105 | "</span></span> " + |
| 1106 | "</div>" + |
| 1107 | "</div>" |
Ankush Menat | bd9ef74 | 2023-07-16 11:34:42 +0530 | [diff] [blame] | 1108 | ); |
| 1109 | } |
| 1110 | }, |
| 1111 | }); |
Himanshu | ec25d59 | 2021-06-14 19:05:52 +0530 | [diff] [blame] | 1112 | }); |
| 1113 | }); |
| 1114 | |
| 1115 | function set_time_to_resolve_and_response(frm, apply_sla_for_resolution) { |
| 1116 | frm.dashboard.clear_headline(); |
| 1117 | |
Saqib | 2411477 | 2021-12-15 11:45:34 +0530 | [diff] [blame] | 1118 | let time_to_respond; |
Saqib Ansari | 476e81a | 2021-12-06 18:55:30 +0530 | [diff] [blame] | 1119 | if (!frm.doc.first_responded_on) { |
Himanshu | ec25d59 | 2021-06-14 19:05:52 +0530 | [diff] [blame] | 1120 | time_to_respond = get_time_left(frm.doc.response_by, frm.doc.agreement_status); |
Saqib | 2411477 | 2021-12-15 11:45:34 +0530 | [diff] [blame] | 1121 | } else { |
| 1122 | time_to_respond = get_status(frm.doc.response_by, frm.doc.first_responded_on); |
Himanshu | ec25d59 | 2021-06-14 19:05:52 +0530 | [diff] [blame] | 1123 | } |
| 1124 | |
| 1125 | let alert = ` |
| 1126 | <div class="row"> |
| 1127 | <div class="col-xs-12 col-sm-6"> |
| 1128 | <span class="indicator whitespace-nowrap ${time_to_respond.indicator}"> |
| 1129 | <span>Time to Respond: ${time_to_respond.diff_display}</span> |
| 1130 | </span> |
| 1131 | </div>`; |
| 1132 | |
Himanshu | ec25d59 | 2021-06-14 19:05:52 +0530 | [diff] [blame] | 1133 | if (apply_sla_for_resolution) { |
Saqib | 2411477 | 2021-12-15 11:45:34 +0530 | [diff] [blame] | 1134 | let time_to_resolve; |
Saqib Ansari | 476e81a | 2021-12-06 18:55:30 +0530 | [diff] [blame] | 1135 | if (!frm.doc.resolution_date) { |
Himanshu | ec25d59 | 2021-06-14 19:05:52 +0530 | [diff] [blame] | 1136 | time_to_resolve = get_time_left(frm.doc.resolution_by, frm.doc.agreement_status); |
Saqib | 2411477 | 2021-12-15 11:45:34 +0530 | [diff] [blame] | 1137 | } else { |
| 1138 | time_to_resolve = get_status(frm.doc.resolution_by, frm.doc.resolution_date); |
Himanshu | ec25d59 | 2021-06-14 19:05:52 +0530 | [diff] [blame] | 1139 | } |
| 1140 | |
| 1141 | alert += ` |
| 1142 | <div class="col-xs-12 col-sm-6"> |
| 1143 | <span class="indicator whitespace-nowrap ${time_to_resolve.indicator}"> |
| 1144 | <span>Time to Resolve: ${time_to_resolve.diff_display}</span> |
| 1145 | </span> |
| 1146 | </div>`; |
| 1147 | } |
| 1148 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 1149 | alert += "</div>"; |
Himanshu | ec25d59 | 2021-06-14 19:05:52 +0530 | [diff] [blame] | 1150 | |
| 1151 | frm.dashboard.set_headline_alert(alert); |
| 1152 | } |
| 1153 | |
| 1154 | function get_time_left(timestamp, agreement_status) { |
Ankush Menat | eaf86a6 | 2023-12-14 15:53:57 +0530 | [diff] [blame] | 1155 | const diff = moment(timestamp).diff(frappe.datetime.system_datetime(true)); |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 1156 | const diff_display = diff >= 44500 ? moment.duration(diff).humanize() : "Failed"; |
| 1157 | let indicator = diff_display == "Failed" && agreement_status != "Fulfilled" ? "red" : "green"; |
| 1158 | return { diff_display: diff_display, indicator: indicator }; |
Himanshu | ec25d59 | 2021-06-14 19:05:52 +0530 | [diff] [blame] | 1159 | } |
| 1160 | |
Saqib | 2411477 | 2021-12-15 11:45:34 +0530 | [diff] [blame] | 1161 | function get_status(expected, actual) { |
| 1162 | const time_left = moment(expected).diff(moment(actual)); |
Saqib Ansari | 476e81a | 2021-12-06 18:55:30 +0530 | [diff] [blame] | 1163 | if (time_left >= 0) { |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 1164 | return { diff_display: "Fulfilled", indicator: "green" }; |
Himanshu | ec25d59 | 2021-06-14 19:05:52 +0530 | [diff] [blame] | 1165 | } else { |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 1166 | return { diff_display: "Failed", indicator: "red" }; |
Himanshu | ec25d59 | 2021-06-14 19:05:52 +0530 | [diff] [blame] | 1167 | } |
| 1168 | } |
| 1169 | |
Alan | c6dc9ea | 2021-05-07 20:30:04 +0530 | [diff] [blame] | 1170 | function attach_selector_button(inner_text, append_loction, context, grid_row) { |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 1171 | let $btn_div = $("<div>").css({ "margin-bottom": "10px", "margin-top": "10px" }).appendTo(append_loction); |
| 1172 | let $btn = $(`<button class="btn btn-sm btn-default">${inner_text}</button>`).appendTo($btn_div); |
Alan | c6dc9ea | 2021-05-07 20:30:04 +0530 | [diff] [blame] | 1173 | |
Ankush Menat | ec74a5e | 2024-03-10 19:45:40 +0530 | [diff] [blame] | 1174 | $btn.on("click", function () { |
Alan | c6dc9ea | 2021-05-07 20:30:04 +0530 | [diff] [blame] | 1175 | context.show_serial_batch_selector(grid_row.frm, grid_row.doc, "", "", true); |
| 1176 | }); |
ruthra kumar | 5981c7e | 2023-08-29 13:19:26 +0530 | [diff] [blame] | 1177 | } |
rohitwaghchaure | 0da19a4 | 2024-03-12 12:27:21 +0530 | [diff] [blame] | 1178 | |
| 1179 | $.extend(erpnext.stock.utils, { |
| 1180 | set_item_details_using_barcode(frm, child_row, callback) { |
| 1181 | const barcode_scanner = new erpnext.utils.BarcodeScanner({ frm: frm }); |
| 1182 | barcode_scanner.scan_api_call(child_row.barcode, callback); |
| 1183 | }, |
| 1184 | }); |