Skip to content

Commit

Permalink
fix(ux): move get_route_options_for_new_doc to refresh (#37096)
Browse files Browse the repository at this point in the history
fix: move `get_route_options_for_new_doc` to `refresh`
  • Loading branch information
FHenry authored Sep 16, 2023
1 parent fc01668 commit 34bb64e
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 110 deletions.
20 changes: 10 additions & 10 deletions erpnext/assets/doctype/asset_repair/asset_repair.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,6 @@ frappe.ui.form.on('Asset Repair', {
}
}
});

let sbb_field = frm.get_docfield('stock_items', 'serial_and_batch_bundle');
if (sbb_field) {
sbb_field.get_route_options_for_new_doc = (row) => {
return {
'item_code': row.doc.item_code,
'voucher_type': frm.doc.doctype,
}
};
}
},

refresh: function(frm) {
Expand All @@ -61,6 +51,16 @@ frappe.ui.form.on('Asset Repair', {
frappe.set_route("query-report", "General Ledger");
});
}

let sbb_field = frm.get_docfield('stock_items', 'serial_and_batch_bundle');
if (sbb_field) {
sbb_field.get_route_options_for_new_doc = (row) => {
return {
'item_code': row.doc.item_code,
'voucher_type': frm.doc.doctype,
}
};
}
},

repair_status: (frm) => {
Expand Down
22 changes: 11 additions & 11 deletions erpnext/manufacturing/doctype/job_card/job_card.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,6 @@ frappe.ui.form.on('Job Card', {
}
});

let sbb_field = frm.get_docfield('serial_and_batch_bundle');
if (sbb_field) {
sbb_field.get_route_options_for_new_doc = () => {
return {
'item_code': frm.doc.production_item,
'warehouse': frm.doc.wip_warehouse,
'voucher_type': frm.doc.doctype,
}
};
}

frm.set_indicator_formatter('sub_operation',
function(doc) {
if (doc.status == "Pending") {
Expand Down Expand Up @@ -124,6 +113,17 @@ frappe.ui.form.on('Job Card', {
}
});
}

let sbb_field = frm.get_docfield('serial_and_batch_bundle');
if (sbb_field) {
sbb_field.get_route_options_for_new_doc = () => {
return {
'item_code': frm.doc.production_item,
'warehouse': frm.doc.wip_warehouse,
'voucher_type': frm.doc.doctype,
}
};
}
},

setup_quality_inspection: function(frm) {
Expand Down
41 changes: 22 additions & 19 deletions erpnext/public/js/controllers/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,6 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
}
}
});

let sbb_field = this.frm.get_docfield('items', 'serial_and_batch_bundle');
if (sbb_field) {
sbb_field.get_route_options_for_new_doc = (row) => {
return {
'item_code': row.doc.item_code,
}
};
}
}

if(
Expand Down Expand Up @@ -207,15 +198,6 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
});
}

let batch_no_field = this.frm.get_docfield("items", "batch_no");
if (batch_no_field) {
batch_no_field.get_route_options_for_new_doc = function(row) {
return {
"item": row.doc.item_code
}
};
}

if (this.frm.fields_dict["items"].grid.get_field('blanket_order')) {
this.frm.set_query("blanket_order", "items", function(doc, cdt, cdn) {
var item = locals[cdt][cdn];
Expand Down Expand Up @@ -268,6 +250,28 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
}
]);
}

if(this.frm.fields_dict['items'].grid.get_field('serial_and_batch_bundle')) {
let sbb_field = this.frm.get_docfield('items', 'serial_and_batch_bundle');
if (sbb_field) {
sbb_field.get_route_options_for_new_doc = (row) => {
return {
'item_code': row.doc.item_code,
}
};
}
}

if(this.frm.fields_dict['items'].grid.get_field('batch_no')) {
let batch_no_field = this.frm.get_docfield('items', 'batch_no');
if (batch_no_field) {
batch_no_field.get_route_options_for_new_doc = function(row) {
return {
'item': row.doc.item_code
}
};
}
}
}

is_return() {
Expand Down Expand Up @@ -358,7 +362,6 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
}

refresh() {

erpnext.toggle_naming_series();
erpnext.hide_company();
this.set_dynamic_labels();
Expand Down
16 changes: 8 additions & 8 deletions erpnext/selling/doctype/installation_note/installation_note.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ frappe.ui.form.on('Installation Note', {
}
}
});
},
onload: function(frm) {
if(!frm.doc.status) {
frm.set_value({ status:'Draft'});
}
if(frm.doc.__islocal) {
frm.set_value({inst_date: frappe.datetime.get_today()});
}

let sbb_field = frm.get_docfield('items', 'serial_and_batch_bundle');
if (sbb_field) {
Expand All @@ -29,14 +37,6 @@ frappe.ui.form.on('Installation Note', {
};
}
},
onload: function(frm) {
if(!frm.doc.status) {
frm.set_value({ status:'Draft'});
}
if(frm.doc.__islocal) {
frm.set_value({inst_date: frappe.datetime.get_today()});
}
},
customer: function(frm) {
erpnext.utils.get_party_details(frm);
},
Expand Down
10 changes: 5 additions & 5 deletions erpnext/selling/doctype/quotation/quotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ frappe.ui.form.on('Quotation', {
}
}
});
},

refresh: function(frm) {
frm.trigger("set_label");
frm.trigger("set_dynamic_field_label");

let sbb_field = frm.get_docfield('packed_items', 'serial_and_batch_bundle');
if (sbb_field) {
Expand All @@ -61,11 +66,6 @@ frappe.ui.form.on('Quotation', {
}
},

refresh: function(frm) {
frm.trigger("set_label");
frm.trigger("set_dynamic_field_label");
},

quotation_to: function(frm) {
frm.trigger("set_label");
frm.trigger("toggle_reqd_lead_customer");
Expand Down
22 changes: 11 additions & 11 deletions erpnext/stock/doctype/pick_list/pick_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,6 @@ frappe.ui.form.on('Pick List', {
}
}
});

let sbb_field = frm.get_docfield('locations', 'serial_and_batch_bundle');
if (sbb_field) {
sbb_field.get_route_options_for_new_doc = (row) => {
return {
'item_code': row.doc.item_code,
'warehouse': row.doc.warehouse,
'voucher_type': frm.doc.doctype,
}
};
}
},
set_item_locations:(frm, save) => {
if (!(frm.doc.locations && frm.doc.locations.length)) {
Expand Down Expand Up @@ -132,6 +121,17 @@ frappe.ui.form.on('Pick List', {
}
}
}

let sbb_field = frm.get_docfield('locations', 'serial_and_batch_bundle');
if (sbb_field) {
sbb_field.get_route_options_for_new_doc = (row) => {
return {
'item_code': row.doc.item_code,
'warehouse': row.doc.warehouse,
'voucher_type': frm.doc.doctype,
}
};
}
},
work_order: (frm) => {
frappe.db.get_value('Work Order',
Expand Down
19 changes: 10 additions & 9 deletions erpnext/stock/doctype/stock_entry/stock_entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,6 @@ frappe.ui.form.on('Stock Entry', {
}
});

let sbb_field = frm.get_docfield('items', 'serial_and_batch_bundle');
if (sbb_field) {
sbb_field.get_route_options_for_new_doc = (row) => {
return {
'item_code': row.doc.item_code,
'voucher_type': frm.doc.doctype,
}
};
}

frm.add_fetch("bom_no", "inspection_required", "inspection_required");
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
Expand Down Expand Up @@ -362,6 +353,16 @@ frappe.ui.form.on('Stock Entry', {
if(!check_should_not_attach_bom_items(frm.doc.bom_no)) {
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
}

let sbb_field = frm.get_docfield('items', 'serial_and_batch_bundle');
if (sbb_field) {
sbb_field.get_route_options_for_new_doc = (row) => {
return {
'item_code': row.doc.item_code,
'voucher_type': frm.doc.doctype,
}
};
}
},

get_items_from_transit_entry: function(frm) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ frappe.ui.form.on('Subcontracting Receipt', {
}

frm.trigger('setup_quality_inspection');
frm.trigger('set_route_options_for_new_doc');
},

set_warehouse: (frm) => {
Expand All @@ -87,6 +88,23 @@ frappe.ui.form.on('Subcontracting Receipt', {
set_warehouse_in_children(frm.doc.items, 'rejected_warehouse', frm.doc.rejected_warehouse);
},

get_scrap_items: (frm) => {
frappe.call({
doc: frm.doc,
method: 'get_scrap_items',
args: {
recalculate_rate: true
},
freeze: true,
freeze_message: __('Getting Scrap Items'),
callback: (r) => {
if (!r.exc) {
frm.refresh();
}
}
});
},

set_queries: (frm) => {
frm.set_query('set_warehouse', () => {
return {
Expand Down Expand Up @@ -173,7 +191,28 @@ frappe.ui.form.on('Subcontracting Receipt', {
}
}
});
},

get_serial_and_batch_bundle_filters: (doc, cdt, cdn) => {
let row = locals[cdt][cdn];
return {
filters: {
'item_code': row.item_code,
'voucher_type': doc.doctype,
'voucher_no': ['in', [doc.name, '']],
'is_cancelled': 0,
}
}
},

setup_quality_inspection: (frm) => {
if (!frm.is_new() && frm.doc.docstatus === 0 && !frm.doc.is_return) {
let transaction_controller = new erpnext.TransactionController({ frm: frm });
transaction_controller.setup_quality_inspection();
}
},

set_route_options_for_new_doc: (frm) => {
let batch_no_field = frm.get_docfield('items', 'batch_no');
if (batch_no_field) {
batch_no_field.get_route_options_for_new_doc = (row) => {
Expand Down Expand Up @@ -213,42 +252,6 @@ frappe.ui.form.on('Subcontracting Receipt', {
}
}
},

get_serial_and_batch_bundle_filters: (doc, cdt, cdn) => {
let row = locals[cdt][cdn];
return {
filters: {
'item_code': row.item_code,
'voucher_type': doc.doctype,
'voucher_no': ['in', [doc.name, '']],
'is_cancelled': 0,
}
}
},

setup_quality_inspection: (frm) => {
if (!frm.is_new() && frm.doc.docstatus === 0 && !frm.doc.is_return) {
let transaction_controller = new erpnext.TransactionController({ frm: frm });
transaction_controller.setup_quality_inspection();
}
},

get_scrap_items: (frm) => {
frappe.call({
doc: frm.doc,
method: 'get_scrap_items',
args: {
recalculate_rate: true
},
freeze: true,
freeze_message: __('Getting Scrap Items'),
callback: (r) => {
if (!r.exc) {
frm.refresh();
}
}
});
},
});

frappe.ui.form.on('Landed Cost Taxes and Charges', {
Expand Down Expand Up @@ -303,4 +306,4 @@ let set_missing_values = (frm) => {
if (!r.exc) frm.refresh();
},
});
}
}

0 comments on commit 34bb64e

Please sign in to comment.