Skip to content

Commit

Permalink
Merge pull request #40783 from rohitwaghchaure/fixed-provision-to-add…
Browse files Browse the repository at this point in the history
…-serial-batch-bundle-in-subcontracting-receipt

fix: button to select serial / batch bundle in the subcontracting receipt
  • Loading branch information
rohitwaghchaure authored Mar 30, 2024
2 parents 679aea6 + d73b1f3 commit 3231ee4
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 7 deletions.
4 changes: 2 additions & 2 deletions erpnext/controllers/selling_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,12 +748,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",
}
Expand Down
2 changes: 1 addition & 1 deletion erpnext/public/js/controllers/buying.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 3 additions & 0 deletions erpnext/stock/serial_batch_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,9 @@ def make_serial_and_batch_bundle(self):
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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -563,20 +565,32 @@
{
"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-27 13:10:47.165943",
"modified": "2024-03-29 15:42:43.425544",
"modified_by": "Administrator",
"module": "Subcontracting",
"name": "Subcontracting Receipt Item",
"naming_rule": "Random",
"owner": "Administrator",
"permissions": [],
"quick_entry": 1,
"sort_field": "creation",
"sort_field": "modified",
"sort_order": "DESC",
"states": []
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"consumed_qty",
"current_stock",
"secbreak_3",
"add_serial_batch_bundle",
"serial_and_batch_bundle",
"use_serial_batch_fields",
"col_break4",
Expand Down Expand Up @@ -224,19 +225,25 @@
{
"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-03-27 13:10:47.405161",
"modified": "2024-03-30 10:26:27.237371",
"modified_by": "Administrator",
"module": "Subcontracting",
"name": "Subcontracting Receipt Supplied Item",
"naming_rule": "Autoincrement",
"owner": "Administrator",
"permissions": [],
"sort_field": "creation",
"sort_field": "modified",
"sort_order": "DESC",
"states": [],
"track_changes": 1
Expand Down

0 comments on commit 3231ee4

Please sign in to comment.