Odoo中自定义设置页面中的Many2one字段

问题描述 投票:1回答:1

我想在odoo11的设置页面中添加many2one字段。我能够在设置页面中添加char或整数字段,但是在Many2one字段中我收到错误。

错误 :

     psycopg2.DataError: invalid input syntax for integer:"double.accounts(406,)"
     LINE 1: ...FROM "double_accounts" WHERE "double_accounts".id IN ('double.acco...

这是我的代码:

class 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 ''))
python odoo odoo-11 erp
1个回答
0
投票

看起来并不是很好。但是,您似乎从参数中获取了记录集而不是ID。所以一个简单的解决方案是将.id放在标记线的末尾。但这不是完整的解决方案,因为你的默认值必须改为self.sudo().env['account.double_accounts_id'].id也可以。

我真的想知道为什么你得到一个记录集,也许有人可以回答这个问题。

© www.soinside.com 2019 - 2024. All rights reserved.