将数据传递给odoo 10中的向导时出现密钥错误
我正在使用上下文将数据发送到向导,但我总是收到以下错误“KeyError:“default\u new\u name” 我试着做这个例子,但仍然得到同样的错误 这是我的密码 创建向导的模型 创建二维矩阵的模型将数据传递给odoo 10中的向导时出现密钥错误,odoo,odoo-10,wizard,Odoo,Odoo 10,Wizard,我正在使用上下文将数据发送到向导,但我总是收到以下错误“KeyError:“default\u new\u name” 我试着做这个例子,但仍然得到同样的错误 这是我的密码 创建向导的模型 创建二维矩阵的模型 create已经在调用line\u id的默认方法。因此,您不应该创建向导记录,只需在没有ID的情况下调用,也可以使用右行的上下文标志创建向导记录: 打开向导而不创建向导 @api.multi def open_x2m_矩阵(自身): context=dict(self.env.conte
create
已经在调用line\u id
的默认方法。因此,您不应该创建向导记录,只需在没有ID的情况下调用,也可以使用右行的上下文标志创建向导记录:
@api.multi
def open_x2m_矩阵(自身):
context=dict(self.env.context或{})
update({'default\u new\u name':self.name})
返回{
“name”:self.name,
'type':'ir.actions.act_window',
“视图类型”:“表单”,
“查看模式”:“表单”,
'res_model':'x2m.matrix.demo.wiz',
'目标':'新',
#“res_id”:wiz.id,#不需要
“上下文”:上下文
}
@api.multi
def open_x2m_矩阵(自身):
wiz=self.env['x2m.matrix.demo.wiz'],带有上下文(
默认的\u new\u name=self.name).create({})
返回{
“name”:self.name,
'type':'ir.actions.act_window',
“视图类型”:“表单”,
“查看模式”:“表单”,
'res_model':'x2m.matrix.demo.wiz',
'目标':'新',
“res_id”:wiz.id,
“上下文”:self.env.context,
}
在x2m.matrix.demo.wiz
模型中是否存在文件名new_name
?顺便说一下,在字典中不能使用两个同名键。您应该创建冻结词典的副本上下文
,更新第一个副本以向其添加您的默认\u新\u名称
键,然后将其发送到返回的词典中。很抱歉,没有看到with \u上下文解决方案,你认为当你在一个向导中创建一个记录时,我认为按钮会被禁用吗?谢谢你的回答所有的解决方案都有效你救了我的命
@api.multi
def open_x2m_matrix(self):
wiz = self.env['x2m.matrix.demo.wiz'].create({})
return {
'name': self.name,
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'form',
'res_model': 'x2m.matrix.demo.wiz',
'target': 'new',
'res_id': wiz.id,
'context': self.env.context,
'context': {'default_new_name': self.name},
}
line_ids = fields.Many2many(
'x2m.demo.line', default=lambda self: self._default_line_ids())
def _default_line_ids(self):
recs =self.env['x2m.demo'].search([("name","!=",self._context['default_new_name'])])
# same with users
users = self.env['x2m.demo.line'].search([]).mapped('new_user_id')
return [
(0, 0, {
'demo_id': rec.id,
'new_user_id': usr.id,
'value': 0,
})
# if the project doesn't have a task for the user, create a new one
if not rec.line_ids.filtered(lambda x: x.new_user_id == usr) else
# otherwise, return the task
(4, rec.line_ids.filtered(lambda x: x.new_user_id == usr)[0].id)
for rec in recs
for usr in users
]