Odoo如何在一个字段中过滤多个字段值 [英] Odoo how to filter many2one field values in one2many field

查看:918
本文介绍了Odoo如何在一个字段中过滤多个字段值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多字段 name_id .通常,当我在此字段下面的 my_model.xml 代码中使用它时,我可以从 my.model.line 中编写的所有值中进行选择. 在这种情况下,我想过滤值并仅查看在当前my.model中编写的这些值的列表.

I have many2one field name_id. Usually when I use it in my_model.xml code below in this field I can select from all the values written in my.model.line. In this case I want to filter values and see the list of only these values which are written in current my.model.

my_model.xml

my_model.xml

    <record model="ir.ui.view" id="view_my_model_form">
        <field name="name">my.model.form</field>
        <field name="model">my.model</field>
        <field name="arch" type="xml">
            <form string="My Model">
            <header>

                        <field name="my_model_line">
                            <tree>
                                <field name="name"/>
                            </tree>
                         </field>
               <notebook>
                    <page>
                        <field name="supply_conditions_status">
            <tree string="My model Lines">
                                <field name="name_id"/>
                            </tree>

课程:

class SupplyConditions(models.Model):
    _name = 'supply.conditions'

    name_id = fields.Many2one('my.model.line', string='Product')
    model_id = fields.Many2one('my.model')


class MyModelLine(models.Model):
    _name = 'my.model.line'

    name = fields.Char('Name')
    my_model_id = fields.Many2one('my.model')

class MyModel(models.Model):
    _name = 'my.model'

    title = fields.Char('Title')
    my_model_line = fields.One2many('my.model.line', 'my_model_id')
    supply_conditions_status = fields.One2many('supply.conditions', 'model_id')

为了更清楚地理解-示例:

For clearer understanding - example:

我有my.model(字段名称='first')和my.model(字段名称='second')的表单视图.

I have form view of my.model (field name = 'first') and my.model (field name = 'second').

在my.model中(名称='first') 在my_model_line名称字段中添加了数据:"item1","item2"

In my.model (name = 'first') In my_model_line name field added data: 'item1', 'item2'

在my.model中(名称='second') 在my_model_line名称字段中添加了数据:"1item","2item"

In my.model (name = 'second') In my_model_line name field added data: '1item', '2item'

现在:

在my.model中(名称='first') supply_conditions_status name_id字段我看到以下选项:'1item','2item,item1','item2'

In my.model (name = 'first') supply_conditions_status name_id field I see selection of: '1item', '2item, item1', 'item2'

需要:

在my.model中(名称='first') supply_conditions_status name_id 仅从"item1","item2"中选择的可能性

In my.model (name = 'first') supply_conditions_status name_id possibility to select only from 'item1', 'item2'

我该如何实现?

推荐答案

您可以通过将domain赋予您的many2one字段来实现此目的. 试试这个:

You can achieve this by simply giving domain to your many2one field. try this:

name_id = fields.Many2one('my.model.line',string ='Product',domain = lambda self:[('my_model_id','=',self.model_id)])

name_id = fields.Many2one('my.model.line', string='Product', domain=lambda self: [('my_model_id', '=', self.model_id)])

这篇关于Odoo如何在一个字段中过滤多个字段值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆