Just select the first field with its value between two classes

advertisements

When I created a many2many relation between 2 classes it showed me all the class in openerp. How to select just the first field with his value?

class f_produit_fabrique(osv.osv):
"""(NULL)"""
_name = 'f.produit.fabrique'
_columns = {
    'code_prod': fields.char('Code_prod',size=30,required=True),
    'lib_prod': fields.char('Lib_prod',size=30,required=True),
    'coefficient':fields.integer('Coefficient',required=True),
    'produit_achete':fields.many2many('a.produit.achete'),
}

f_produit_fabrique()

class a_produit_achete(osv.osv):
"""(NULL)"""
_name = 'a.produit.achete'
_columns = {
    'code_prod': fields.char('Code_prod',size=30,required=True),
    'lib_prod': fields.char('Lib_prod',size=30,required=True),
    'prix_produitachete':fields.float('Prix_produitachete',size=30,required=True),
    'quantite':fields.float('quantite',size=30,required=True),
    'fournisseur_a_fournir': fields.many2one('fournisseur','fournisseur'),
}

a_produit_achete()


Many2many

  • Bi-directional multiple relationship between objects.
  • This is the most general kind of relation: a record may be related to any number of records on the other side, and vice-versa.
  • In the case of a many-to-many relationship, each row in Products is linked to zero, one or many rows in Taxes and vice versa. Normally, New Table a mapping table is required to map such kind of relationships.
  • In this relationship new table is required to store reference of the both table.

When you access this fields from odoo classes or in xml it will return the list of browsable objects of relational table.

So when you just display simple m2m field in xml file then it will gives the list of all columns in tree view, if you want to display only specific fields then you need to specify those fields in tree.

<field name="m2m_field_name" >
    <tree>
        <field name="relation_table_field1"/>
        <field name="relation_table_field2"/>
        <field name="relation_table_field3"/>
    </tree>
</field>

And if you want only one field over there and you want to display it like multi selection combobox then you need to apply widget over there.

<field name="m2m_field_name" widget="many2many_tags" />

It will display name field if name field is not there then it will bring _rec_name field's value over there.