fix: fall back to the company in-transit warehouse

set_transit_warehouse re-tested from_warehouse inside a guard that
already requires it, so the Company branch of its ternary was
unreachable: with no default on the source warehouse the field stayed
empty and Company.default_in_transit_warehouse was silently ignored.
Try the warehouse's default first, then the company's.
This commit is contained in:
Mihir Kandoi
2026-07-17 13:05:29 +05:30
parent 9fdb6dd875
commit 920e64ded0

View File

@@ -943,11 +943,16 @@ frappe.ui.form.on("Stock Entry", {
!frm.doc.to_warehouse && !frm.doc.to_warehouse &&
frm.doc.from_warehouse frm.doc.from_warehouse
) { ) {
let dt = frm.doc.from_warehouse ? "Warehouse" : "Company"; // prefer the source warehouse's in-transit default, then the company's
let dn = frm.doc.from_warehouse ? frm.doc.from_warehouse : frm.doc.company; frappe.db.get_value("Warehouse", frm.doc.from_warehouse, "default_in_transit_warehouse", (r) => {
frappe.db.get_value(dt, dn, "default_in_transit_warehouse", (r) => {
if (r.default_in_transit_warehouse) { if (r.default_in_transit_warehouse) {
frm.set_value("to_warehouse", r.default_in_transit_warehouse); frm.set_value("to_warehouse", r.default_in_transit_warehouse);
} else if (frm.doc.company) {
frappe.db.get_value("Company", frm.doc.company, "default_in_transit_warehouse", (res) => {
if (res.default_in_transit_warehouse) {
frm.set_value("to_warehouse", res.default_in_transit_warehouse);
}
});
} }
}); });
} }