2016-11-11 4 views
0

Ich habe ein Modell Version, die eine Beziehung zu dem Produktmodell wie folgt hinzu:Wie korrigiere ich die Domäne zu einem Feld in einem one2many Feld in Odoo?

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

Ich füge ein Feld „version_filter zum sale.order Ansicht, und wollen nun Produktsuche nach dieser Beziehung filtern, aber nur sind diejenigen added nicht die vorherigen Zugabe

Like this:

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

Aber die "product_id" Feld wird nie ersetzen

.Ich würde lieber ein modales Formular als in "Suche mehr" -Option in many2one Felder machen ... aber wenn jemand mir helfen könnte, nach Domain zu filtern, ist die order_line product_id Suche mehr als ok

Danke fürs Lesen!

Antwort

0

Problem ist da mit dem XPath. Sie sollten versuchen, zu folgen.

Wenn Sie Domäne in Kundenauftragszeile -> Produkt-ID in der Formularansicht und in der Baumansicht hinzufügen möchten, dann ist das Beispiel unten angegeben.

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