主模型改变,过滤子模型
True
当主模型发生改变时,希望子模型也随着改变而过滤
主模型
class ArrangeClassManage(models.Model):
_name = 'funenc_xa_station.arrange_class_manage'
_description = u'排班规则管理'
_inherit = 'fuenc_station.station_base' //

name = fields.Char(string='名称', compute='_compute_name')

obj_selection = fields.Selection(selection=[('arrange_class', '班组'), ('motorized', '机动人员')],
default="arrange_class") # 班组对象
remarks = fields.Text(string='备注')

order_to_arrange_ids = fields.One2many('arrange_order_to_arrange_class_manage', 'arrange_class_manage_id',
string='排班类型', required=True)
主模型继承字段
class fuenc_station(models.Model):
_name = 'fuenc_station.station_base'

site_id = fields.Many2one('cdtct_dingtalk.cdtct_dingtalk_department', string='站点',
)
line_id = fields.Many2one('cdtct_dingtalk.cdtct_dingtalk_department', string='线路',
)


子模型
class ArrangeOrderToArrangeClassManage(models.Model):
'''
为什么要采取自定义中间表因为班次可以重复选择
'''
_name = 'arrange_order_to_arrange_class_manage'
_description = '班次和排班规则中间表'


  
get_site_id = fields.Integer(
    compute="_compute_site_id",
    readonly=True,
    store=False,
)
    arrange_class_manage_id = fields.Many2one('funenc_xa_station.arrange_class_manage', string='排班规则')
arrange_order_id = fields.Many2one('funenc_xa_station.arrange_order', string='排班班次')

@api.depends('arrange_class_manage_id.site_id')
def _compute_site_id(self):
    for this in self:
        this.get_site_id = this.arrange_class_manage_id.site_id.id


xml文件

<field name="line_id" string="线路" options="{'no_create':True,'no_open':True}"
domain="product_id_domain" required="1"/>
<field name="site_id" string="站点" options="{'no_create':True,'no_open':True}"
domain="product_site_id_domain" required="1"/>
<field name="order_to_arrange_ids" string="排班类型">
<tree editable="top" class="noOpen">
<field name="get_site_id" context="{'get_site_id':get_site_id}" invisible="1"/> <!--站点信息保存在这里-->
<field name="arrange_order_id" string="班次" domain="[('site_id','=',get_site_id)]"
            options="{'no_create':True,'no_open':True}"/> <!--并且这里可以形成动态domain-->

</tree>
</field>






odoo 对 many2many one2many的操作
True