Openerp TypeError:write()为关键字参数' context'提供了多个值。

时间:2016-06-20 09:01:27

标签: openerp typeerror odoo-8

我有这个代码。单击保存按钮时出现此错误。请帮助解决此问题。

  

TypeError:write()为关键字参数' context'

获取了多个值
class crm_case_stage(osv.osv):
    _inherit="crm.case.stage"

    _columns = {
                 'name':fields.char('Stage Name'),
                 'email_template_ids':fields.many2many('email.template','email_tempate_rel','template_id'), #Integrate email templates with stage ids
                 'template_count' : fields.integer('Mail Template Count'),
                }

    def write(self, cr, uid, ids, context=None):
        cur_obj=self.browse(cr, uid, ids, context=context)
        self.write(cr, uid, ids,{'template_count':len(cur_obj.email_template_ids.ids)},context=context)

1 个答案:

答案 0 :(得分:1)

如果您正在使用Odoo V8 +尝试使用新API:

@api.multi
def write(self, vals):
    res = super(crm_case_stage, self).write(vals)
    for stage in self:
        stage.template_count = len(stage.email_template_ids)
    return res

或旧API:

def write(self, cr, uid, ids, vals, context=None):
    res = True
    for stage in self.browse(cr, uid, ids, context):
        vals['template_count'] = len(stage.email_template_ids)
        res &= super(crm_case_stage, self).write(cr, uid, ids, vals, context)
    return res