0

モデル バージョンを作成し、次のように製品モデルに関係を追加します。

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')

「version_filter」フィールドをsale.orderビューに追加し、この関係で製品検索をフィルタリングしたいのですが、以前に追加されたものではなく、追加されたものだけです

このような:

<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>

ただし、「product_id」フィールドは決して置き換えられません。

many2oneフィールドの「もっと検索」オプションのように、モーダルフォームを作成したいのですが...ドメインでフィルタリングするのを手伝ってくれる人がいれば、order_line product_id検索は大丈夫です

読んでくれてありがとう!

4

1 に答える 1

1

xpath に問題があります。フォローしてみてください。

受注明細にドメインを追加する場合 -> フォーム ビューとツリー ビューの両方で 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>
于 2016-11-11T04:42:15.037 に答える