【发布时间】:2019-08-15 10:01:39
【问题描述】:
我正在尝试在 odoo11 的设置页面中添加 many2one 字段。我可以在设置页面中添加字符或整数字段,但使用 Many2one 字段时出现错误。
错误:
psycopg2.DataError: invalid input syntax for integer:"double.accounts(406,)"
LINE 1: ...FROM "double_accounts" WHERE "double_accounts".id IN ('double.acco...
这是我的代码:
类 AccountSetting(models.TransientModel):
_inherit = 'res.config.settings'
authtoken_module = fields.Char(default_model='account.move')
organization_module = fields.Char(default_model='account.move')
double_accounts_id = fields.Many2one('double.accounts', string="double Entery", default_model='account.move')
def get_values(self):
res = super(AccountSetting, self).get_values()
res.update({
'authtoken_module': self.env['ir.config_parameter'].sudo().get_param('account.authtoken_module', default=''),
'organization_module': self.env['ir.config_parameter'].sudo().get_param('account.organization_module'),
#### the error that i am facing from this line
'double_accounts_id': self.env['ir.config_parameter'].sudo().get_param('account.double_accounts_id', default=''),
####
})
return res
def set_values(self):
super(AccountSetting, self).set_values()
self.env['ir.config_parameter'].sudo().set_param('account.authtoken_module', (self.authtoken_module or ''))
self.env['ir.config_parameter'].sudo().set_param('account.organization_module', (self.organization_module or ''))
self.env['ir.config_parameter'].sudo().set_param('account.double_accounts_id', (self.double_accounts_id or ''))
【问题讨论】:
-
我认为您需要做的是将值设置为 id 而不是它自己的记录集。
self.env['ir.config_parameter'].sudo().set_param('account.double_accounts_id', (self.double_accounts_id.id or ''))--> self.double_accounts_id.id -
我得到了 odoo 服务器错误(数据库获取未命中 ids (('395',)) 并且有额外的 ids ((395,)),可能是由先前请求中的类型不一致引起的)