Odoo V8得到错误不可用类型:' list'

时间:2017-03-29 10:31:06

标签: python odoo-8

我有这样的错误:

    Traceback (most recent call last):
  File "C:\Program Files (x86)\Odoo 8.0\server\.\openerp\http.py", line 544, in _handle_exception
  File "C:\Program Files (x86)\Odoo 8.0\server\.\openerp\http.py", line 581, in dispatch
  File "C:\Program Files (x86)\Odoo 8.0\server\.\openerp\http.py", line 317, in _call_function
  File "C:\Program Files (x86)\Odoo 8.0\server\.\openerp\service\model.py", line 118, in wrapper
  File "C:\Program Files (x86)\Odoo 8.0\server\.\openerp\http.py", line 314, in checked_call
  File "C:\Program Files (x86)\Odoo 8.0\server\.\openerp\http.py", line 810, in __call__
  File "C:\Program Files (x86)\Odoo 8.0\server\.\openerp\http.py", line 410, in response_wrap
  File "C:\Program Files (x86)\Odoo 8.0\server\openerp\addons\web\controllers\main.py", line 944, in call_kw
  File "C:\Program Files (x86)\Odoo 8.0\server\openerp\addons\web\controllers\main.py", line 936, in _call_kw
  File "C:\Program Files (x86)\Odoo 8.0\server\.\openerp\api.py", line 268, in wrapper
  File "C:\Program Files (x86)\Odoo 8.0\server\.\openerp\api.py", line 399, in old_api
  File "C:\Program Files (x86)\Odoo 8.0\server\.\openerp\models.py", line 5989, in onchange
  File "C:\Program Files (x86)\Odoo 8.0\server\.\openerp\models.py", line 5887, in _onchange_eval
  File "C:\Program Files (x86)\Odoo 8.0\server\.\openerp\models.py", line 5395, in _convert_to_cache
  File "C:\Program Files (x86)\Odoo 8.0\server\.\openerp\models.py", line 5396, in <dictcomp>
  File "C:\Program Files (x86)\Odoo 8.0\server\.\openerp\fields.py", line 1661, in convert_to_cache
  File "C:\Program Files (x86)\Odoo 8.0\server\.\openerp\tools\misc.py", line 1288, in add
  File "collections.pyc", line 63, in __setitem__
TypeError: unhashable type: 'list'

我已经使用pdb检查了它,但是我的代码中没有错误,但得到了这部分:

File "C:\Program Files (x86)\Odoo 8.0\server\.\openerp\models.py", line 5887, in _onchange_eval

    TypeError: unhashable type: 'list'

这是我的代码,我的目标是覆盖hr.payslip模型中的onchange_employee_id函数,并希望使用(1,ID,{values})更新one2many字段行值:

import openerp
from openerp.osv import fields, osv
from openerp import api, fields, models, _, SUPERUSER_ID
from datetime import datetime
import time

class hr_payslip(models.Model):
    _inherit = 'hr.payslip'

    #@api.model
    #@api.multi
    def onchange_employee_id(self, cr, uid, ids, date_from, date_to, employee_id=False, contract_id=False, context=None):
        import pdb;pdb.set_trace()
        res = super(hr_payslip, self).onchange_employee_id(cr, uid, ids, date_from, date_to, employee_id=employee_id, contract_id=contract_id, context=context)
        #res = super(hr_payslip, self).onchange_employee_id(cr, uid, ids, date_from, date_to, employee_id, contract_id, context)
        for pay in self.browse(cr, uid, ids):
            empy = self.pool.get('overtime_details').search(cr, uid, [
                                ('start_date','>=',datetime.strptime(pay.date_from, "%Y-%m-%d").strftime("%Y-%m-%d %H:%M:%S")), 
                                ('end_date','<=',datetime.strptime(pay.date_to, "%Y-%m-%d").strftime("%Y-%m-%d %H:%M:%S")), 
                                ('employee_id.name','=',pay.employee_id.name), 
                                ('overtime_id.state', '=', 'done')], context=context)
            if pay.id:
                #chk_struct = self.pool.get('hr.payroll.structure').search(cr, uid, [('name', '=', pay.struct_id.name)], context=context)
                #chk_contract = self.pool.get('hr.contract').search(cr, uid, [('name', '=', pay.contract_id.name)], context=context)
                if empy:
                    #if chk_struct:
                        #if chk_contract:
                    chk_ovt = self.pool.get('overtime_details').browse(cr, uid, empy, context=context)
                    if chk_ovt:
                        counter = 0
                        hrs = 0
                        vals = []
                        for ovt in chk_ovt:
                            if ovt.id:
                                counter = counter + 1
                                hrs = hrs + ovt.ttalmtp
                    vals.append([1,[pay.worked_days_line_ids],{'number_of_days':counter, 
                    'number_of_hours':hrs, 'contract_id':pay.contract_id}])
                    return {'value' : {'worked_days_line_ids' : vals }}
                                #self.create(cr, uid, val2)
                else :
                    val = 0

            return res

我该怎么做才能解决错误

之前感谢:)

2 个答案:

答案 0 :(得分:1)

问题在于:

return {'value' : {'worked_days_line_ids' : vals }}

您尝试将list插入字典中,但是,这是不可能的,因为list 不可用。您可以通过将列表转换为tuple

来解决此问题
return {'value' : {'worked_days_line_ids' : tuple(vals)}}

答案 1 :(得分:0)

我得到了解决方案,所以使用(1,ID,{values})iam使用(0,0,{values}) 并在以后更新,这是我的代码解决方案:

vals.append([0,0,{'number_of_days':counter, 
                'number_of_hours':hrs, 'contract_id':pay.contract_id}])
                ovrtm = {'worked_days_line_ids' : vals }
                res['value'].update(ovrtm)