Merge pull request #21375 from marination/commonify-warehouse-autofill

chore: Commonify auto-filling warehouses in child tables
This commit is contained in:
Deepesh Garg
2020-05-03 20:33:45 +05:30
committed by GitHub
6 changed files with 28 additions and 55 deletions

View File

@@ -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) {

View File

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