基于另一个领域的域

Domain for on field based on another

在任务模板表单中我可以添加 group_id。我想创建一个域,根据它们所属的组添加任务模板,但现在有点不知道。

class ProjectTaskGroup(models.Model):
    _name = 'project.task.group'
    _inherit = 'project.object'

    name = fields.Char(string="Name", required=True)


class ProjectTaskTemplate(models.Model):
    _name = 'project.task.template'
    _inherit = 'project.object'

    name = fields.Char(string="Name", required=True)
    group_id = fields.Many2one('project.task.group', string="Task Group")
<!-- Project Task Views -->
<record id="view_task_form2" model="ir.ui.view">
    <field name="name">project.task.form</field>
    <field name="model">project.task</field>
    <field name="inherit_id" ref="project.view_task_form2"/>
    <field name="arch" type="xml">
        <xpath expr="//div[@class='oe_title']" position="before">
            <div class="oe_inline oe_edit_only">
                <field name="group_id" class="oe_inline"/>
                <field name="task_template_id" class="oe_inline"/>
            </div>
        </xpath>
    </field>
</record>

首先在模型中添加字段'project.task.group'

template_id = fields.One2many('project.task.template', 'group_id', string='Group task')

'project.task'领域

task_template_id = field.Many2one('project.task.template') 
group_id=field.Many2one('project.task.group')

鉴于'project.task'

<field name="task_template_id" class="oe_inline"/>
<field name="group_id" class="oe_inline" domain="[('template_id', '=', task_template_id)]"/>

第一个 select 模板所以我们得到 group_id 属于 task_template_id