fix: Add disable and mandatory check for accounting dimension filters
This commit is contained in:
		
							parent
							
								
									0c6319194e
								
							
						
					
					
						commit
						d82c0f3bea
					
				| @ -3,16 +3,48 @@ | ||||
| 
 | ||||
| frappe.ui.form.on('Accounting Dimension Filter', { | ||||
| 	onload: function(frm) { | ||||
| 		frm.set_query('applicable_on_account', 'accounts', function() { | ||||
| 			return { | ||||
| 				filters : { | ||||
| 					'company': frm.doc.company | ||||
| 				} | ||||
| 			} | ||||
| 		}); | ||||
| 
 | ||||
| 		frappe.db.get_list('Accounting Dimension', | ||||
| 			{fields: ['name']}).then((res) => { | ||||
| 			{fields: ['document_type']}).then((res) => { | ||||
| 			let options = ['Cost Center', 'Project']; | ||||
| 
 | ||||
| 			res.forEach((dimension) => { | ||||
| 				options.push(dimension.name); | ||||
| 				options.push(dimension.document_type); | ||||
| 			}); | ||||
| 
 | ||||
| 			frm.set_df_property('accounting_dimension', 'options', options); | ||||
| 		}); | ||||
| 
 | ||||
| 		frm.trigger('setup_filters'); | ||||
| 	}, | ||||
| 
 | ||||
| 	setup_filters: function(frm) { | ||||
| 		let filters = {}; | ||||
| 
 | ||||
| 		frappe.model.with_doctype(frm.doc.accounting_dimension, function() { | ||||
| 			if (frm.doc.accounting_dimension) { | ||||
| 				if (frappe.model.is_tree(frm.doc.accounting_dimension)) { | ||||
| 					filters['is_group'] = 0; | ||||
| 				} | ||||
| 
 | ||||
| 				if (frappe.meta.has_field(frm.doc.accounting_dimension, 'company')) { | ||||
| 					filters['company'] = frm.doc.company; | ||||
| 				} | ||||
| 
 | ||||
| 				frm.set_query('dimension_value', 'dimensions', function() { | ||||
| 					return { | ||||
| 						filters: filters | ||||
| 					} | ||||
| 				}); | ||||
| 			} | ||||
| 		}); | ||||
| 	}, | ||||
| 
 | ||||
| 	accounting_dimension: function(frm) { | ||||
| @ -20,6 +52,7 @@ frappe.ui.form.on('Accounting Dimension Filter', { | ||||
| 		let row = frm.add_child("dimensions"); | ||||
| 		row.accounting_dimension = frm.doc.accounting_dimension; | ||||
| 		frm.refresh_field("dimensions"); | ||||
| 		frm.trigger('setup_filters'); | ||||
| 	}, | ||||
| }); | ||||
| 
 | ||||
|  | ||||
| @ -7,8 +7,10 @@ | ||||
|  "engine": "InnoDB", | ||||
|  "field_order": [ | ||||
|   "accounting_dimension", | ||||
|   "column_break_2", | ||||
|   "allow_or_restrict", | ||||
|   "column_break_2", | ||||
|   "company", | ||||
|   "disabled", | ||||
|   "section_break_4", | ||||
|   "accounts", | ||||
|   "column_break_6", | ||||
| @ -70,11 +72,28 @@ | ||||
|    "reqd": 1, | ||||
|    "show_days": 1, | ||||
|    "show_seconds": 1 | ||||
|   }, | ||||
|   { | ||||
|    "default": "0", | ||||
|    "fieldname": "disabled", | ||||
|    "fieldtype": "Check", | ||||
|    "label": "Disabled", | ||||
|    "show_days": 1, | ||||
|    "show_seconds": 1 | ||||
|   }, | ||||
|   { | ||||
|    "fieldname": "company", | ||||
|    "fieldtype": "Link", | ||||
|    "label": "Company", | ||||
|    "options": "Company", | ||||
|    "reqd": 1, | ||||
|    "show_days": 1, | ||||
|    "show_seconds": 1 | ||||
|   } | ||||
|  ], | ||||
|  "index_web_pages_for_search": 1, | ||||
|  "links": [], | ||||
|  "modified": "2020-11-14 18:02:02.616932", | ||||
|  "modified": "2020-11-16 17:27:40.292860", | ||||
|  "modified_by": "Administrator", | ||||
|  "module": "Accounts", | ||||
|  "name": "Accounting Dimension Filter", | ||||
|  | ||||
| @ -32,12 +32,13 @@ def get_dimension_filter_map(): | ||||
| 	filters = frappe.db.sql( | ||||
| 		""" SELECT | ||||
| 				a.applicable_on_account, d.dimension_value, p.accounting_dimension, | ||||
| 				p.allow_or_restrict, ad.fieldname | ||||
| 				p.allow_or_restrict, ad.fieldname, a.is_mandatory | ||||
| 			FROM | ||||
| 				`tabApplicable On Account` a, `tabAllowed Dimension` d, | ||||
| 				`tabAccounting Dimension Filter` p, `tabAccounting Dimension` ad | ||||
| 			WHERE | ||||
| 				p.name = a.parent | ||||
| 				AND p.disabled = 0 | ||||
| 				AND p.name = d.parent | ||||
| 				AND (p.accounting_dimension = ad.name | ||||
| 				OR p.accounting_dimension in ('Cost Center', 'Project')) | ||||
| @ -50,13 +51,14 @@ def get_dimension_filter_map(): | ||||
| 			f.fieldname = scrub(f.accounting_dimension) | ||||
| 
 | ||||
| 		build_map(dimension_filter_map, f.fieldname, f.applicable_on_account, f.dimension_value, | ||||
| 			f.allow_or_restrict) | ||||
| 			f.allow_or_restrict, f.is_mandatory) | ||||
| 
 | ||||
| 	return dimension_filter_map | ||||
| 
 | ||||
| def build_map(map_object, dimension, account, filter_value, allow_or_restrict): | ||||
| def build_map(map_object, dimension, account, filter_value, allow_or_restrict, is_mandatory): | ||||
| 	map_object.setdefault((dimension, account), { | ||||
| 		'allowed_dimensions': [], | ||||
| 		'is_mandatory': is_mandatory, | ||||
| 		'allow_or_restrict': allow_or_restrict | ||||
| 	}) | ||||
| 	map_object[(dimension, account)]['allowed_dimensions'].append(filter_value) | ||||
|  | ||||
| @ -22,6 +22,7 @@ | ||||
|    "fieldname": "dimension_value", | ||||
|    "fieldtype": "Dynamic Link", | ||||
|    "in_list_view": 1, | ||||
|    "label": "Applicable Dimension", | ||||
|    "options": "accounting_dimension", | ||||
|    "show_days": 1, | ||||
|    "show_seconds": 1 | ||||
| @ -30,7 +31,7 @@ | ||||
|  "index_web_pages_for_search": 1, | ||||
|  "istable": 1, | ||||
|  "links": [], | ||||
|  "modified": "2020-11-14 19:54:03.269016", | ||||
|  "modified": "2020-11-16 17:41:50.422843", | ||||
|  "modified_by": "Administrator", | ||||
|  "module": "Accounts", | ||||
|  "name": "Allowed Dimension", | ||||
|  | ||||
| @ -5,7 +5,8 @@ | ||||
|  "editable_grid": 1, | ||||
|  "engine": "InnoDB", | ||||
|  "field_order": [ | ||||
|   "applicable_on_account" | ||||
|   "applicable_on_account", | ||||
|   "is_mandatory" | ||||
|  ], | ||||
|  "fields": [ | ||||
|   { | ||||
| @ -17,12 +18,22 @@ | ||||
|    "reqd": 1, | ||||
|    "show_days": 1, | ||||
|    "show_seconds": 1 | ||||
|   }, | ||||
|   { | ||||
|    "columns": 2, | ||||
|    "default": "0", | ||||
|    "fieldname": "is_mandatory", | ||||
|    "fieldtype": "Check", | ||||
|    "in_list_view": 1, | ||||
|    "label": "Is Mandatory", | ||||
|    "show_days": 1, | ||||
|    "show_seconds": 1 | ||||
|   } | ||||
|  ], | ||||
|  "index_web_pages_for_search": 1, | ||||
|  "istable": 1, | ||||
|  "links": [], | ||||
|  "modified": "2020-11-14 16:54:06.756883", | ||||
|  "modified": "2020-11-16 13:36:59.129672", | ||||
|  "modified_by": "Administrator", | ||||
|  "module": "Accounts", | ||||
|  "name": "Applicable On Account", | ||||
|  | ||||
| @ -77,11 +77,9 @@ class GLEntry(Document): | ||||
| 					.format(self.voucher_type, self.voucher_no, self.account)) | ||||
| 
 | ||||
| 	def validate_dimensions_for_pl_and_bs(self): | ||||
| 
 | ||||
| 		account_type = frappe.db.get_value("Account", self.account, "report_type") | ||||
| 
 | ||||
| 		for dimension in get_checks_for_pl_and_bs_accounts(): | ||||
| 
 | ||||
| 			if account_type == "Profit and Loss" \ | ||||
| 				and self.company == dimension.company and dimension.mandatory_for_pl and not dimension.disabled: | ||||
| 				if not self.get(dimension.fieldname): | ||||
| @ -101,6 +99,10 @@ class GLEntry(Document): | ||||
| 			account = key[1] | ||||
| 
 | ||||
| 			if self.account == account: | ||||
| 				if value['is_mandatory'] and not self.get(dimension): | ||||
| 					frappe.throw(_("{0} is mandatory for account {1}").format( | ||||
| 						frappe.bold(frappe.unscrub(dimension)), frappe.bold(self.account))) | ||||
| 
 | ||||
| 				if value['allow_or_restrict'] == 'Allow': | ||||
| 					if self.get(dimension) and self.get(dimension) not in value['allowed_dimensions']: | ||||
| 						frappe.throw(_("Invalid value {0} for account {1}").format( | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user