2013-05-13 48 views
0

我需要時間重新日期字段時,我改變我的師類型錯誤:<在0xaaa7064功能context_today>不是JSON序列化

這裏是我的Python代碼

 tea_worker_ids = self.pool.get('bpl.worker').search(cr, uid, [('bpl_division_id', '=', division_id), ('default_work', '=', 'tea')]) 
     for record in self.pool.get('bpl.worker').browse(cr, uid, tea_worker_ids): 
      tea_list_data.append({'worker_id': record.id, 'worker_emp_no': record.emp_no, 'is_selected':True,'date': (fields.date.context_today)})# 
     tea_v['selected_tea_workers'] = tea_list_data 

這是錯誤

2013-05-13 06:22:28,810 15393 ERROR ABC werkzeug: Error on request: 
Traceback (most recent call last): 
    File "/usr/share/pyshared/werkzeug/serving.py", line 159, in run_wsgi 
    execute(app) 
    File "/usr/share/pyshared/werkzeug/serving.py", line 146, in execute 
    application_iter = app(environ, start_response) 
    File "/usr/share/pyshared/simplejson/__init__.py", line 286, in dumps 
    return _default_encoder.encode(obj) 
    File "/usr/share/pyshared/simplejson/encoder.py", line 226, in encode 
    chunks = self.iterencode(o, _one_shot=True) 
    File "/usr/share/pyshared/simplejson/encoder.py", line 296, in iterencode 
    return _iterencode(o, 0) 
    File "/usr/share/pyshared/simplejson/encoder.py", line 202, in default 
    raise TypeError(repr(o) + " is not JSON serializable") 
TypeError: <function context_today at 0xaaa7064> is not JSON serializable 

請幫我解決這問題,

EDITED

當它變爲fields.date.context_today() 然後錯誤出現如下

File "/home/bellvantage/Documents/openerp-7.0/openerp-7/openerp/addons/bpl/bpl.py", line 1059, in on_change_division 
    workers_list.append({'worker_id': record.id,'start_date': fields.date.context_today()}) 
TypeError: context_today() takes at least 3 arguments (0 given) 

回答

0

工作
workers_list.append({'worker_id': record.id, 'start_date': time.strftime('%Y-%m-%d'), 'selected':True}) 
+1

感謝Priyan ..!這次它真的工作。再次感謝你的答案。 – user2323577 2013-05-13 07:33:18

+0

這是一個破解,因爲缺乏i18n支持。 – uprego 2014-08-13 08:24:59

3

貌似context_today是一種方法,而不是一個值。你需要調用它:

tea_list_data.append({'worker_id': record.id, 'worker_emp_no': record.emp_no, 
         'is_selected':True,'date': (fields.date.context_today())}) 
+0

謝謝親愛的丹尼爾。但現在又發生了一個錯誤&說較少的參數given.please幫助排序這個問題:-) – 2013-05-13 06:59:28

0

這裏fields.date.context_today是一個方法,所以你需要傳遞的參數,所以這將是什麼樣子,

tea_list_data.append({'worker_id': record.id, 'worker_emp_no': record.emp_no, 
            'is_selected':True, 
            'date': (fields.date.context_today(self,cr,uid,context=context))}) 
相關問題