Я использую odoo 11, и я разработал пользовательский модуль, который позволяет изменять «hr.attendance» через запрос на изменение, который будет одобрен менеджером после того, как этот «hr.attendance» будет автоматически обновлен с новыми значениями проверки и изменения модификации посещаемости. Но когда я нажимаю кнопку подтверждения, это показывает эту ошибку
Traceback
Traceback (most recent call last):
File "/opt/openhrms/odoo/http.py", line 651, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/opt/openhrms/odoo/http.py", line 310, in _handle_exception
raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
File "/opt/openhrms/odoo/tools/pycompat.py", line 87, in reraise
raise value
File "/opt/openhrms/odoo/http.py", line 693, in dispatch
result = self._call_function(**self.params)
File "/opt/openhrms/odoo/http.py", line 342, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/opt/openhrms/odoo/service/model.py", line 97, in wrapper
return f(dbname, *args, **kwargs)
File "/opt/openhrms/odoo/http.py", line 335, in checked_call
result = self.endpoint(*a, **kw)
File "/opt/openhrms/odoo/http.py", line 937, in __call__
return self.method(*args, **kw)
File "/opt/openhrms/odoo/http.py", line 515, in response_wrap
response = f(*args, **kw)
File "/opt/openhrms/addons/web/controllers/main.py", line 938, in call_button
action = self._call_kw(model, method, args, {})
File "/opt/openhrms/addons/web/controllers/main.py", line 926, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "/opt/openhrms/odoo/api.py", line 689, in call_kw
return call_kw_multi(method, model, args, kwargs)
File "/opt/openhrms/odoo/api.py", line 680, in call_kw_multi
result = method(recs, *args, **kwargs)
File "/opt/openhrms/addons/sifast_attendance_modification_request/models/hr_attendance_modification_request.py", line 54, in modification_approval
attendance_check_in_date = datetime.datetime.strptime(record.attendance_id.check_in,DEFAULT_SERVER_DATETIME_FORMAT).date()
TypeError: strptime() argument 1 must be str, not bool
Вот мой код:
class AttendanceModificationRequest(models.Model):
_name = 'attendance.modification.request'
_description = 'Attendance modification Request'
_inherit = ['mail.thread', 'mail.activity.mixin']
def _get_employee_id(self):
employee_rec = self.env['hr.employee'].search([('user_id', '=',
self.env.uid)], limit=1)
return employee_rec.id
employee_id = fields.Many2one('hr.employee', 'Employee',
readonly=True,
default=_get_employee_id,
required=True)
user_id = fields.Many2one(
'res.users',
string='User',
track_visibility='onchange',
readonly=True,
states={'draft': [('readonly', False)]},
default=lambda self: self.env.user,
)
state = fields.Selection([('draft', 'Pending'), ('waiting',
'Waiting for approval'), ('approved',
'Approved'), ('cancel', 'Cancelled')],
readonly=True,
help='Gives the state of the attendance request modification .'
, default='draft')
modification_date = fields.Date('Date')
time_check_in_1 = fields.Datetime('Check in')
time_check_out_1 = fields.Datetime('Check out')
note = fields.Text('Note')
attendance_id = fields.Many2one('hr.attendance', string='Attendance'
)
@api.multi
def modification_approval(self):
attend_signin_ids = self.env['hr.attendance'
].search([('employee_id', '=', self.employee_id.id)])
check_in_date = \
datetime.datetime.strptime(self.time_check_in_1,
DEFAULT_SERVER_DATETIME_FORMAT).date()
check_out_date = \
datetime.datetime.strptime(self.time_check_out_1,
DEFAULT_SERVER_DATETIME_FORMAT).date()
for record in self:
attendance_check_in_date = \
datetime.datetime.strptime(record.attendance_id.check_in,
DEFAULT_SERVER_DATETIME_FORMAT).date()
attendance_check_out_date = \
datetime.datetime.strptime(record.attendance_id.check_out,
DEFAULT_SERVER_DATETIME_FORMAT).date()
if record.attendance_id.employee_id == self.employee_id \
and check_in_date == attendance_check_in_date:
record.attendance_id.check_in = self.time_check_in_1
record.attendance_id.check_out = self.time_check_out_1
return self.write({'state': 'approved'})