我的代码有问题,我的错误是:
TypeError:-:“ float”和“ NoneType”的不受支持的操作数类型
所在行:
diff = self.days_compensation_remaining - compensation_legal_leave.get_days(
self.id)[compensation_legal_leave.id].get('days_compensation_remaining')
以下是完整的代码:
类和型号:
class HrEmployee(models.Model):
_inherit = 'hr.employee'
days_compensation_remaining = fields.Float(
'Jours de récupération restant',
compute='_compute_days_compensation_remaining',
readonly=True,
inverse='_inverse_days_compensation_remaining',
help='Nombre total des jours de récupération '
)
我的第一个功能:
@api.multi
def _inverse_days_compensation_remaining(self):
self.ensure_one()
days_compensation = self.company_id.days_compensation_holidays_status_id
if not compensation_legal_leave:
raise UserError(_("le type de congé pour les jours de récupération n'est pas défini"))
diff = self.days_compensation_remaining - compensation_legal_leave.get_days(
self.id)[compensation_legal_leave.id].get('days_compensation_remaining')
如果差异大于0:
if diff > 0:
leave = self.env['hr.holidays'].create(
{
'name': 'Allocation for %s' % self.name,
'employee_id': self.id,
'holiday_status_id': compensation_legal_leave.id,
'type': 'add',
'holiday_type': 'employee',
'number_of_days_temp': diff
}
)
leave.action_approve()
if leave.double_validation:
leave.action_validate()
elif diff < 0:
raise UserError(_('vous ne pouvez pas réduire le nombre de jours'))
第二个功能:
@api.multi
def _compute_days_compensation_remaining(self):
for r in self:
compensation_legal_leave = r.company_id.days_compensation_holidays_status_id
if not compensation_legal_leave:
raise UserError(_("le type de congé pour les jours de récupération n'est pas défini"))
r.days_compensation_remaining = compensation_legal_leave.get_days(
r.id)[compensation_legal_leave.id].get('days_compensation_remaining')
答案 0 :(得分:0)
将行更改为:
diff = self.days_compensation_remaining - compensation_legal_leave.get_days( self.id)[compensation_legal_leave.id].get('days_compensation_remaining', 0)