Odoo,create() 缺少 1 个必需的位置参数:'vals' [英] Odoo, create() missing 1 required positional argument: 'vals'
问题描述
我继承了 account_analytic_line 的创建函数.那里的逻辑是,如果字段 support_ticket_id 出现在 vals 字典中,它将执行 if 语句中的所有代码.
I've inherited create function for account_analytic_line. The logic there is that if the field support_ticket_id is coming on vals dictionary, it will execute all the code inside the if statement.
@api.model
def create(self, vals):
for val in vals:
if 'support_ticket_id' in val:
ticket_id = vals['support_ticket_id']
ticket = self.env['website.support.ticket'].search([('id', '=', ticket_id)], limit=1)
vals['account_id'] = ticket.analytic_account_id.id
res = super(AccountAnalyticLine, self).create(vals)
return res
奇怪的是,在我当地的环境中运行良好.但是在生产环境下,是抛出这个错误:
The weird thing is that, on my local enviroment is working fine. But on the production enviroment, is throwing this error:
TypeError: create() 缺少 1 个必需的位置参数:'vals'
TypeError: create() missing 1 required positional argument: 'vals'
更奇怪的是,如果我更改为@api.multi(我知道它不能在 create 方法中使用,但我只是试了一下)并且在我的本地环境中抛出了同样的错误,但是生产工作正常.所以本地和生产之间完全倒退,我不知道是什么触发了这个.
More weird thing is that, if I change to @api.multi (I know that it can't be used in create method, but I just gave it a shot) and on my local enviroment is throwing same mistake, but on production is working fine. So it's all backwards between local and production and I don't know what is triggering this.
推荐答案
用代码试试:
@api.model
def create(self, vals):
if vals.get("support_ticket_id"):
ticket_id = vals.get("support_ticket_id")
ticket = self.env['website.support.ticket'].browse(ticket_id)
if ticket.analytic_account_id:
vals['account_id'] = ticket.analytic_account_id.id
res = super(AccountAnalyticLine, self).create(vals)
return res
几点改进:
- 如果您有车票的整数 ID,我们可以使用浏览方式.
- 不必要地使用 for 循环
这篇关于Odoo,create() 缺少 1 个必需的位置参数:'vals'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!