【问题标题】:Many2one field in a Custom Setting page in OdooOdoo 自定义设置页面中的 Many2one 字段
【发布时间】: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,)),可能是由先前请求中的类型不一致引起的)

标签: python odoo odoo-11 erp


【解决方案1】:

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

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

【讨论】:

  • 您的解决方案不起作用...我仍然得到没有值的记录集 psycopg2.DataError: invalid input syntax for integer: "double.accounts()"
  • 您是否更改了get_paramdefault
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-02-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-28
  • 1970-01-01
相关资源
最近更新 更多