From 83ce3dd91598b8c2aad65e7f934c16131a9dbdc7 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Wed, 9 Oct 2024 09:06:34 +0530 Subject: [PATCH] fix: Accepted and Rejected warehouse cannot be same (backport #43568) (#43573) fix: Accepted and Rejected warehouse cannot be same (#43568) (cherry picked from commit 5130f7d411a8f27c1b51064611b739aaf8e09869) Co-authored-by: rohitwaghchaure --- erpnext/public/js/controllers/buying.js | 4 +-- .../js/utils/serial_no_batch_selector.js | 25 ++++++++++++++----- .../serial_and_batch_bundle.py | 12 ++++++--- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/erpnext/public/js/controllers/buying.js b/erpnext/public/js/controllers/buying.js index 1d0680de861..202efe157f0 100644 --- a/erpnext/public/js/controllers/buying.js +++ b/erpnext/public/js/controllers/buying.js @@ -392,7 +392,7 @@ erpnext.buying = { item[field] = r.message[field]; }); - item.type_of_transaction = item.rejected_qty > 0 ? "Inward" : "Outward"; + item.type_of_transaction = !doc.is_return > 0 ? "Inward" : "Outward"; item.is_rejected = true; new erpnext.SerialBatchPackageSelector( @@ -404,7 +404,7 @@ erpnext.buying = { } let update_values = { - "serial_and_batch_bundle": r.name, + "rejected_serial_and_batch_bundle": r.name, "use_serial_batch_fields": 0, "rejected_qty": qty / flt(item.conversion_factor || 1, precision("conversion_factor", item)) } diff --git a/erpnext/public/js/utils/serial_no_batch_selector.js b/erpnext/public/js/utils/serial_no_batch_selector.js index 46ff6366de8..1045965e43d 100644 --- a/erpnext/public/js/utils/serial_no_batch_selector.js +++ b/erpnext/public/js/utils/serial_no_batch_selector.js @@ -96,7 +96,12 @@ erpnext.SerialBatchPackageSelector = class SerialNoBatchBundleUpdate { options: "Warehouse", default: this.get_warehouse(), onchange: () => { - this.item.warehouse = this.dialog.get_value("warehouse"); + if (this.item?.is_rejected) { + this.item.rejected_warehouse = this.dialog.get_value("warehouse"); + } else { + this.item.warehouse = this.dialog.get_value("warehouse"); + } + this.get_auto_data(); }, get_query: () => { @@ -282,10 +287,6 @@ erpnext.SerialBatchPackageSelector = class SerialNoBatchBundleUpdate { return fields; } - set_serial_nos_from_series() {} - - set_batch_nos_from_series() {} - set_serial_nos_from_range() { const serial_no_range = this.dialog.get_value("serial_no_range"); @@ -508,12 +509,17 @@ erpnext.SerialBatchPackageSelector = class SerialNoBatchBundleUpdate { based_on = "FIFO"; } + let warehouse = this.item.warehouse || this.item.s_warehouse; + if (this.item?.is_rejected) { + warehouse = this.item.rejected_warehouse; + } + if (qty) { frappe.call({ method: "erpnext.stock.doctype.serial_and_batch_bundle.serial_and_batch_bundle.get_auto_data", args: { item_code: this.item.item_code, - warehouse: this.item.warehouse || this.item.s_warehouse, + warehouse: warehouse, has_serial_no: this.item.has_serial_no, has_batch_no: this.item.has_batch_no, qty: qty, @@ -627,6 +633,10 @@ erpnext.SerialBatchPackageSelector = class SerialNoBatchBundleUpdate { frappe.throw(__("Please select a Warehouse")); } + if (this.item?.is_rejected && this.item.rejected_warehouse === this.item.warehouse) { + frappe.throw(__("Rejected Warehouse and Accepted Warehouse cannot be same.")); + } + frappe .call({ method: "erpnext.stock.doctype.serial_and_batch_bundle.serial_and_batch_bundle.add_serial_batch_ledgers", @@ -701,5 +711,8 @@ erpnext.SerialBatchPackageSelector = class SerialNoBatchBundleUpdate { }); this.dialog.fields_dict.entries.grid.refresh(); + if (this.dialog.fields_dict.entries.df.data?.length) { + this.dialog.set_value("enter_manually", 0); + } } }; diff --git a/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py b/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py index 62f95f5b2e8..94ec8675db8 100644 --- a/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py +++ b/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py @@ -1308,8 +1308,12 @@ def add_serial_batch_ledgers(entries, child_row, doc, warehouse, do_not_save=Fal if parent_doc and isinstance(parent_doc, str): parent_doc = parse_json(parent_doc) - if frappe.db.exists("Serial and Batch Bundle", child_row.serial_and_batch_bundle): - sb_doc = update_serial_batch_no_ledgers(entries, child_row, parent_doc, warehouse) + bundle = child_row.serial_and_batch_bundle + if child_row.get("is_rejected"): + bundle = child_row.rejected_serial_and_batch_bundle + + if frappe.db.exists("Serial and Batch Bundle", bundle): + sb_doc = update_serial_batch_no_ledgers(bundle, entries, child_row, parent_doc, warehouse) else: sb_doc = create_serial_batch_no_ledgers( entries, child_row, parent_doc, warehouse, do_not_save=do_not_save @@ -1412,8 +1416,8 @@ def get_type_of_transaction(parent_doc, child_row): return type_of_transaction -def update_serial_batch_no_ledgers(entries, child_row, parent_doc, warehouse=None) -> object: - doc = frappe.get_doc("Serial and Batch Bundle", child_row.serial_and_batch_bundle) +def update_serial_batch_no_ledgers(bundle, entries, child_row, parent_doc, warehouse=None) -> object: + doc = frappe.get_doc("Serial and Batch Bundle", bundle) doc.voucher_detail_no = child_row.name doc.posting_date = parent_doc.posting_date doc.posting_time = parent_doc.posting_time