Ir al contenido
Menú
Se marcó esta pregunta
3 Respuestas
54139 Vistas

I have a custom module with a tree view that display a many2many field. Everything works fine, i would just like to display different fields in the tree view.

This is the pertinant part of the code

<group>
    <tree string="Partner Contacts">
        <field name="partner_id" domain="[('customer','=',True),('opt_out','=',False)]"/>
    </tree>
</group>

Using the above XML code, the tree view displays the columns Name, Phone, Email.

How can I modify it so that the columns display are Name, City, State?

Thanks.

Avatar
Descartar
Autor Mejor respuesta

I fixed it by doing the following:

<group>
<field name="partner_id" widget="many2many">
   <tree>
      <field name="name"/>
      <field name="city"/>
      <field name="state"/>
   </tree>
</field>
</group>
Avatar
Descartar

Still works in Odoo 10

<field name="partner_id" widget="many2many_tags">

in odoo 11

Mejor respuesta

You may define a custom tree view with the fields you want to show and explicitly use it for your many2many field

doc.openerp.com/v6.0/developer/2_6_views_events/views/specify_view_to_use.html

<field name="order_line" colspan="4" nolabel="1" context="{'form_view_ref' : 'module.view_id', 'tree_view_ref' : model.view_id'}"/>

where 'tree_view_ref' points to your custom tree view

Avatar
Descartar
Mejor respuesta

Please check this sample. The model has a many2one field. This many2one is Calib_id. This is a connection with a two table. csyscmeascalibrate >> csyscmeascalibraterow. You can use this way to see what you want, and filter the data if is it necessary.

Xml.:

        <record model="ir.ui.view" id="csysc_measuringtoolcalibration_form_view">   
        <field name="name">csysc_measuringtoolcalibration.form</field>
        <field name="model">csyscmeascalibrate</field>
        <field name="type">form</field>       
        <field name="arch" type="xml">
        <form string="Measuring Equipment Calibration Plan">
                <group colspan="4" col="6">                                 
                <field name="name"/>     
                <field name="Title"/>
                <field name="ISO_form_number"/>
                <field name="type"/>    
                </group>  
                                <notebook colspan="4">
                                    <page string="Controlled Calibration points">
                                     <field colspan="4" name="Calib_lines" nolabel="1" widget="one2many_list" mode="tree"/>                                                                                                 
                                    </page>
                                </notebook>         


            </form>             
        </field>
    </record>

python

class csyscmeascalibraterow(osv.osv):
_name = "csyscmeascalibraterow"
_description = "calibration data sheet"
_columns = {    
    'name'  : fields.char('Calibration point:',size=40, required = True, help='The name of the calibration point, like jig width or ring diameter...etc'),
    'Calib_id':fields.many2one('csyscmeascalibrate','Parent Calibration', select=False, ondelete='cascade'),
    'NomValue' : fields.float('Nominal Value:',size=40, required = False, help='Nominal measuring value: like 12.00'),
    "Max_deviation" : fields.char('Max deviation:',size=40, required = False, help='Maximum deviation from nominal measuring value: like 12.00'),
    }
csyscmeascalibraterow() 


class csyscmeascalibrate(osv.osv):
_name = "csyscmeascalibrate"
_description = "calibration data sheet"
_columns = {
    'name'  : fields.char('Calibration Name:',size=40, required = True, help='The name of the calibration like Calipper 0-150...etc'),
    'Title'     : fields.char('Calibration title:',size=40, required = True, help='Title of the calibration point, like measuring series with jig...'),     
    'ISO_form_number' : fields.char('Iso Form Number:',size=40, required = False, help='The ISO system form number'),
    'type': fields.many2one('csyscmtooltypes','Equipment type',required = True),
    'Calibration_child_row_id': fields.many2one('csyscmeascalibrate','csyscmeascalibrate'),
    'Calib_lines': fields.one2many('csyscmeascalibraterow', 'Calib_id', 'Calibration Plan id'),  
        }
csyscmeascalibrate()
Avatar
Descartar
Autor

thank you for your comment, but how does this change the columns automatically displayed when a many2many field is displayed?

As I think this is depend the relation. Please put it your code, and the situation will be clear, what you want...

klacus, your example does not customize the fields you want to show within the nested tree view

Yes because this is show all of the fields from csyscmeascalibraterow. If you want to show a special view, you must declare it in xml, and after that you need to call according by tree name. (As I know :-) )

"i would just like to display different fields in the tree view.", that's the key part

Publicaciones relacionadas Respuestas Vistas Actividad
4
jun 25
11057
0
mar 15
6848
2
mar 15
9593
3
may 23
2136
1
abr 23
3703