2017-07-20 82 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,因爲我在前端需要這個值。非常感謝 –