Skip to Content
Menu
This question has been flagged

Hi forum!


I try to calculate employees leaves and i get this error:

record.current_holiday_pool = total_holidays.remaining_count - total_record
TypeError: unsupported operand type(s) for -: 'int' and 'hr.holidays'


my method:


current_holiday_pool = fields.Integer(compute="_get_current_holiday_pool", store=True)

@api.multi
@api.depends('yearly_holidays_ids')
def _get_current_holiday_pool(self):
for record in self:
current_year = datetime.date.today().year
total_holidays = record.yearly_holidays_ids.filtered(lambda lm:lm.year == current_year)
total_record = total_holidays.mapped("holidays_ids").filtered(lambda lm:lm.holiday_status_id.name == 'annual')
record.current_holiday_pool = total_holidays.remaining_count - total_record

What do I do wrong?
Thank you for your help!

Regards,

Steven

Avatar
Discard
Best Answer

Hi Steven: total_record is returning a recordset, whereas according to the error message, total_holidays.remaining_count is an integer. Assuming that you are trying to get a count of the records, change total_record to len(total_record) and it should work.

Avatar
Discard
Author

Thank you very much for your reply, solved the issue!

Related Posts Replies Views Activity
2
Apr 21
11052
2
Feb 19
6554
2
Aug 18
3698
0
Apr 16
7903
0
Mar 16
3308