diff --git a/erpnext/controllers/selling_controller.py b/erpnext/controllers/selling_controller.py index ec2e35949ae5beaf3bb8295b37c699eabced67d4..002793b56f9b0b7c1c6ff97f5e4d2bec619daab4 100644 --- a/erpnext/controllers/selling_controller.py +++ b/erpnext/controllers/selling_controller.py @@ -790,12 +790,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 3e8cd85cf1dad349825fcff8562fb8289de8bd03..6bb10dc962f3c5b8754780b9b0183c62490a0626 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 61fef7db680484439726541f84b5e12d3f4a9b4a..d657e9a8607e6b034a52c33f532699da5e480572 100644 --- a/erpnext/stock/serial_batch_bundle.py +++ b/erpnext/stock/serial_batch_bundle.py @@ -866,6 +866,11 @@ 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 05357999a1b5e40fd10bfdf93c711b1d09e0eded..a453bfe356ffb7156dcd6d9c002fe83cc87324c8 100644 --- a/erpnext/subcontracting/doctype/subcontracting_receipt/subcontracting_receipt.js +++ b/erpnext/subcontracting/doctype/subcontracting_receipt/subcontracting_receipt.js @@ -311,12 +311,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 27341b8455a0aacfdfd892a692fbd78a255b62b6..75e263e2c1cb8020aaa0e653b1ffdd15050780a1 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,24 @@ { "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": [], - "modified": "2024-03-07 11:43:38.954262", + "modified": "2024-03-29 15:42:43.425544", "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 e09cd553074a4415641afca768652ff445c81bfd..e1927a5467a0d3a8afb9738cce2bc4d814221fe1 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,18 @@ { "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": [], - "modified": "2024-02-04 16:32:17.534162", + "modified": "2024-03-30 10:26:27.237371", "modified_by": "Administrator", "module": "Subcontracting", "name": "Subcontracting Receipt Supplied Item",