fix(minor): fix dynamically changing grid properties
This commit is contained in:
		
							parent
							
								
									34d00772e7
								
							
						
					
					
						commit
						65f25c27b3
					
				| @ -42,10 +42,7 @@ let add_fields_to_mapping_table = function (frm) { | ||||
| 		}); | ||||
| 	}); | ||||
| 
 | ||||
| 	frappe.meta.get_docfield("Bank Transaction Mapping", "bank_transaction_field", | ||||
| 		frm.doc.name).options = options; | ||||
| 
 | ||||
| 	frm.fields_dict.bank_transaction_mapping.grid.refresh(); | ||||
| 	frm.fields_dict.bank_transaction_mapping.grid.update_docfield_property('frm.fields_dict.bank_transaction_mapping.grid', 'options', options); | ||||
| }; | ||||
| 
 | ||||
| erpnext.integrations.refreshPlaidLink = class refreshPlaidLink { | ||||
|  | ||||
| @ -327,18 +327,16 @@ erpnext.accounts.JournalEntry = frappe.ui.form.Controller.extend({ | ||||
| 	}, | ||||
| 
 | ||||
| 	setup_balance_formatter: function() { | ||||
| 		var me = this; | ||||
| 		$.each(["balance", "party_balance"], function(i, field) { | ||||
| 			var df = frappe.meta.get_docfield("Journal Entry Account", field, me.frm.doc.name); | ||||
| 			df.formatter = function(value, df, options, doc) { | ||||
| 				var currency = frappe.meta.get_field_currency(df, doc); | ||||
| 				var dr_or_cr = value ? ('<label>' + (value > 0.0 ? __("Dr") : __("Cr")) + '</label>') : ""; | ||||
| 				return "<div style='text-align: right'>" | ||||
| 					+ ((value==null || value==="") ? "" : format_currency(Math.abs(value), currency)) | ||||
| 					+ " " + dr_or_cr | ||||
| 					+ "</div>"; | ||||
| 			} | ||||
| 		}) | ||||
| 		const formatter = function(value, df, options, doc) { | ||||
| 			var currency = frappe.meta.get_field_currency(df, doc); | ||||
| 			var dr_or_cr = value ? ('<label>' + (value > 0.0 ? __("Dr") : __("Cr")) + '</label>') : ""; | ||||
| 			return "<div style='text-align: right'>" | ||||
| 				+ ((value==null || value==="") ? "" : format_currency(Math.abs(value), currency)) | ||||
| 				+ " " + dr_or_cr | ||||
| 				+ "</div>"; | ||||
| 		} | ||||
| 		this.frm.fields_dict.accounts.grid.update_docfield_property('balance', 'formatter', formatter); | ||||
| 		this.frm.fields_dict.accounts.grid.update_docfield_property('party_balance', 'formatter', formatter); | ||||
| 	}, | ||||
| 
 | ||||
| 	reference_name: function(doc, cdt, cdn) { | ||||
| @ -431,15 +429,6 @@ cur_frm.cscript.validate = function(doc,cdt,cdn) { | ||||
| 	cur_frm.cscript.update_totals(doc); | ||||
| } | ||||
| 
 | ||||
| cur_frm.cscript.select_print_heading = function(doc,cdt,cdn){ | ||||
| 	if(doc.select_print_heading){ | ||||
| 		// print heading
 | ||||
| 		cur_frm.pformat.print_heading = doc.select_print_heading; | ||||
| 	} | ||||
| 	else | ||||
| 		cur_frm.pformat.print_heading = __("Journal Entry"); | ||||
| } | ||||
| 
 | ||||
| frappe.ui.form.on("Journal Entry Account", { | ||||
| 	party: function(frm, cdt, cdn) { | ||||
| 		var d = frappe.get_doc(cdt, cdn); | ||||
| @ -511,8 +500,11 @@ $.extend(erpnext.journal_entry, { | ||||
| 		}; | ||||
| 
 | ||||
| 		$.each(field_label_map, function (fieldname, label) { | ||||
| 			var df = frappe.meta.get_docfield("Journal Entry Account", fieldname, frm.doc.name); | ||||
| 			df.label = frm.doc.multi_currency ? (label + " in Account Currency") : label; | ||||
| 			frm.fields_dict.accounts.grid.update_docfield_property( | ||||
| 				fieldname, | ||||
| 				'label', | ||||
| 				frm.doc.multi_currency ? (label + " in Account Currency") : label | ||||
| 			); | ||||
| 		}) | ||||
| 	}, | ||||
| 
 | ||||
|  | ||||
| @ -234,8 +234,9 @@ erpnext.accounts.PaymentReconciliationController = frappe.ui.form.Controller.ext | ||||
| 		}); | ||||
| 
 | ||||
| 		if (invoices) { | ||||
| 			frappe.meta.get_docfield("Payment Reconciliation Payment", "invoice_number", | ||||
| 				me.frm.doc.name).options = "\n" + invoices.join("\n"); | ||||
| 			this.frm.fields_dict.payment.grid.update_docfield_property( | ||||
| 				'invoice_number', options, "\n" + invoices.join("\n") | ||||
| 			) | ||||
| 
 | ||||
| 			$.each(me.frm.doc.payments || [], function(i, p) { | ||||
| 				if(!in_list(invoices, cstr(p.invoice_number))) p.invoice_number = null; | ||||
|  | ||||
| @ -16,8 +16,13 @@ frappe.ui.form.on('POS Settings', { | ||||
| 				} | ||||
| 			}); | ||||
| 
 | ||||
| 			frappe.meta.get_docfield("POS Field", "fieldname", frm.doc.name).options = [""].concat(fields); | ||||
| 			frm.fields_dict.invoice_fields.grid.update_docfield_property( | ||||
| 				'fieldname', | ||||
| 				'options', | ||||
| 				[""].concat(fields) | ||||
| 			); | ||||
| 		}); | ||||
| 
 | ||||
| 	} | ||||
| }); | ||||
| 
 | ||||
|  | ||||
| @ -496,15 +496,6 @@ cur_frm.fields_dict['items'].grid.get_field('project').get_query = function(doc, | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| cur_frm.cscript.select_print_heading = function(doc,cdt,cdn){ | ||||
| 	if(doc.select_print_heading){ | ||||
| 		// print heading
 | ||||
| 		cur_frm.pformat.print_heading = doc.select_print_heading; | ||||
| 	} | ||||
| 	else | ||||
| 		cur_frm.pformat.print_heading = __("Purchase Invoice"); | ||||
| } | ||||
| 
 | ||||
| frappe.ui.form.on("Purchase Invoice", { | ||||
| 	setup: function(frm) { | ||||
| 		frm.custom_make_buttons = { | ||||
|  | ||||
| @ -1,9 +1,6 @@ | ||||
| // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
 | ||||
| // License: GNU General Public License v3. See license.txt
 | ||||
| 
 | ||||
| // print heading
 | ||||
| cur_frm.pformat.print_heading = 'Invoice'; | ||||
| 
 | ||||
| {% include 'erpnext/selling/sales_common.js' %}; | ||||
| frappe.provide("erpnext.accounts"); | ||||
| 
 | ||||
|  | ||||
| @ -39,11 +39,13 @@ frappe.ui.form.on('Patient Assessment', { | ||||
| 	}, | ||||
| 
 | ||||
| 	set_score_range: function(frm) { | ||||
| 		let options = []; | ||||
| 		let options = ['']; | ||||
| 		for(let i = frm.doc.scale_min; i <= frm.doc.scale_max; i++) { | ||||
| 			options.push(i); | ||||
| 		} | ||||
| 		frappe.meta.get_docfield('Patient Assessment Sheet', 'score', frm.doc.name).options = [''].concat(options); | ||||
| 		frm.fields_dict.assessment_sheet.grid.update_docfield_property( | ||||
| 			'score', 'options', options | ||||
| 		); | ||||
| 	}, | ||||
| 
 | ||||
| 	calculate_total_score: function(frm, cdt, cdn) { | ||||
| @ -83,4 +85,4 @@ frappe.ui.form.on('Patient Assessment Sheet', { | ||||
| 	score: function(frm, cdt, cdn) { | ||||
| 		frm.events.calculate_total_score(frm, cdt, cdn); | ||||
| 	} | ||||
| }); | ||||
| }); | ||||
|  | ||||
| @ -58,8 +58,12 @@ frappe.ui.form.on('Therapy Plan', { | ||||
| 		} | ||||
| 
 | ||||
| 		if (frm.doc.therapy_plan_template) { | ||||
| 			frappe.meta.get_docfield('Therapy Plan Detail', 'therapy_type', frm.doc.name).read_only = 1; | ||||
| 			frappe.meta.get_docfield('Therapy Plan Detail', 'no_of_sessions', frm.doc.name).read_only = 1; | ||||
| 			frm.fields_dict.therapy_plan_details.grid.update_docfield_property( | ||||
| 				'therapy_type', 'read_only', 1, | ||||
| 			); | ||||
| 			frm.fields_dict.therapy_plan_details.grid.update_docfield_property( | ||||
| 				'no_of_sessions', 'read_only', 1 | ||||
| 			); | ||||
| 		} | ||||
| 	}, | ||||
| 
 | ||||
| @ -126,4 +130,4 @@ frappe.ui.form.on('Therapy Plan Detail', { | ||||
| 		frm.set_value('total_sessions', total); | ||||
| 		refresh_field('total_sessions'); | ||||
| 	} | ||||
| }); | ||||
| }); | ||||
|  | ||||
| @ -11,10 +11,9 @@ frappe.ui.form.on('Routing', { | ||||
| 	}, | ||||
| 
 | ||||
| 	display_sequence_id_column: function(frm) { | ||||
| 		frappe.meta.get_docfield("BOM Operation", "sequence_id", | ||||
| 			frm.doc.name).in_list_view = true; | ||||
| 
 | ||||
| 		frm.fields_dict.operations.grid.refresh(); | ||||
| 		frm.fields_dict.operations.grid.update_docfield_property( | ||||
| 			'sequence_id', 	'in_list_view', 1 | ||||
| 		); | ||||
| 	}, | ||||
| 
 | ||||
| 	calculate_operating_cost: function(frm, child) { | ||||
| @ -69,4 +68,4 @@ frappe.ui.form.on('BOM Operation', { | ||||
| 		const d = locals[cdt][cdn]; | ||||
| 		frm.events.calculate_operating_cost(frm, d); | ||||
| 	} | ||||
| }); | ||||
| }); | ||||
|  | ||||
| @ -111,12 +111,17 @@ frappe.ui.form.on('Salary Structure', { | ||||
| 				frappe.set_route('Form', 'Salary Structure Assignment', doc.name); | ||||
| 			}); | ||||
| 			frm.add_custom_button(__("Assign to Employees"),function () { | ||||
| 			frm.trigger('assign_to_employees') | ||||
| 		}) | ||||
| 				frm.trigger('assign_to_employees') | ||||
| 			}) | ||||
| 		} | ||||
| 
 | ||||
| 		// set columns read-only
 | ||||
| 		let fields_read_only = ["is_tax_applicable", "is_flexible_benefit", "variable_based_on_taxable_salary"]; | ||||
| 		fields_read_only.forEach(function(field) { | ||||
| 			frappe.meta.get_docfield("Salary Detail", field, frm.doc.name).read_only = 1; | ||||
| 			frm.fields_dict.earnings.grid.update_docfield_property( | ||||
| 				field, 'read_only', 1); | ||||
| 			frm.fields_dict.deductions.grid.update_docfield_property( | ||||
| 				field, 'read_only', 1); | ||||
| 		}); | ||||
| 		frm.trigger('set_earning_deduction_component'); | ||||
| 	}, | ||||
|  | ||||
| @ -10,10 +10,12 @@ frappe.ui.form.on('Products Settings', { | ||||
| 				df => ['Link', 'Table MultiSelect'].includes(df.fieldtype) && !df.hidden | ||||
| 			).map(df => ({ label: df.label, value: df.fieldname })); | ||||
| 
 | ||||
| 			const field = frappe.meta.get_docfield("Website Filter Field", "fieldname", frm.docname); | ||||
| 			field.fieldtype = 'Select'; | ||||
| 			field.options = valid_fields; | ||||
| 			frm.fields_dict.filter_fields.grid.refresh(); | ||||
| 			frm.fields_dict.filter_fields.grid.update_docfield_property( | ||||
| 				'fieldname', 'fieldtype', 'Select' | ||||
| 			); | ||||
| 			frm.fields_dict.filter_fields.grid.update_docfield_property( | ||||
| 				'fieldname', 'options', valid_fields | ||||
| 			); | ||||
| 		}); | ||||
| 	} | ||||
| }); | ||||
|  | ||||
| @ -276,74 +276,3 @@ erpnext.taxes.set_conditional_mandatory_rate_or_amount = function(grid_row) { | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| // For customizing print
 | ||||
| cur_frm.pformat.total = function(doc) { return ''; } | ||||
| cur_frm.pformat.discount_amount = function(doc) { return ''; } | ||||
| cur_frm.pformat.grand_total = function(doc) { return ''; } | ||||
| cur_frm.pformat.rounded_total = function(doc) { return ''; } | ||||
| cur_frm.pformat.in_words = function(doc) { return ''; } | ||||
| 
 | ||||
| cur_frm.pformat.taxes= function(doc){ | ||||
| 	//function to make row of table
 | ||||
| 	var make_row = function(title, val, bold, is_negative) { | ||||
| 		var bstart = '<b>'; var bend = '</b>'; | ||||
| 		return '<tr><td style="width:50%;">' + (bold?bstart:'') + title + (bold?bend:'') + '</td>' | ||||
| 			+ '<td style="width:50%;text-align:right;">' + (is_negative ? '- ' : '') | ||||
| 		+ format_currency(val, doc.currency) + '</td></tr>'; | ||||
| 	} | ||||
| 
 | ||||
| 	function print_hide(fieldname) { | ||||
| 		var doc_field = frappe.meta.get_docfield(doc.doctype, fieldname, doc.name); | ||||
| 		return doc_field.print_hide; | ||||
| 	} | ||||
| 
 | ||||
| 	out =''; | ||||
| 	if (!doc.print_without_amount) { | ||||
| 		var cl = doc.taxes || []; | ||||
| 
 | ||||
| 		// outer table
 | ||||
| 		var out='<div><table class="noborder" style="width:100%"><tr><td style="width: 60%"></td><td>'; | ||||
| 
 | ||||
| 		// main table
 | ||||
| 
 | ||||
| 		out +='<table class="noborder" style="width:100%">'; | ||||
| 
 | ||||
| 		if(!print_hide('total')) { | ||||
| 			out += make_row('Total', doc.total, 1); | ||||
| 		} | ||||
| 
 | ||||
| 		// Discount Amount on net total
 | ||||
| 		if(!print_hide('discount_amount') && doc.apply_discount_on == "Net Total" && doc.discount_amount) | ||||
| 			out += make_row('Discount Amount', doc.discount_amount, 0, 1); | ||||
| 
 | ||||
| 		// add rows
 | ||||
| 		if(cl.length){ | ||||
| 			for(var i=0;i<cl.length;i++) { | ||||
| 				if(cl[i].tax_amount!=0 && !cl[i].included_in_print_rate) | ||||
| 					out += make_row(cl[i].description, cl[i].tax_amount, 0); | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		// Discount Amount on grand total
 | ||||
| 		if(!print_hide('discount_amount') && doc.apply_discount_on == "Grand Total" && doc.discount_amount) | ||||
| 			out += make_row('Discount Amount', doc.discount_amount, 0, 1); | ||||
| 
 | ||||
| 		// grand total
 | ||||
| 		if(!print_hide('grand_total')) | ||||
| 			out += make_row('Grand Total', doc.grand_total, 1); | ||||
| 
 | ||||
| 		if(!print_hide('rounded_total')) | ||||
| 			out += make_row('Rounded Total', doc.rounded_total, 1); | ||||
| 
 | ||||
| 		if(doc.in_words && !print_hide('in_words')) { | ||||
| 			out +='</table></td></tr>'; | ||||
| 			out += '<tr><td colspan = "2">'; | ||||
| 			out += '<table><tr><td style="width:25%;"><b>In Words</b></td>'; | ||||
| 			out += '<td style="width:50%;">' + doc.in_words + '</td></tr>'; | ||||
| 		} | ||||
| 		out += '</table></td></tr></table></div>'; | ||||
| 	} | ||||
| 	return out; | ||||
| } | ||||
| @ -61,7 +61,7 @@ frappe.ui.form.on("Item Group", { | ||||
| 				frappe.set_route("List", "Item", {"item_group": frm.doc.name}); | ||||
| 			}); | ||||
| 		} | ||||
| 		 | ||||
| 
 | ||||
| 		frappe.model.with_doctype('Item', () => { | ||||
| 			const item_meta = frappe.get_meta('Item'); | ||||
| 
 | ||||
| @ -69,10 +69,12 @@ frappe.ui.form.on("Item Group", { | ||||
| 				df => ['Link', 'Table MultiSelect'].includes(df.fieldtype) && !df.hidden | ||||
| 			).map(df => ({ label: df.label, value: df.fieldname })); | ||||
| 
 | ||||
| 			const field = frappe.meta.get_docfield("Website Filter Field", "fieldname", frm.docname); | ||||
| 			field.fieldtype = 'Select'; | ||||
| 			field.options = valid_fields; | ||||
| 			frm.fields_dict.filter_fields.grid.refresh(); | ||||
| 			frm.fields_dict.filter_fields.grid.update_docfield_property( | ||||
| 				'fieldname', 'fieldtype', 'Select' | ||||
| 			); | ||||
| 			frm.fields_dict.filter_fields.grid.update_docfield_property( | ||||
| 				'fieldname', 'options', valid_fields | ||||
| 			); | ||||
| 		}); | ||||
| 	}, | ||||
| 
 | ||||
|  | ||||
| @ -15,8 +15,9 @@ frappe.ui.form.on('Item Variant Settings', { | ||||
| 				} | ||||
| 			}); | ||||
| 
 | ||||
| 			const child = frappe.meta.get_docfield("Variant Field", "field_name", frm.doc.name); | ||||
| 			child.options = allow_fields; | ||||
| 			frm.fields_dict.fields.grid.update_docfield_property( | ||||
| 				'field_name', 'options', allow_fields | ||||
| 			); | ||||
| 		}); | ||||
| 	} | ||||
| }); | ||||
|  | ||||
| @ -110,19 +110,4 @@ cur_frm.cscript.calc_net_total_pkg = function(doc, ps_detail) { | ||||
| 	refresh_many(['net_weight_pkg', 'net_weight_uom', 'gross_weight_uom', 'gross_weight_pkg']); | ||||
| } | ||||
| 
 | ||||
| var make_row = function(title,val,bold){ | ||||
| 	var bstart = '<b>'; var bend = '</b>'; | ||||
| 	return '<tr><td class="datalabelcell">'+(bold?bstart:'')+title+(bold?bend:'')+'</td>' | ||||
| 	+'<td class="datainputcell" style="text-align:left;">'+ val +'</td>' | ||||
| 	+'</tr>' | ||||
| } | ||||
| 
 | ||||
| cur_frm.pformat.net_weight_pkg= function(doc){ | ||||
| 	return '<table style="width:100%">' + make_row('Net Weight', doc.net_weight_pkg) + '</table>' | ||||
| } | ||||
| 
 | ||||
| cur_frm.pformat.gross_weight_pkg= function(doc){ | ||||
| 	return '<table style="width:100%">' + make_row('Gross Weight', doc.gross_weight_pkg) + '</table>' | ||||
| } | ||||
| 
 | ||||
| // TODO: validate gross weight field
 | ||||
|  | ||||
| @ -248,13 +248,6 @@ cur_frm.fields_dict['items'].grid.get_field('project').get_query = function(doc, | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| cur_frm.cscript.select_print_heading = function(doc, cdt, cdn) { | ||||
| 	if(doc.select_print_heading) | ||||
| 		cur_frm.pformat.print_heading = doc.select_print_heading; | ||||
| 	else | ||||
| 		cur_frm.pformat.print_heading = "Purchase Receipt"; | ||||
| } | ||||
| 
 | ||||
| cur_frm.fields_dict['select_print_heading'].get_query = function(doc, cdt, cdn) { | ||||
| 	return { | ||||
| 		filters: [ | ||||
|  | ||||
| @ -10,7 +10,9 @@ frappe.ui.form.on('Service Level Agreement', { | ||||
| 			let statuses = frappe.meta.get_docfield('Issue', 'status', frm.doc.name).options; | ||||
| 			statuses = statuses.split('\n'); | ||||
| 			allow_statuses = statuses.filter((status) => !exclude_statuses.includes(status)); | ||||
| 			frappe.meta.get_docfield('Pause SLA On Status', 'status', frm.doc.name).options = [''].concat(allow_statuses); | ||||
| 			frm.fields_dict.pause_sla_on.grid.update_docfield_property( | ||||
| 				'status', 'options', [''].concat(allow_statuses) | ||||
| 			); | ||||
| 		}); | ||||
| 	} | ||||
| }); | ||||
| }); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user