I have this problem related to simple update query. I couldn't figure out what went wrong.
The class and fields need to get updated
class allowance_attendances(osv.osv):
_name = "allowance.attendances"
_description = "Allowance Attendances"
_columns = {
'worked_hours':fields.datetime("Extra Hours"),
'compati_hours' : fields.datetime("Compatible Hours"),
}
The update query I wrote
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))
Data type of the compati_hours and cal_hours is datetime.timedelta
Error massage is;
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 -
There is no field only Time. If you want to store only Time. You may use fields.char
Date
Store date. The field provides some helpers:
>>> 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'
DateTime
Store datetime. The field provide some helper:
>>> 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'