我正在使用odoo 11,并且我已经开发了一个自定义模块,该模块允许通过修改请求来修改“ hr.attendance”,经理会批准该修改后,“ hr.attendance”将自动更新为新值签入和签出的出勤修改。但是,当我按批准按钮时,它显示此错误
跟踪
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'})
答案 0 :(得分:0)
classmethod
datetime.strptime(date_string, format)
返回与date_string相对应的日期时间,并根据格式进行解析。这等效于
datetime(*(time.strptime(date_string, format)[0:6]))
。如果{_1}无法解析date_string和格式,或者返回的值不是时间元组,则会引发ValueError。 -来自https://docs.python.org/3/library/datetime.html#datetime.datetime.strptime
第一个参数应该是字符串而不是布尔值。从字面上看,这就是错误的意思。
time.strptime()
应该是表示日期的字符串,格式为record.attendance_id.check_in
。
答案 1 :(得分:0)
这种错误通常发生在strptime()无法获取值时,在您的情况下,可能是strptime()没有获取 record.attendance_id.check_in 。