chore: Commonify autofilling warehouses in child tables
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -1889,21 +1889,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) {
|
||||
let doctype = child_table[0].doctype;
|
||||
if (warehouse) {
|
||||
$.each(child_table || [], function(i, item) {
|
||||
frappe.model.set_value(doctype, item.name, warehouse_field, warehouse);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user