我遇到与简单更新查询相关的问题。我无法弄清楚出了什么问题所以请帮助我。
课程和字段需要更新
class allowance_attendances(osv.osv):
_name = "allowance.attendances"
_description = "Allowance Attendances"
_columns = {
'worked_hours':fields.datetime("Extra Hours"),
'compati_hours' : fields.datetime("Compatible Hours"),
}
我写的更新查询
cr.execute("""UPDATE allowance_attendances SET compati_hours = '%s',worked_hours='%s' WHERE att_date ='%s' and employee_id=%s"""%(comp_hours,cal_hours,cal_date,emp_id))
compatibility_hours 和 cal_hours 的数据类型为 datetime.timedelta
错误按摩是
2017-07-20 04:25:01,469 4170 ERROR testtest openerp.netsvc: invalid input syntax for type timestamp: "6:59:00"
LINE 1: UPDATE allowance_attendances SET compati_hours = '6:59:00',w...
^
Traceback (most recent call last):
File "/home/manisha/HR_Workspace/openerp-7.0/openerp/netsvc.py", line 296, in dispatch_rpc
result = ExportService.getService(service_name).dispatch(method, params)
File "/home/manisha/HR_Workspace/openerp-7.0/openerp/service/web_services.py", line 626, in dispatch
res = fn(db, uid, *params)
File "/home/manisha/HR_Workspace/openerp-7.0/openerp/osv/osv.py", line 190, in execute_kw
return self.execute(db, uid, obj, method, *args, **kw or {})
File "/home/manisha/HR_Workspace/openerp-7.0/openerp/osv/osv.py", line 132, in wrapper
return f(self, dbname, *args, **kwargs)
File "/home/manisha/HR_Workspace/openerp-7.0/openerp/osv/osv.py", line 199, in execute
res = self.execute_cr(cr, uid, obj, method, *args, **kw)
File "/home/manisha/HR_Workspace/openerp-7.0/openerp/addons/audittrail/audittrail.py", line 532, in execute_cr
return fct_src(cr, uid, model, method, *args, **kw)
File "/home/manisha/HR_Workspace/openerp-7.0/openerp/osv/osv.py", line 187, in execute_cr
return getattr(object, method)(cr, uid, *args, **kw)
File "/home/manisha/HR_Workspace/openerp-7.0/openerp/addons/hr_allowances/hr_allowances.py", line 482, in populate_attendance_normal_shift
self.get_number_of_hours(cr, uid, ids, all_emp_id,all_date, all_sign_in, all_sign_out,all_sign_in2,all_sign_out2, all_emp_type, context)
File "/home/manisha/HR_Workspace/openerp-7.0/openerp/addons/hr_allowances/hr_allowances.py", line 336, in get_number_of_hours
cr.execute("""UPDATE allowance_attendances SET compati_hours = '%s',worked_hours='%s' WHERE att_date ='%s' and employee_id=%s"""%(comp_hours,cal_hours,cal_date,emp_id))
File "/home/manisha/HR_Workspace/openerp-7.0/openerp/sql_db.py", line 161, in wrapper
return f(self, *args, **kwargs)
File "/home/manisha/HR_Workspace/openerp-7.0/openerp/sql_db.py", line 226, in execute
res = self._obj.execute(query, params)
DataError: invalid input syntax for type timestamp: "6:59:00"
LINE 1: UPDATE allowance_attendances SET compati_hours = '6:59:00',w...
^
2017-07-20 04:25:01,470 4170 INFO testtest werkzeug: 127.0.0.1 - - [20/Jul/2017 04:25:01] "POST /web/dataset/call_kw/allowance.attendances:populate_attendance_normal_shift HTTP/1.1" 200 -
答案 0 :(得分:1)
没有字段时间。如果您只想存储时间。你应该用户fields.char
<强>日期强>
存储日期。该字段提供了一些帮助:
>>> from openerp import fields
>>> adate = fields.Date()
>>> fields.Date.today()
'2014-06-15'
>>> fields.Date.context_today(self)
'2014-06-15'
>>> fields.Date.context_today(self, timestamp=datetime.datetime.now())
'2014-06-15'
>>> fields.Date.from_string(fields.Date.today())
datetime.datetime(2014, 6, 15, 19, 32, 17)
>>> fields.Date.to_string(datetime.datetime.today())
'2014-06-15'
<强>日期时间强>
存储日期时间。该领域提供了一些帮助:
>>> fields.Datetime.context_timestamp(self, timestamp=datetime.datetime.now())
datetime.datetime(2014, 6, 15, 21, 26, 1, 248354, tzinfo=<DstTzInfo 'Europe/Brussels' CEST+2:00:00 DST>)
>>> fields.Datetime.now()
'2014-06-15 19:26:13'
>>> fields.Datetime.from_string(fields.Datetime.now())
datetime.datetime(2014, 6, 15, 19, 32, 17)
>>> fields.Datetime.to_string(datetime.datetime.now())
'2014-06-15 19:26:13''2014-06-15 19:26:13'