mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-13 06:31:48 +00:00
refactor: move new-doc route options to StockController
set_route_options_for_new_doc lived in TransactionController, so doctypes
extending StockController directly (Stock Reconciliation, Stock Entry) missed
the Batch/SABB prefill or duplicated it locally. Move it to StockController
and call it from onload_post_render so all descendants inherit it.
- Batch quick entry from Stock Reconciliation items now prefills Item
- SABB route options unified: warehouse || s_warehouse || t_warehouse,
so transaction doctypes now also prefill warehouse
- Stock Entry's duplicate handler removed; its onload_post_render now
calls super
(cherry picked from commit 551559e804)
This commit is contained in:
@@ -11,6 +11,36 @@ erpnext.stock.StockController = class StockController extends frappe.ui.form.Con
|
||||
}
|
||||
}
|
||||
|
||||
onload_post_render() {
|
||||
this.set_route_options_for_new_doc();
|
||||
}
|
||||
|
||||
set_route_options_for_new_doc() {
|
||||
// While creating a Batch or Serial and Batch Bundle from the link
|
||||
// field, copy details from the line item to the new form
|
||||
if (!this.frm.fields_dict.items) return;
|
||||
|
||||
let batch_no_field = this.frm.get_docfield("items", "batch_no");
|
||||
if (batch_no_field) {
|
||||
batch_no_field.get_route_options_for_new_doc = (row) => {
|
||||
return {
|
||||
item: row.doc.item_code,
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
let sbb_field = this.frm.get_docfield("items", "serial_and_batch_bundle");
|
||||
if (sbb_field) {
|
||||
sbb_field.get_route_options_for_new_doc = (row) => {
|
||||
return {
|
||||
item_code: row.doc.item_code,
|
||||
warehouse: row.doc.warehouse || row.doc.s_warehouse || row.doc.t_warehouse,
|
||||
voucher_type: this.frm.doc.doctype,
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
barcode(doc, cdt, cdn) {
|
||||
let row = locals[cdt][cdn];
|
||||
if (row.barcode) {
|
||||
|
||||
@@ -649,34 +649,6 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
|
||||
erpnext.toggle_serial_batch_fields(this.frm);
|
||||
}
|
||||
|
||||
set_route_options_for_new_doc() {
|
||||
// While creating the batch from the link field, copy item from line item to batch form
|
||||
|
||||
if (this.frm.fields_dict["items"].grid.get_field("batch_no")) {
|
||||
let batch_no_field = this.frm.get_docfield("items", "batch_no");
|
||||
if (batch_no_field) {
|
||||
batch_no_field.get_route_options_for_new_doc = function (row) {
|
||||
return {
|
||||
item: row.doc.item_code,
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// While creating the SABB from the link field, copy item, doctype from line item to SABB form
|
||||
if (this.frm.fields_dict["items"].grid.get_field("serial_and_batch_bundle")) {
|
||||
let sbb_field = this.frm.get_docfield("items", "serial_and_batch_bundle");
|
||||
if (sbb_field) {
|
||||
sbb_field.get_route_options_for_new_doc = (row) => {
|
||||
return {
|
||||
item_code: row.doc.item_code,
|
||||
voucher_type: this.frm.doc.doctype,
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
scan_barcode() {
|
||||
frappe.flags.dialog_set = false;
|
||||
this.barcode_scanner.process_scan();
|
||||
|
||||
@@ -569,8 +569,6 @@ frappe.ui.form.on("Stock Entry", {
|
||||
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
|
||||
}
|
||||
|
||||
frm.events.set_route_options_for_new_doc(frm);
|
||||
|
||||
frm.set_df_property(
|
||||
"items",
|
||||
"cannot_add_rows",
|
||||
@@ -583,28 +581,6 @@ frappe.ui.form.on("Stock Entry", {
|
||||
);
|
||||
},
|
||||
|
||||
set_route_options_for_new_doc(frm) {
|
||||
let batch_no_field = frm.get_docfield("items", "batch_no");
|
||||
if (batch_no_field) {
|
||||
batch_no_field.get_route_options_for_new_doc = function (row) {
|
||||
return {
|
||||
item: row.doc.item_code,
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
let sbb_field = frm.get_docfield("items", "serial_and_batch_bundle");
|
||||
if (sbb_field) {
|
||||
sbb_field.get_route_options_for_new_doc = (row) => {
|
||||
return {
|
||||
item_code: row.doc.item_code,
|
||||
voucher_type: frm.doc.doctype,
|
||||
warehouse: row.doc.s_warehouse || row.doc.t_warehouse,
|
||||
};
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
get_items_from_transit_entry: function (frm) {
|
||||
if (frm.doc.docstatus === 0 && !frm.doc.subcontracting_inward_order) {
|
||||
frm.add_custom_button(
|
||||
@@ -1312,6 +1288,7 @@ erpnext.stock.StockEntry = class StockEntry extends erpnext.stock.StockControlle
|
||||
}
|
||||
|
||||
onload_post_render() {
|
||||
super.onload_post_render();
|
||||
var me = this;
|
||||
if (me.frm.doc.__islocal && me.frm.doc.company && !me.frm.doc.amended_from) {
|
||||
me.company();
|
||||
|
||||
@@ -46,17 +46,6 @@ frappe.ui.form.on("Stock Reconciliation", {
|
||||
};
|
||||
});
|
||||
|
||||
let sbb_field = frm.get_docfield("items", "serial_and_batch_bundle");
|
||||
if (sbb_field) {
|
||||
sbb_field.get_route_options_for_new_doc = (row) => {
|
||||
return {
|
||||
item_code: row.doc.item_code,
|
||||
warehouse: row.doc.warehouse,
|
||||
voucher_type: frm.doc.doctype,
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
if (frm.doc.company) {
|
||||
erpnext.queries.setup_queries(frm, "Warehouse", function () {
|
||||
return erpnext.queries.warehouse(frm.doc);
|
||||
|
||||
Reference in New Issue
Block a user