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