diff --git a/erpnext/public/js/controllers/buying.js b/erpnext/public/js/controllers/buying.js index d99de629e11d46d32bea1d8a312369420d19c18b..61457b818fc4ed281f87e6ef9bacbfe16668fac5 100644 --- a/erpnext/public/js/controllers/buying.js +++ b/erpnext/public/js/controllers/buying.js @@ -347,7 +347,6 @@ erpnext.buying = { add_serial_batch_bundle(doc, cdt, cdn) { let item = locals[cdt][cdn]; let me = this; - let path = "assets/erpnext/js/utils/serial_no_batch_selector.js"; frappe.db.get_value("Item", item.item_code, ["has_batch_no", "has_serial_no"]) .then((r) => { @@ -357,30 +356,28 @@ erpnext.buying = { item.type_of_transaction = item.qty > 0 ? "Inward" : "Outward"; item.is_rejected = false; - frappe.require(path, function() { - new erpnext.SerialBatchPackageSelector( - me.frm, item, (r) => { - if (r) { - let qty = Math.abs(r.total_qty); - if (doc.is_return) { - qty = qty * -1; - } - - let update_values = { - "serial_and_batch_bundle": r.name, - "use_serial_batch_fields": 0, - "qty": qty / flt(item.conversion_factor || 1, precision("conversion_factor", item)) - } - - if (r.warehouse) { - update_values["warehouse"] = r.warehouse; - } - - frappe.model.set_value(item.doctype, item.name, update_values); + new erpnext.SerialBatchPackageSelector( + me.frm, item, (r) => { + if (r) { + let qty = Math.abs(r.total_qty); + if (doc.is_return) { + qty = qty * -1; } + + let update_values = { + "serial_and_batch_bundle": r.name, + "use_serial_batch_fields": 0, + "qty": qty / flt(item.conversion_factor || 1, precision("conversion_factor", item)) + } + + if (r.warehouse) { + update_values["warehouse"] = r.warehouse; + } + + frappe.model.set_value(item.doctype, item.name, update_values); } - ); - }); + } + ); } }); } @@ -388,7 +385,6 @@ erpnext.buying = { add_serial_batch_for_rejected_qty(doc, cdt, cdn) { let item = locals[cdt][cdn]; let me = this; - let path = "assets/erpnext/js/utils/serial_no_batch_selector.js"; frappe.db.get_value("Item", item.item_code, ["has_batch_no", "has_serial_no"]) .then((r) => { @@ -398,30 +394,28 @@ erpnext.buying = { item.type_of_transaction = item.qty > 0 ? "Inward" : "Outward"; item.is_rejected = true; - frappe.require(path, function() { - new erpnext.SerialBatchPackageSelector( - me.frm, item, (r) => { - if (r) { - let qty = Math.abs(r.total_qty); - if (doc.is_return) { - qty = qty * -1; - } - - let update_values = { - "serial_and_batch_bundle": r.name, - "use_serial_batch_fields": 0, - "rejected_qty": qty / flt(item.conversion_factor || 1, precision("conversion_factor", item)) - } - - if (r.warehouse) { - update_values["rejected_warehouse"] = r.warehouse; - } - - frappe.model.set_value(item.doctype, item.name, update_values); + new erpnext.SerialBatchPackageSelector( + me.frm, item, (r) => { + if (r) { + let qty = Math.abs(r.total_qty); + if (doc.is_return) { + qty = qty * -1; } + + let update_values = { + "serial_and_batch_bundle": r.name, + "use_serial_batch_fields": 0, + "rejected_qty": qty / flt(item.conversion_factor || 1, precision("conversion_factor", item)) + } + + if (r.warehouse) { + update_values["rejected_warehouse"] = r.warehouse; + } + + frappe.model.set_value(item.doctype, item.name, update_values); } - ); - }); + } + ); } }); } diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index c03e8b9bcb2be864a4cc5c559f01300cae0cab6d..b52d9b26a608e597edc9745bd8b1cd78ae526d19 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -2599,27 +2599,25 @@ erpnext.show_serial_batch_selector = function (frm, item_row, callback, on_close } } - frappe.require("assets/erpnext/js/utils/serial_no_batch_selector.js", function() { - if (["Sales Invoice", "Delivery Note"].includes(frm.doc.doctype)) { - item_row.type_of_transaction = frm.doc.is_return ? "Inward" : "Outward"; - } else { - item_row.type_of_transaction = frm.doc.is_return ? "Outward" : "Inward"; - } - - new erpnext.SerialBatchPackageSelector(frm, item_row, (r) => { - if (r) { - let update_values = { - "serial_and_batch_bundle": r.name, - "qty": Math.abs(r.total_qty) - } + if (["Sales Invoice", "Delivery Note"].includes(frm.doc.doctype)) { + item_row.type_of_transaction = frm.doc.is_return ? "Inward" : "Outward"; + } else { + item_row.type_of_transaction = frm.doc.is_return ? "Outward" : "Inward"; + } - if (r.warehouse) { - update_values[warehouse_field] = r.warehouse; - } + new erpnext.SerialBatchPackageSelector(frm, item_row, (r) => { + if (r) { + let update_values = { + "serial_and_batch_bundle": r.name, + "qty": Math.abs(r.total_qty) + } - frappe.model.set_value(item_row.doctype, item_row.name, update_values); + if (r.warehouse) { + update_values[warehouse_field] = r.warehouse; } - }); + + frappe.model.set_value(item_row.doctype, item_row.name, update_values); + } }); } diff --git a/erpnext/public/js/erpnext.bundle.js b/erpnext/public/js/erpnext.bundle.js index 88b4b4af1808fffdb8be1b8b34f2bd3c71c50057..2a6d88d3b77604796f846ea1fa839ecf5139e100 100644 --- a/erpnext/public/js/erpnext.bundle.js +++ b/erpnext/public/js/erpnext.bundle.js @@ -4,6 +4,7 @@ import "./queries"; import "./sms_manager"; import "./utils/party"; import "./controllers/stock_controller"; +import "./utils/serial_no_batch_selector"; import "./payment/payments"; import "./templates/visual_plant_floor_template.html"; import "./plant_floor_visual/visual_plant"; diff --git a/erpnext/public/js/utils.js b/erpnext/public/js/utils.js index 53fa00472a78a3968adb144b16bf8cee3b41a2cd..9c204fe5068e93f1352cd1565f7f73b0e015a99e 100755 --- a/erpnext/public/js/utils.js +++ b/erpnext/public/js/utils.js @@ -386,31 +386,28 @@ $.extend(erpnext.utils, { let item_row = frappe.get_doc(cdt, cdn); item_row.type_of_transaction = type_of_transaction; - frappe.db.get_value("Item", item_row.item_code, ["has_batch_no", "has_serial_no"]) - .then((r) => { - item_row.has_batch_no = r.message.has_batch_no; - item_row.has_serial_no = r.message.has_serial_no; - - frappe.require("assets/erpnext/js/utils/serial_no_batch_selector.js", function() { - new erpnext.SerialBatchPackageSelector(frm, item_row, (r) => { - if (r) { - let update_values = { - "serial_and_batch_bundle": r.name, - "qty": Math.abs(r.total_qty) - } - - if (!warehouse_field) { - warehouse_field = "warehouse"; - } + frappe.db.get_value("Item", item_row.item_code, ["has_batch_no", "has_serial_no"]).then((r) => { + item_row.has_batch_no = r.message.has_batch_no; + item_row.has_serial_no = r.message.has_serial_no; + + new erpnext.SerialBatchPackageSelector(frm, item_row, (r) => { + if (r) { + let update_values = { + serial_and_batch_bundle: r.name, + qty: Math.abs(r.total_qty), + }; + + if (!warehouse_field) { + warehouse_field = "warehouse"; + } - if (r.warehouse) { - update_values[warehouse_field] = r.warehouse; - } + if (r.warehouse) { + update_values[warehouse_field] = r.warehouse; + } - frappe.model.set_value(item_row.doctype, item_row.name, update_values); - } - }); - }); + frappe.model.set_value(item_row.doctype, item_row.name, update_values); + } + }); }); }, diff --git a/erpnext/public/js/utils/sales_common.js b/erpnext/public/js/utils/sales_common.js index 0ee87e5bf30c3773c1386af32485256b10c4c646..e26017567505020d23d9fa77a92a8664c8ef5db2 100644 --- a/erpnext/public/js/utils/sales_common.js +++ b/erpnext/public/js/utils/sales_common.js @@ -318,7 +318,6 @@ erpnext.sales_common = { pick_serial_and_batch(doc, cdt, cdn) { let item = locals[cdt][cdn]; let me = this; - let path = "assets/erpnext/js/utils/serial_no_batch_selector.js"; frappe.db.get_value("Item", item.item_code, ["has_batch_no", "has_serial_no"]) .then((r) => { @@ -334,26 +333,27 @@ erpnext.sales_common = { item.title = __("Select Serial and Batch"); } - frappe.require(path, function() { - new erpnext.SerialBatchPackageSelector( - me.frm, item, (r) => { - if (r) { - let qty = Math.abs(r.total_qty); - if (doc.is_return) { - qty = qty * -1; - } - - frappe.model.set_value(item.doctype, item.name, { - "serial_and_batch_bundle": r.name, - "use_serial_batch_fields": 0, - "qty": qty / flt(item.conversion_factor || 1, precision("conversion_factor", item)) - }); - } - } - ); - }); - } - }); + new erpnext.SerialBatchPackageSelector(me.frm, item, (r) => { + if (r) { + let qty = Math.abs(r.total_qty); + if (doc.is_return) { + qty = qty * -1; + } + + frappe.model.set_value(item.doctype, item.name, { + serial_and_batch_bundle: r.name, + use_serial_batch_fields: 0, + qty: + qty / + flt( + item.conversion_factor || 1, + precision("conversion_factor", item) + ), + }); + } + }); + } + }); } update_auto_repeat_reference(doc) { diff --git a/erpnext/selling/page/point_of_sale/pos_item_details.js b/erpnext/selling/page/point_of_sale/pos_item_details.js index 2fa6d4c4dad71ee62af36083330ab69b49556562..b2ab95a4061eafa8916593e058179db7f3a580f3 100644 --- a/erpnext/selling/page/point_of_sale/pos_item_details.js +++ b/erpnext/selling/page/point_of_sale/pos_item_details.js @@ -376,20 +376,18 @@ erpnext.PointOfSale.ItemDetails = class { } bind_auto_serial_fetch_event() { - this.$form_container.on('click', '.auto-fetch-btn', () => { - frappe.require("assets/erpnext/js/utils/serial_no_batch_selector.js", () => { - let frm = this.events.get_frm(); - let item_row = this.item_row; - item_row.type_of_transaction = "Outward"; - - new erpnext.SerialBatchPackageSelector(frm, item_row, (r) => { - if (r) { - frappe.model.set_value(item_row.doctype, item_row.name, { - "serial_and_batch_bundle": r.name, - "qty": Math.abs(r.total_qty) - }); - } - }); + this.$form_container.on("click", ".auto-fetch-btn", () => { + let frm = this.events.get_frm(); + let item_row = this.item_row; + item_row.type_of_transaction = "Outward"; + + new erpnext.SerialBatchPackageSelector(frm, item_row, (r) => { + if (r) { + frappe.model.set_value(item_row.doctype, item_row.name, { + serial_and_batch_bundle: r.name, + qty: Math.abs(r.total_qty), + }); + } }); }) } diff --git a/erpnext/stock/doctype/pick_list/pick_list.js b/erpnext/stock/doctype/pick_list/pick_list.js index c04c5ddbf401aa37d2fd2f808aa84f9d20109783..c35afb8176f262cbb4a451870d0b1821411fb514 100644 --- a/erpnext/stock/doctype/pick_list/pick_list.js +++ b/erpnext/stock/doctype/pick_list/pick_list.js @@ -320,23 +320,19 @@ frappe.ui.form.on('Pick List Item', { item.title = __("Select Serial and Batch"); } - frappe.require(path, function() { - new erpnext.SerialBatchPackageSelector( - frm, item, (r) => { - if (r) { - let qty = Math.abs(r.total_qty); - frappe.model.set_value(item.doctype, item.name, { - "serial_and_batch_bundle": r.name, - "use_serial_batch_fields": 0, - "qty": qty / flt(item.conversion_factor || 1, precision("conversion_factor", item)) - }); - } - } - ); - }); - } - }); - } + new erpnext.SerialBatchPackageSelector(frm, item, (r) => { + if (r) { + let qty = Math.abs(r.total_qty); + frappe.model.set_value(item.doctype, item.name, { + serial_and_batch_bundle: r.name, + use_serial_batch_fields: 0, + qty: qty / flt(item.conversion_factor || 1, precision("conversion_factor", item)), + }); + } + }); + } + }); + }, }); function get_item_details(item_code, uom=null) { diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.js b/erpnext/stock/doctype/stock_entry/stock_entry.js index a0e3b91eccb148e808d70524c48c9946d3ca64c5..85b56c9dc3fc0d1b26bf4d276e92f27f3820ac6e 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.js +++ b/erpnext/stock/doctype/stock_entry/stock_entry.js @@ -1252,29 +1252,26 @@ erpnext.stock.StockEntry = class StockEntry extends erpnext.stock.StockControlle erpnext.stock.select_batch_and_serial_no = (frm, item) => { let path = "assets/erpnext/js/utils/serial_no_batch_selector.js"; - frappe.db.get_value("Item", item.item_code, ["has_batch_no", "has_serial_no"]) - .then((r) => { - if (r.message && (r.message.has_batch_no || r.message.has_serial_no)) { - item.has_serial_no = r.message.has_serial_no; - item.has_batch_no = r.message.has_batch_no; - item.type_of_transaction = item.s_warehouse ? "Outward" : "Inward"; - - frappe.require(path, function() { - new erpnext.SerialBatchPackageSelector( - frm, item, (r) => { - if (r) { - frappe.model.set_value(item.doctype, item.name, { - "serial_and_batch_bundle": r.name, - "use_serial_batch_fields": 0, - "qty": Math.abs(r.total_qty) / flt(item.conversion_factor || 1, precision("conversion_factor", item)) - }); - } - } - ); - }); - } - }); -} + frappe.db.get_value("Item", item.item_code, ["has_batch_no", "has_serial_no"]).then((r) => { + if (r.message && (r.message.has_batch_no || r.message.has_serial_no)) { + item.has_serial_no = r.message.has_serial_no; + item.has_batch_no = r.message.has_batch_no; + item.type_of_transaction = item.s_warehouse ? "Outward" : "Inward"; + + new erpnext.SerialBatchPackageSelector(frm, item, (r) => { + if (r) { + frappe.model.set_value(item.doctype, item.name, { + serial_and_batch_bundle: r.name, + use_serial_batch_fields: 0, + qty: + Math.abs(r.total_qty) / + flt(item.conversion_factor || 1, precision("conversion_factor", item)), + }); + } + }); + } + }); +}; function attach_bom_items(bom_no) { if (!bom_no) {