feat(Employee Advance): add 'Returned' and 'Partly Claimed and Returned' status
This commit is contained in:
		
							parent
							
								
									dbda10e092
								
							
						
					
					
						commit
						e04b3aaf7a
					
				| @ -2,7 +2,7 @@ | |||||||
|  "actions": [], |  "actions": [], | ||||||
|  "allow_import": 1, |  "allow_import": 1, | ||||||
|  "autoname": "naming_series:", |  "autoname": "naming_series:", | ||||||
|  "creation": "2017-10-09 14:26:29.612365", |  "creation": "2022-01-17 18:36:51.450395", | ||||||
|  "doctype": "DocType", |  "doctype": "DocType", | ||||||
|  "editable_grid": 1, |  "editable_grid": 1, | ||||||
|  "engine": "InnoDB", |  "engine": "InnoDB", | ||||||
| @ -121,7 +121,7 @@ | |||||||
|    "fieldtype": "Select", |    "fieldtype": "Select", | ||||||
|    "label": "Status", |    "label": "Status", | ||||||
|    "no_copy": 1, |    "no_copy": 1, | ||||||
|    "options": "Draft\nPaid\nUnpaid\nClaimed\nCancelled", |    "options": "Draft\nPaid\nUnpaid\nClaimed\nReturned\nPartly Claimed and Returned\nCancelled", | ||||||
|    "read_only": 1 |    "read_only": 1 | ||||||
|   }, |   }, | ||||||
|   { |   { | ||||||
| @ -200,7 +200,7 @@ | |||||||
|  ], |  ], | ||||||
|  "is_submittable": 1, |  "is_submittable": 1, | ||||||
|  "links": [], |  "links": [], | ||||||
|  "modified": "2021-09-11 18:38:38.617478", |  "modified": "2022-01-17 19:33:52.345823", | ||||||
|  "modified_by": "Administrator", |  "modified_by": "Administrator", | ||||||
|  "module": "HR", |  "module": "HR", | ||||||
|  "name": "Employee Advance", |  "name": "Employee Advance", | ||||||
| @ -237,5 +237,41 @@ | |||||||
|  "search_fields": "employee,employee_name", |  "search_fields": "employee,employee_name", | ||||||
|  "sort_field": "modified", |  "sort_field": "modified", | ||||||
|  "sort_order": "DESC", |  "sort_order": "DESC", | ||||||
|  |  "states": [ | ||||||
|  |   { | ||||||
|  |    "color": "Red", | ||||||
|  |    "custom": 1, | ||||||
|  |    "title": "Draft" | ||||||
|  |   }, | ||||||
|  |   { | ||||||
|  |    "color": "Green", | ||||||
|  |    "custom": 1, | ||||||
|  |    "title": "Paid" | ||||||
|  |   }, | ||||||
|  |   { | ||||||
|  |    "color": "Orange", | ||||||
|  |    "custom": 1, | ||||||
|  |    "title": "Unpaid" | ||||||
|  |   }, | ||||||
|  |   { | ||||||
|  |    "color": "Blue", | ||||||
|  |    "custom": 1, | ||||||
|  |    "title": "Claimed" | ||||||
|  |   }, | ||||||
|  |   { | ||||||
|  |    "color": "Gray", | ||||||
|  |    "title": "Returned" | ||||||
|  |   }, | ||||||
|  |   { | ||||||
|  |    "color": "Yellow", | ||||||
|  |    "title": "Partly Claimed and Returned" | ||||||
|  |   }, | ||||||
|  |   { | ||||||
|  |    "color": "Red", | ||||||
|  |    "custom": 1, | ||||||
|  |    "title": "Cancelled" | ||||||
|  |   } | ||||||
|  |  ], | ||||||
|  |  "title_field": "employee_name", | ||||||
|  "track_changes": 1 |  "track_changes": 1 | ||||||
| } | } | ||||||
| @ -28,18 +28,31 @@ class EmployeeAdvance(Document): | |||||||
| 	def on_cancel(self): | 	def on_cancel(self): | ||||||
| 		self.ignore_linked_doctypes = ('GL Entry') | 		self.ignore_linked_doctypes = ('GL Entry') | ||||||
| 
 | 
 | ||||||
| 	def set_status(self): | 	def set_status(self, update=False): | ||||||
|  | 		precision = self.precision("paid_amount") | ||||||
|  | 		total_amount = flt(flt(self.claimed_amount) + flt(self.return_amount), precision) | ||||||
|  | 		status = None | ||||||
|  | 
 | ||||||
| 		if self.docstatus == 0: | 		if self.docstatus == 0: | ||||||
| 			self.status = "Draft" | 			status = "Draft" | ||||||
| 		if self.docstatus == 1: | 		elif self.docstatus == 1: | ||||||
| 			if self.claimed_amount and flt(self.claimed_amount) == flt(self.paid_amount): | 			if flt(self.claimed_amount) > 0 and flt(self.claimed_amount, precision) == flt(self.paid_amount, precision): | ||||||
| 				self.status = "Claimed" | 				status = "Claimed" | ||||||
| 			elif self.paid_amount and self.advance_amount == flt(self.paid_amount): | 			elif flt(self.return_amount) > 0 and flt(self.return_amount, precision) == flt(self.paid_amount, precision): | ||||||
| 				self.status = "Paid" | 				status = "Returned" | ||||||
|  | 			elif flt(self.claimed_amount) > 0 and (flt(self.return_amount) > 0) and total_amount == flt(self.paid_amount, precision): | ||||||
|  | 				status = "Partly Claimed and Returned" | ||||||
|  | 			elif flt(self.paid_amount) > 0 and flt(self.advance_amount, precision) == flt(self.paid_amount, precision): | ||||||
|  | 				status = "Paid" | ||||||
| 			else: | 			else: | ||||||
| 				self.status = "Unpaid" | 				status = "Unpaid" | ||||||
| 		elif self.docstatus == 2: | 		elif self.docstatus == 2: | ||||||
| 			self.status = "Cancelled" | 			status = "Cancelled" | ||||||
|  | 
 | ||||||
|  | 		if update: | ||||||
|  | 			self.db_set("status", status) | ||||||
|  | 		else: | ||||||
|  | 			self.status = status | ||||||
| 
 | 
 | ||||||
| 	def set_total_advance_paid(self): | 	def set_total_advance_paid(self): | ||||||
| 		gle = frappe.qb.DocType("GL Entry") | 		gle = frappe.qb.DocType("GL Entry") | ||||||
| @ -85,9 +98,7 @@ class EmployeeAdvance(Document): | |||||||
| 
 | 
 | ||||||
| 		self.db_set("paid_amount", paid_amount) | 		self.db_set("paid_amount", paid_amount) | ||||||
| 		self.db_set("return_amount", return_amount) | 		self.db_set("return_amount", return_amount) | ||||||
| 		self.set_status() | 		self.set_status(update=True) | ||||||
| 		frappe.db.set_value("Employee Advance", self.name , "status", self.status) |  | ||||||
| 
 |  | ||||||
| 
 | 
 | ||||||
| 	def update_claimed_amount(self): | 	def update_claimed_amount(self): | ||||||
| 		claimed_amount = frappe.db.sql(""" | 		claimed_amount = frappe.db.sql(""" | ||||||
| @ -103,8 +114,8 @@ class EmployeeAdvance(Document): | |||||||
| 
 | 
 | ||||||
| 		frappe.db.set_value("Employee Advance", self.name, "claimed_amount", flt(claimed_amount)) | 		frappe.db.set_value("Employee Advance", self.name, "claimed_amount", flt(claimed_amount)) | ||||||
| 		self.reload() | 		self.reload() | ||||||
| 		self.set_status() | 		self.set_status(update=True) | ||||||
| 		frappe.db.set_value("Employee Advance", self.name, "status", self.status) | 
 | ||||||
| 
 | 
 | ||||||
| @frappe.whitelist() | @frappe.whitelist() | ||||||
| def get_pending_amount(employee, posting_date): | def get_pending_amount(employee, posting_date): | ||||||
|  | |||||||
| @ -171,7 +171,7 @@ frappe.ui.form.on("Expense Claim", { | |||||||
| 					['docstatus', '=', 1], | 					['docstatus', '=', 1], | ||||||
| 					['employee', '=', frm.doc.employee], | 					['employee', '=', frm.doc.employee], | ||||||
| 					['paid_amount', '>', 0], | 					['paid_amount', '>', 0], | ||||||
| 					['status', '!=', 'Claimed'] | 					['status', 'not in', ['Claimed', 'Returned', 'Partly Claimed and Returned']] | ||||||
| 				] | 				] | ||||||
| 			}; | 			}; | ||||||
| 		}); | 		}); | ||||||
|  | |||||||
| @ -341,18 +341,27 @@ def get_expense_claim_account(expense_claim_type, company): | |||||||
| 
 | 
 | ||||||
| @frappe.whitelist() | @frappe.whitelist() | ||||||
| def get_advances(employee, advance_id=None): | def get_advances(employee, advance_id=None): | ||||||
| 	if not advance_id: | 	advance = frappe.qb.DocType("Employee Advance") | ||||||
| 		condition = 'docstatus=1 and employee={0} and paid_amount > 0 and paid_amount > claimed_amount + return_amount'.format(frappe.db.escape(employee)) |  | ||||||
| 	else: |  | ||||||
| 		condition = 'name={0}'.format(frappe.db.escape(advance_id)) |  | ||||||
| 
 | 
 | ||||||
| 	return frappe.db.sql(""" | 	query = ( | ||||||
| 		select | 		frappe.qb.from_(advance) | ||||||
| 			name, posting_date, paid_amount, claimed_amount, advance_account | 			.select( | ||||||
| 		from | 				advance.name, advance.posting_date, advance.paid_amount, | ||||||
| 			`tabEmployee Advance` | 				advance.claimed_amount, advance.advance_account | ||||||
| 		where {0} | 			) | ||||||
| 	""".format(condition), as_dict=1) | 	) | ||||||
|  | 
 | ||||||
|  | 	if not advance_id: | ||||||
|  | 		query = query.where( | ||||||
|  | 			(advance.docstatus == 1) | ||||||
|  | 			& (advance.employee == employee) | ||||||
|  | 			& (advance.paid_amount > 0) | ||||||
|  | 			& (advance.status.notin(["Claimed", "Returned", "Partly Claimed and Returned"])) | ||||||
|  | 		) | ||||||
|  | 	else: | ||||||
|  | 		query = query.where(advance.name == advance_id) | ||||||
|  | 
 | ||||||
|  | 	return query.run(as_dict=True) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @frappe.whitelist() | @frappe.whitelist() | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user