【问题标题】:How can I get a list of filtered values from a many2many field in odoo 11?如何从odoo 11中的many2many字段中获取过滤值列表?
【发布时间】:2018-06-01 23:29:36
【问题描述】:

我有一个名为“student”的模型,它与一个名为“authorized”的模型具有多对多关系,另一个名为“authorized”的模型与“学生”模型具有多对多关系。另一方面,我有第三个模型,名为“exit_control”,它包含与模型“student”的多对一关系。

我想要模型“exit_control”中的第二个字段 many2one,它只显示与所选学生相关的授权。

也就是说:如果student1与authorized6和authorized8相关,并且authorized的完整表有20个authorized,我在模型exit_control的student_id字段中选择student1,我想显示一个字段many2one和authorized6和授权8.

学生模型有:

authorized_ids = fields.Many2many('aula10.authorized', string='Authorizeds')

授权模型有:

authorized_for_ids = fields.Many2many('aula10.student', string='Can get this student:')

Exit_control 模型有:

student_id = fields.Many2one('aula10.student',string='Student')
Given_to_id = fields.Many2one('aula10.authorized', string='Given to:')

Given_to_id 是我想用来显示过滤后的授权的字段。

我尝试在视图和模型中使用属性域,但对我来说是不可能的。

你能帮帮我吗?

【问题讨论】:

  • 解决了!解决方案是 Given_to_id = fields.Many2one('aula10.authorized', string='Given to:' , domain="[('authorized_for_ids', '=', student_id)]")

标签: filter odoo


【解决方案1】:

在模型定义中?

Given_to_id = fields.Many2one('aula10.authorized', string='Given to:', domain=[('authorized_for_ids', 'in', [student_id ])])

你可以使用带有存储选项的计算字段吗?

【讨论】:

  • 我试过了,但之后,单击菜单链接时我无法访问。 Firefox 控制台中出现下一个错误:调用 Python 对象时超出了最大递归深度。
  • 解决了!域将是:domain="[('authorized_por_ids', '=', student_id)]") 在 student_id 中缺少 ",不需要 [] 并且是 = 而不是 IN。
猜你喜欢
  • 1970-01-01
  • 2022-06-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多