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

时间:2019-03-25 07:37:11

标签: python odoo odoo-11 erp

我正在尝试在odoo11的设置页面中添加many2one字段。我可以在设置页面中添加char或integer字段,但是在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 ''))

1 个答案:

答案 0 :(得分:0)

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

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