chore: Commonify autofilling warehouses in child tables

This commit is contained in:
marination
2020-04-23 00:18:21 +05:30
parent eaa956b994
commit 8a30cb2565
6 changed files with 29 additions and 56 deletions

View File

@@ -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);
});