Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
2808 Переглядів

Dear Forum!

I have a field called current, this field is a compute field that gives employees the number of holidays left in the current year. But I should only deduct the value from the remaining leave if the type of leave is annual leave.

yearly_holidays_ids = fields.One2many('hr.employee.yearly.holidays', 'employee_id')
current = fields.Integer(compute="_get_current", store=True)

@api.multi
@api.depends('yearly_holidays_ids')
def _get_current(self):
for record in self:
current_year = datetime.date.today().year
total_record = record.yearly_holidays_ids.filtered(lambda lm:lm.year == current_year)
if len(total_record) > 1:
total_record = total_record[0]
record.current = total_record.remaining_count
elif len(total_record) == 1:
record.current = total_record.remaining_count
elif len(total_record) == 0:
record.current = 0
Do I need the annual leave ID?

Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
2
серп. 23
18885
1
серп. 25
3919
1
жовт. 24
5741
2
лип. 24
2451
2
бер. 24
2244