admin管理员组文章数量:1122846
I need to create a new Many2one field in Odoo 17, extending the standard res.partner model so that the domain of the newly created res_partner.settore_principale
field and its possible values are selected dynamically according to the value of the res_partner.x_studio_macrocategoria
attribute of the same record, both in case the latter is modified and in case it hasn't been.
I tries to create a new field with a callback defining it's domain, as shown below:
settore_principale = fields.Many2one(
'res.partner.industry',
string="Settore",
domain=lambda self: self._compute_settore_domain() # I tried both with and without str()
)
def _compute_settore_domain(self):
domain = [('x_studio_settore_padre', '=', False)]
if self.x_studio_macrocategoria:
domain.append(('x_studio_macrocategoria', '=', self.x_studio_macrocategoria))
return domain # Return domain as a list of tuples, not string
@api.onchange('x_studio_macrocategoria')
def _onchange_macrocategoria(self):
return {'domain': {'settore_principale': self._compute_settore_domain()}}
fact is that on loading the addon, even on a first try, I receive the following error:
odoo.addons.base.models.ir_qweb.QWebException: Error while render the template
UndefinedColumn: column res_partner.settore_principale does not exist
LINE 1: ...uid", "res_partner"."write_date" AS "write_date", "res_partn...
^
it appears that while the code gets parsed and executed in at least a partially correct way, it doesn't allow Odoo to follow with the actual field creation in the database.
Could anyone help me understand what i'm doing wrong?
Thanks in advance
本文标签: pythonDynamic many2one field domain in Odoo 17 based on callback functionStack Overflow
版权声明:本文标题:python - Dynamic many2one field domain in Odoo 17 based on callback function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736309086a1933893.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论