モデル バージョンを作成し、次のように製品モデルに関係を追加します。
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', '>', 0), ('procurement_ids', '!=', [])]}"
domain="[('version_filter', 'in', versions_ids)]"
/>
</xpath>
</field>
</record>
ただし、「product_id」フィールドは決して置き換えられません。
many2oneフィールドの「もっと検索」オプションのように、モーダルフォームを作成したいのですが...ドメインでフィルタリングするのを手伝ってくれる人がいれば、order_line product_id検索は大丈夫です
読んでくれてありがとう!