如何更正将域添加到Odoo中one2many字段内的字段?

时间:2016-11-11 00:26:53

标签: openerp odoo-8 odoo-9 odoo-view

我创建了一个模型版本,像这样添加产品模型的关系:

class product_template(models.Model):
    _inherit = 'product.template'

    versions_ids = fields.Many2many('mymodel.version',string='Versions')

class sale_order(models.Model):
    _inherit = 'sale.order'

    version_filter = fields.Many2one('mymodel.version')

我在sale.order视图中添加了一个字段" version_filter,现在想要通过这种关系来过滤产品搜索,但只添加不添加之前的那些

像这样:

<record id="sale_filter_append" model="ir.ui.view">
    <field name="name">sale.order.form</field>
    <field name="model">sale.order</field>
    <field name="inherit_id" ref="sale.view_order_form"/>
    <field name="arch" type="xml">
        <xpath expr="//field[@name='order_line']" position="before">
            <group colspan="4">
                <field name="version_filter"/>
            </group>
        </xpath>
        <xpath expr="//field[@name='product_id']" position="replace">
            <field name="product_id"
                   context="{'partner_id':parent.partner_id, 'quantity':product_uom_qty, 'pricelist':parent.pricelist_id, 'uom':product_uom, 'company_id': parent.company_id}"
                   attrs="{'readonly': ['|', ('qty_invoiced', '&gt;', 0), ('procurement_ids', '!=', [])]}"
                   domain="[('version_filter', 'in', versions_ids)]"
            />
        </xpath>
    </field>
</record>

但&#34; product_id&#34;领域永远不会取代。

我宁愿制作一个模态形式,如&#34;搜索更多&#34; many2one字段中的选项...但如果有人可以帮助我按域过滤order_line product_id搜索它比ok更好

感谢阅读!

1 个答案:

答案 0 :(得分:1)

xpath存在问题。你应该尝试一下。

如果您想在销售订单行中添加域名 - &gt;表单视图和树视图中的product_id然后是下面给出的示例。

<xpath expr="//notebook/page[@string='Order Lines']/field[@name='order_line']/form/group[1]/group/field[@name='product_id']" position="attributes">                 
    <attribute name = "domain">Add your domain</attribute>
</xpath>

<xpath expr="//notebook/page[@string='Order Lines']/field[@name='order_line']/tree[@string='Sales Order Lines']/field[@name='product_id']" position="replace">
    <field name="product_id" context="{'partner_id':parent.partner_id, 'quantity':product_uom_qty, 'pricelist':parent.pricelist_id, 'uom':product_uom, 'company_id': parent.company_id}"
        attrs="{'readonly': ['|', ('qty_invoiced', '&gt;', 0), ('procurement_ids', '!=', [])]}"
        domain="[('version_filter', 'in', versions_ids)]" />        
</xpath>