Merge pull request #21375 from marination/commonify-warehouse-autofill
chore: Commonify auto-filling warehouses in child tables
This commit is contained in:
commit
6df581f78b
@ -122,12 +122,8 @@ frappe.ui.form.on("Work Order", {
|
||||
},
|
||||
|
||||
source_warehouse: function(frm) {
|
||||
if (frm.doc.source_warehouse) {
|
||||
frm.doc.required_items.forEach(d => {
|
||||
frappe.model.set_value(d.doctype, d.name,
|
||||
"source_warehouse", frm.doc.source_warehouse);
|
||||
});
|
||||
}
|
||||
let transaction_controller = new erpnext.TransactionController();
|
||||
transaction_controller.autofill_warehouse(frm.doc.required_items, "source_warehouse", frm.doc.source_warehouse);
|
||||
},
|
||||
|
||||
refresh: function(frm) {
|
||||
|
@ -253,6 +253,13 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
|
||||
}
|
||||
},
|
||||
|
||||
rejected_warehouse: function(doc, cdt) {
|
||||
// trigger autofill_warehouse only if parent rejected_warehouse field is triggered
|
||||
if (["Purchase Invoice", "Purchase Receipt"].includes(cdt)) {
|
||||
this.autofill_warehouse(doc.items, "rejected_warehouse", doc.rejected_warehouse);
|
||||
}
|
||||
},
|
||||
|
||||
category: function(doc, cdt, cdn) {
|
||||
// should be the category field of tax table
|
||||
if(cdt != doc.doctype) {
|
||||
|
@ -1903,21 +1903,16 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
||||
},
|
||||
|
||||
set_reserve_warehouse: function() {
|
||||
this.autofill_warehouse("reserve_warehouse");
|
||||
this.autofill_warehouse(this.frm.doc.supplied_items, "reserve_warehouse", this.frm.doc.set_reserve_warehouse);
|
||||
},
|
||||
|
||||
set_warehouse: function() {
|
||||
this.autofill_warehouse("warehouse");
|
||||
this.autofill_warehouse(this.frm.doc.items, "warehouse", this.frm.doc.set_warehouse);
|
||||
},
|
||||
|
||||
autofill_warehouse : function (warehouse_field) {
|
||||
// set warehouse in all child table rows
|
||||
var me = this;
|
||||
let warehouse = (warehouse_field === "warehouse") ? me.frm.doc.set_warehouse : me.frm.doc.set_reserve_warehouse;
|
||||
let child_table = (warehouse_field === "warehouse") ? me.frm.doc.items : me.frm.doc.supplied_items;
|
||||
let doctype = (warehouse_field === "warehouse") ? (me.frm.doctype + " Item") : (me.frm.doctype + " Item Supplied");
|
||||
|
||||
if(warehouse) {
|
||||
autofill_warehouse : function (child_table, warehouse_field, warehouse) {
|
||||
if (warehouse && child_table && child_table.length) {
|
||||
let doctype = child_table[0].doctype;
|
||||
$.each(child_table || [], function(i, item) {
|
||||
frappe.model.set_value(doctype, item.name, warehouse_field, warehouse);
|
||||
});
|
||||
|
@ -429,7 +429,7 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
|
||||
if (doc.has_serial_no && doc.serial_no) {
|
||||
args['serial_no'] = doc.serial_no
|
||||
}
|
||||
|
||||
|
||||
return frappe.call({
|
||||
method: 'erpnext.stock.doctype.batch.batch.get_batch_no',
|
||||
args: args,
|
||||
|
@ -101,17 +101,6 @@ frappe.ui.form.on("Delivery Note", {
|
||||
})
|
||||
}, __('Create'));
|
||||
}
|
||||
},
|
||||
|
||||
to_warehouse: function(frm) {
|
||||
if(frm.doc.to_warehouse) {
|
||||
["items", "packed_items"].forEach(doctype => {
|
||||
frm.doc[doctype].forEach(d => {
|
||||
frappe.model.set_value(d.doctype, d.name,
|
||||
"target_warehouse", frm.doc.to_warehouse);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@ -287,6 +276,14 @@ erpnext.stock.DeliveryNoteController = erpnext.selling.SellingController.extend(
|
||||
frappe.ui.form.is_saving = false;
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
to_warehouse: function() {
|
||||
let packed_items_table = this.frm.doc["packed_items"];
|
||||
this.autofill_warehouse(this.frm.doc["items"], "target_warehouse", this.frm.doc.to_warehouse);
|
||||
if (packed_items_table && packed_items_table.length) {
|
||||
this.autofill_warehouse(packed_items_table, "target_warehouse", this.frm.doc.to_warehouse);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -875,39 +875,17 @@ erpnext.stock.StockEntry = erpnext.stock.StockController.extend({
|
||||
if(!row.t_warehouse) row.t_warehouse = this.frm.doc.to_warehouse;
|
||||
},
|
||||
|
||||
source_mandatory: ["Material Issue", "Material Transfer", "Send to Subcontractor",
|
||||
"Material Transfer for Manufacture", "Send to Warehouse", "Receive at Warehouse"],
|
||||
target_mandatory: ["Material Receipt", "Material Transfer", "Send to Subcontractor",
|
||||
"Material Transfer for Manufacture", "Send to Warehouse", "Receive at Warehouse"],
|
||||
|
||||
from_warehouse: function(doc) {
|
||||
var me = this;
|
||||
this.set_warehouse_if_different("s_warehouse", doc.from_warehouse, function(row) {
|
||||
return me.source_mandatory.indexOf(me.frm.doc.purpose)!==-1;
|
||||
});
|
||||
this.set_warehouse_in_children(doc.items, "s_warehouse", doc.from_warehouse);
|
||||
},
|
||||
|
||||
to_warehouse: function(doc) {
|
||||
var me = this;
|
||||
this.set_warehouse_if_different("t_warehouse", doc.to_warehouse, function(row) {
|
||||
return me.target_mandatory.indexOf(me.frm.doc.purpose)!==-1;
|
||||
});
|
||||
this.set_warehouse_in_children(doc.items, "t_warehouse", doc.to_warehouse);
|
||||
},
|
||||
|
||||
set_warehouse_if_different: function(fieldname, value, condition) {
|
||||
var changed = false;
|
||||
for (var i=0, l=(this.frm.doc.items || []).length; i<l; i++) {
|
||||
var row = this.frm.doc.items[i];
|
||||
if (row[fieldname] != value) {
|
||||
if (condition && !condition(row)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
frappe.model.set_value(row.doctype, row.name, fieldname, value, "Link");
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
refresh_field("items");
|
||||
set_warehouse_in_children: function(child_table, warehouse_field, warehouse) {
|
||||
let transaction_controller = new erpnext.TransactionController();
|
||||
transaction_controller.autofill_warehouse(child_table, warehouse_field, warehouse);
|
||||
},
|
||||
|
||||
items_on_form_rendered: function(doc, grid_row) {
|
||||
|
Loading…
Reference in New Issue
Block a user