diff --git a/erpnext/controllers/selling_controller.py b/erpnext/controllers/selling_controller.py index 747b4e061b6..c1b3a6fcedf 100644 --- a/erpnext/controllers/selling_controller.py +++ b/erpnext/controllers/selling_controller.py @@ -750,12 +750,12 @@ def get_serial_and_batch_bundle(child, parent): "item_code": child.item_code, "warehouse": child.warehouse, "voucher_type": parent.doctype, - "voucher_no": parent.name, + "voucher_no": parent.name if parent.docstatus < 2 else None, "voucher_detail_no": child.name, "posting_date": parent.posting_date, "posting_time": parent.posting_time, "qty": child.qty, - "type_of_transaction": "Outward" if child.qty > 0 else "Inward", + "type_of_transaction": "Outward" if child.qty > 0 and parent.docstatus < 2 else "Inward", "company": parent.company, "do_not_submit": "True", } diff --git a/erpnext/public/js/controllers/buying.js b/erpnext/public/js/controllers/buying.js index 1c493660afa..b5a8b757706 100644 --- a/erpnext/public/js/controllers/buying.js +++ b/erpnext/public/js/controllers/buying.js @@ -386,7 +386,7 @@ erpnext.buying = { 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.qty > 0 ? "Inward" : "Outward"; + item.type_of_transaction = item.rejected_qty > 0 ? "Inward" : "Outward"; item.is_rejected = true; new erpnext.SerialBatchPackageSelector( diff --git a/erpnext/stock/serial_batch_bundle.py b/erpnext/stock/serial_batch_bundle.py index 9625b20da41..24e2ee10ab1 100644 --- a/erpnext/stock/serial_batch_bundle.py +++ b/erpnext/stock/serial_batch_bundle.py @@ -856,6 +856,9 @@ class SerialBatchCreation: if not doc.get("entries"): return frappe._dict({}) + if doc.voucher_no and frappe.get_cached_value(doc.voucher_type, doc.voucher_no, "docstatus") == 2: + doc.voucher_no = "" + doc.save() self.validate_qty(doc) diff --git a/erpnext/subcontracting/doctype/subcontracting_receipt/subcontracting_receipt.js b/erpnext/subcontracting/doctype/subcontracting_receipt/subcontracting_receipt.js index aeff2f6d58f..d407d9c82d7 100644 --- a/erpnext/subcontracting/doctype/subcontracting_receipt/subcontracting_receipt.js +++ b/erpnext/subcontracting/doctype/subcontracting_receipt/subcontracting_receipt.js @@ -335,12 +335,115 @@ frappe.ui.form.on("Subcontracting Receipt Item", { items_remove: (frm) => { set_missing_values(frm); }, + + add_serial_batch_bundle(frm, cdt, cdn) { + let item = locals[cdt][cdn]; + + 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.qty > 0 ? "Inward" : "Outward"; + item.is_rejected = false; + + new erpnext.SerialBatchPackageSelector(frm, item, (r) => { + if (r) { + let qty = Math.abs(r.total_qty); + if (frm.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); + } + }); + } + }); + }, + + add_serial_batch_for_rejected_qty(frm, cdt, cdn) { + let item = locals[cdt][cdn]; + + 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.rejected_qty > 0 ? "Inward" : "Outward"; + item.is_rejected = true; + + new erpnext.SerialBatchPackageSelector(frm, item, (r) => { + if (r) { + let qty = Math.abs(r.total_qty); + if (frm.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); + } + }); + } + }); + }, }); frappe.ui.form.on("Subcontracting Receipt Supplied Item", { consumed_qty(frm) { set_missing_values(frm); }, + + add_serial_batch_bundle(frm, cdt, cdn) { + let item = locals[cdt][cdn]; + + item.item_code = item.rm_item_code; + item.qty = item.consumed_qty; + item.warehouse = frm.doc.supplier_warehouse; + 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.qty > 0 ? "Outward" : "Inward"; + item.is_rejected = false; + + new erpnext.SerialBatchPackageSelector(frm, item, (r) => { + if (r) { + let qty = Math.abs(r.total_qty); + if (frm.doc.is_return) { + qty = qty * -1; + } + + let update_values = { + serial_and_batch_bundle: r.name, + use_serial_batch_fields: 0, + consumed_qty: + qty / flt(item.conversion_factor || 1, precision("conversion_factor", item)), + }; + + frappe.model.set_value(item.doctype, item.name, update_values); + } + }); + } + }); + }, }); let set_warehouse_in_children = (child_table, warehouse_field, warehouse) => { diff --git a/erpnext/subcontracting/doctype/subcontracting_receipt_item/subcontracting_receipt_item.json b/erpnext/subcontracting/doctype/subcontracting_receipt_item/subcontracting_receipt_item.json index ca14f09c9c5..97545a3ffca 100644 --- a/erpnext/subcontracting/doctype/subcontracting_receipt_item/subcontracting_receipt_item.json +++ b/erpnext/subcontracting/doctype/subcontracting_receipt_item/subcontracting_receipt_item.json @@ -47,9 +47,11 @@ "schedule_date", "reference_name", "section_break_45", + "add_serial_batch_bundle", "serial_and_batch_bundle", "use_serial_batch_fields", "col_break5", + "add_serial_batch_for_rejected_qty", "rejected_serial_and_batch_bundle", "section_break_jshh", "serial_no", @@ -563,12 +565,28 @@ { "fieldname": "column_break_henr", "fieldtype": "Column Break" + }, + { + "depends_on": "eval:doc.use_serial_batch_fields === 0", + "fieldname": "add_serial_batch_bundle", + "fieldtype": "Button", + "label": "Add Serial / Batch Bundle" + }, + { + "depends_on": "eval:doc.use_serial_batch_fields === 0", + "fieldname": "add_serial_batch_for_rejected_qty", + "fieldtype": "Button", + "label": "Add Serial / Batch No (Rejected Qty)" } ], "idx": 1, "istable": 1, "links": [], +<<<<<<< HEAD "modified": "2024-03-07 11:43:38.954262", +======= + "modified": "2024-03-29 15:42:43.425544", +>>>>>>> d73b1f3e6a (fix: button to select serial / batch bundle in the subcontracting receipt) "modified_by": "Administrator", "module": "Subcontracting", "name": "Subcontracting Receipt Item", diff --git a/erpnext/subcontracting/doctype/subcontracting_receipt_supplied_item/subcontracting_receipt_supplied_item.json b/erpnext/subcontracting/doctype/subcontracting_receipt_supplied_item/subcontracting_receipt_supplied_item.json index 957b6a2a654..f4109ad6d1c 100644 --- a/erpnext/subcontracting/doctype/subcontracting_receipt_supplied_item/subcontracting_receipt_supplied_item.json +++ b/erpnext/subcontracting/doctype/subcontracting_receipt_supplied_item/subcontracting_receipt_supplied_item.json @@ -25,6 +25,7 @@ "consumed_qty", "current_stock", "secbreak_3", + "add_serial_batch_bundle", "serial_and_batch_bundle", "use_serial_batch_fields", "col_break4", @@ -224,12 +225,22 @@ { "fieldname": "column_break_qibi", "fieldtype": "Column Break" + }, + { + "depends_on": "eval:doc.use_serial_batch_fields === 0", + "fieldname": "add_serial_batch_bundle", + "fieldtype": "Button", + "label": "Add Serial / Batch Bundle" } ], "idx": 1, "istable": 1, "links": [], +<<<<<<< HEAD "modified": "2024-02-04 16:32:17.534162", +======= + "modified": "2024-03-30 10:26:27.237371", +>>>>>>> d73b1f3e6a (fix: button to select serial / batch bundle in the subcontracting receipt) "modified_by": "Administrator", "module": "Subcontracting", "name": "Subcontracting Receipt Supplied Item",