我有这个方法,我需要改变它,如果annual_leave的值改变,什么都不应该发生,但如果值不改变,添加+1到剩余的计数变量。
我该怎么做?
@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)
annual_leaves = self.env['hr.holidays'].search_count([('holiday_status_id.name', '=', 'annual')])
if annual_leaves > 1:
total_holidays = total_holidays[0]
record.current_holiday_pool = total_holidays.remaining_count
elif annual_leaves == 1:
record.current_holiday_pool = total_holidays.remaining_count
elif annual_leaves == 0:
record.current_holiday_pool = 0
[这只适用于onchange
方法]
在触发onchange
之前,您可以使用self._origin
获取旧值/记录。之后,你可以用它来比较当前的值/记录,这样你就会知道有什么变化。