如何解决Odoo - 基于项目中的角色过滤下拉列表
我有一个功能问题,我有一个基于 Many2one 字段填充的下拉列表,应该显示为特定项目创建的所有角色,并且在第一次创建它带来的条目时工作正常应该是的元素,但是当我点击“编辑”并尝试更改角色时,下拉列表会显示系统中的所有角色。
# In the model this is how we fetch the roles per project.
role_id = fields.Many2one('project.task',required=True,string='Role')
def _get_tasks_ids(self):
tasks = self.env['project.task'].search([('project_id','=',self.env.context.get('default_project_id'))])
logging.info(tasks)
if tasks:
return tasks.ids
else:
return []
@api.onchange('role_id')
def fetch_task_ids(self):
task_list = self._get_tasks_ids()
if len(task_list)>0:
return {'domain': {'role_id': [('id','in',task_list)] }}
else:
# return empy list by default
return {'domain': {'role_id': [('id',-1)]}}
# the view
<group name="project_discounts_bottom" string="Role level adjustments" colspan="2">
<field name="discount_ids" string="" context="{'default_project_id':id}" widget="one2many_list">
<tree editable="bottom">
<field name="discount_type" widget="selection"/>
<field name ='adjustment_type' widget="selection" />
<field name="discount_value" />
<field name="role_id" />
<field name="discount_date_start" />
<field name="discount_date_end" />
</tree>
<form>
<field name="discount_type" widget="selection" />
<field name ='adjustment_type' widget="selection" />
<field name="discount_value" />
<field name="role_id" domain="[('project_id','project.id')]" />
<field name="discount_date_start" />
<field name="discount_date_end" />
</form>
</field>
</group>
仅在我编辑条目时可能导致此问题的原因是什么?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。