2017-07-20 80 views
1

我有这个问题与简单更新查询有关。我无法弄清楚出了什么问题,请帮助我解决这个问题。Openerp 7:不执行查询

类和字段需要得到更新

class allowance_attendances(osv.osv): 

    _name = "allowance.attendances" 
    _description = "Allowance Attendances" 
    _columns = { 

      'worked_hours':fields.datetime("Extra Hours"), 
      'compati_hours' : fields.datetime("Compatible Hours"), 
      } 

更新查询我写的compati_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)) 

数据类型和cal_hours日期时间。 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 - 
+1

如果'compati_hours'是'datetime'场不宜您的数据的'datetime'而不只是'time' – Bijoy

+0

甚至没有尝试过将它转换为字符串,并试图将其存储在char字段中,但它不存储 –

回答

1

没有字段只有时间。如果你只想存储时间。你应该用户fields.char

日期

店日期。现场提供了一些助手:

  • context_today返回今天
  • 基于TZ当天的日期字符串返回当前系统日期字符串
  • from_string返回datetime.date()从字符串
  • to_string返回从日期字符串datetime.date
>>> 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' 

日期时间

存储日期时间。现场提供一些帮助:

  • context_timestamp返回)从字符串基于TZ当天日期字符串
  • 现在返回当前系统日期字符串
  • from_string返回datetime.date(
  • to_string返回从日期字符串datetime.date
>>> 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' 
+0

非常感谢您提供了很好的说明。我将它存储为char,因为我在前端需要这个值。非常感谢 –