fix: button to select serial / batch bundle in the subcontracting receipt

This commit is contained in:
Rohit Waghchaure
2024-03-30 10:46:56 +05:30
parent 8e522183bc
commit d73b1f3e6a
6 changed files with 134 additions and 7 deletions

View File

@@ -748,12 +748,12 @@ def get_serial_and_batch_bundle(child, parent):
"item_code": child.item_code, "item_code": child.item_code,
"warehouse": child.warehouse, "warehouse": child.warehouse,
"voucher_type": parent.doctype, "voucher_type": parent.doctype,
"voucher_no": parent.name, "voucher_no": parent.name if parent.docstatus < 2 else None,
"voucher_detail_no": child.name, "voucher_detail_no": child.name,
"posting_date": parent.posting_date, "posting_date": parent.posting_date,
"posting_time": parent.posting_time, "posting_time": parent.posting_time,
"qty": child.qty, "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, "company": parent.company,
"do_not_submit": "True", "do_not_submit": "True",
} }

View File

@@ -386,7 +386,7 @@ erpnext.buying = {
if (r.message && (r.message.has_batch_no || r.message.has_serial_no)) { if (r.message && (r.message.has_batch_no || r.message.has_serial_no)) {
item.has_serial_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.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; item.is_rejected = true;
new erpnext.SerialBatchPackageSelector( new erpnext.SerialBatchPackageSelector(

View File

@@ -844,6 +844,9 @@ class SerialBatchCreation:
if not doc.get("entries"): if not doc.get("entries"):
return frappe._dict({}) 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() doc.save()
self.validate_qty(doc) self.validate_qty(doc)

View File

@@ -335,12 +335,115 @@ frappe.ui.form.on("Subcontracting Receipt Item", {
items_remove: (frm) => { items_remove: (frm) => {
set_missing_values(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", { frappe.ui.form.on("Subcontracting Receipt Supplied Item", {
consumed_qty(frm) { consumed_qty(frm) {
set_missing_values(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) => { let set_warehouse_in_children = (child_table, warehouse_field, warehouse) => {

View File

@@ -47,9 +47,11 @@
"schedule_date", "schedule_date",
"reference_name", "reference_name",
"section_break_45", "section_break_45",
"add_serial_batch_bundle",
"serial_and_batch_bundle", "serial_and_batch_bundle",
"use_serial_batch_fields", "use_serial_batch_fields",
"col_break5", "col_break5",
"add_serial_batch_for_rejected_qty",
"rejected_serial_and_batch_bundle", "rejected_serial_and_batch_bundle",
"section_break_jshh", "section_break_jshh",
"serial_no", "serial_no",
@@ -563,12 +565,24 @@
{ {
"fieldname": "column_break_henr", "fieldname": "column_break_henr",
"fieldtype": "Column Break" "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, "idx": 1,
"istable": 1, "istable": 1,
"links": [], "links": [],
"modified": "2024-03-27 13:10:47.165943", "modified": "2024-03-29 15:42:43.425544",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Subcontracting", "module": "Subcontracting",
"name": "Subcontracting Receipt Item", "name": "Subcontracting Receipt Item",
@@ -576,7 +590,7 @@
"owner": "Administrator", "owner": "Administrator",
"permissions": [], "permissions": [],
"quick_entry": 1, "quick_entry": 1,
"sort_field": "creation", "sort_field": "modified",
"sort_order": "DESC", "sort_order": "DESC",
"states": [] "states": []
} }

View File

@@ -25,6 +25,7 @@
"consumed_qty", "consumed_qty",
"current_stock", "current_stock",
"secbreak_3", "secbreak_3",
"add_serial_batch_bundle",
"serial_and_batch_bundle", "serial_and_batch_bundle",
"use_serial_batch_fields", "use_serial_batch_fields",
"col_break4", "col_break4",
@@ -224,19 +225,25 @@
{ {
"fieldname": "column_break_qibi", "fieldname": "column_break_qibi",
"fieldtype": "Column Break" "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, "idx": 1,
"istable": 1, "istable": 1,
"links": [], "links": [],
"modified": "2024-03-27 13:10:47.405161", "modified": "2024-03-30 10:26:27.237371",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Subcontracting", "module": "Subcontracting",
"name": "Subcontracting Receipt Supplied Item", "name": "Subcontracting Receipt Supplied Item",
"naming_rule": "Autoincrement", "naming_rule": "Autoincrement",
"owner": "Administrator", "owner": "Administrator",
"permissions": [], "permissions": [],
"sort_field": "creation", "sort_field": "modified",
"sort_order": "DESC", "sort_order": "DESC",
"states": [], "states": [],
"track_changes": 1 "track_changes": 1