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 (将#修改为@)