Override py function

Hello, I want to override the below py function without using a custom app
Can anyone suggest if it can be done using client script or server script?

Here’s my function

def validate_leave_allocation_days(self):
		company = frappe.db.get_value("Employee", self.employee, "company")
		leave_period = get_leave_period(self.from_date, self.to_date, company)
		max_leaves_allowed = flt(
			frappe.db.get_value("Leave Type", self.leave_type, "max_leaves_allowed")
		)
		if max_leaves_allowed > 0:
			leave_allocated = 0
			if leave_period:
				leave_allocated = get_leave_allocation_for_period(
					self.employee,
					self.leave_type,
					leave_period[0].from_date,
					leave_period[0].to_date,
					exclude_allocation=self.name,
				)
			leave_allocated += flt(self.new_leaves_allocated)
			if leave_allocated > max_leaves_allowed:
				frappe.throw(
					_(
						"Total allocated leaves are more than maximum allocation allowed for {0} leave type for employee {1} in the period"
					).format(self.leave_type, self.employee),
					OverAllocationError,
				)            

Hi @Jignasa_Chavda,

Hmm :thinking:

Please try it on server script doctype.

Code:

company = frappe.db.get_value("Employee", doc.employee, "company")
leave_period = get_leave_period(doc.from_date, doc.to_date, company)
max_leaves_allowed = flt(
	frappe.db.get_value("Leave Type", doc.leave_type, "max_leaves_allowed")
)

if max_leaves_allowed > 0:
	leave_allocated = 0
	if leave_period:
		leave_allocated = get_leave_allocation_for_period(
			doc.employee,
			doc.leave_type,
			leave_period[0].from_date,
			leave_period[0].to_date,
			exclude_allocation=doc.name,
		)
	leave_allocated += flt(doc.new_leaves_allocated)
	if leave_allocated > max_leaves_allowed:
		frappe.throw(
			_(
				"Total allocated leaves are more than maximum allocation allowed for {0} leave type for employee {1} in the period"
			).format(doc.leave_type, doc.employee),
			OverAllocationError,
		)

We haven’t tried so please try and check it.

I hope this helps.
Thank You!

Thanks for your response
I have tried to override using server script and its is working on before save(submitted document) method but not on before validate method
It will be a great help if you can suggest any solution!

Sorry @Jignasa_Chavda,

Without a custom app does not possible.
It’s very complicated.

Thank You!