Skip to Content
Menu
This question has been flagged
2 Replies
1441 Views

Hello bros:

How can we get last payslip date  for a particular employee.

Basically i want to calculate days between last payslip date and resign date. For example last payslip for an employee "Ali" was generated in 02/02/2020. Then how can we get this date in our method.

Avatar
Discard
Author

Another Solution is:

@api.multi

def _get_working_days(self):

fmt = '%Y-%m-%d'

payslip = []

payslip = self.env['hr.payslip'].search([('employee_id', '=', self.employee_id.id)], order='date_from desc',

limit=1)

test = payslip.date_from

d1 = datetime.strptime(test, fmt)

d2 = datetime.strptime(self.joining_date, fmt)

self.working_days = (d1 - d2).days

Author Best Answer

Hey,

I solve this question by:

@api.multi
@api.depends('joining_date')
def _get_working_days(self):
fmt = '%Y-%m-%d'
payslip = self.env['hr.payslip'].search([('employee_id', '=', self.employee_id.id)])
from_date = payslip.mapped('date_from')
latest = max(from_date)
d1 = datetime.strptime(latest, fmt)
d2 = datetime.strptime(self.joining_date, fmt)
self.working_days = (d1-d2).days

Thanks.
Avatar
Discard