【问题标题】:how to domain one2many field from another function field in odoo 8?如何从odoo 8中的另一个函数字段中定义one2many字段?
【发布时间】:2019-06-07 16:37:42
【问题描述】:

我想根据 get_loc_user 字段中的 location_id 过滤 get_parts_locations_rel_ids...但我无法得到它。

我在旧 api 中使用了 odoo 8

# this is my python code


_columns = {
        'get_loc_user': fields.function(check_location_user, string="loc_user", type="char"),
        'get_parts_locations_rel_ids': fields.one2many('parts.locations_rel','product_id','Locations'),
    }

# field 'get_loc_user' is a function that will return a list result such [1,2,3]

#-------------------------------

# in xml

<record id="product_normal_form_view_inherit" model="ir.ui.view">
            <field name="name">product.product.form</field>
            <field name="model">product.product</field>
            <field name="mode">primary</field>
            <field eval="7" name="priority"/>
            <field name="inherit_id" ref="product.product_template_form_view"/>
            <field name="arch" type="xml">
                <xpath expr="//field[@name='categ_id']" position="after">
                    <field name="get_loc_user"  />
                </xpath>
                <xpath expr="//field[@name='asset_ids']" position="after">
                    <field name="get_parts_locations_rel_ids">
                        <tree string="Locations" >
                            <field name="loc_case"/>
                            <field name="loc_row" />
                            <field name="loc_rack" />
                            <field name="location_id" />
                        </tree >
                    </field>
                </xpath>
            </field>
        </record>

我希望 one2many 字段 get_parts_locations_rel_ids 中的结果是根据 get_loc_user 字段按字段 location_id 过滤,但我不知道该怎么做

【问题讨论】:

    标签: python xml odoo odoo-8


    【解决方案1】:

    如果你想为get_loc_user 设置一个域,你可以在tree &amp; form view 像这样parent.get_loc_user 访问它

     <field name="location_id" domain="parent.get_loc_user and [('your_field_domain', '=', parent.get_loc_user)] or []"/>
    

    我不知道你到底需要什么,但我想你明白了

    【讨论】:

    • 感谢您的想法...但是什么是父母?我必须写父或父表单或树或模型还是什么?之前谢谢...对不起我的英语不好,我是odoo的新手...
    • 不,您不必声明它,它从 Odoo 开箱即用,这是从 One2many 字段(在树视图中)访问主模型字段的简单方法。就像你的情况一样,我不知道你在你的域中到底需要什么。
    • 正是我想要一个one2many字段...与我在谷歌learnopenerp.blogspot.com/2018/01/…找到的博客中完全相同的情况我尝试按照教程但我仍然无法得到它...对不起先生,我想再问一件事......哪个是正确的 domain="[('field_name', 'in', (1,2,3))]" 或 domain="[('field_name', '在',[1,2,3])]”?哪个是正确的使用元组或列表?先谢谢先生...
    • 两者都可以正常工作,但我习惯使用列表,所以我不会与很多括号混淆^^。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多