Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

1

How do I change the columns displayed in a many2many tree view?

By
AJ Schrafel Paper Corp
on 4/20/13, 7:50 PM 8,952 views

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.

8

AJ Schrafel Paper Corp

--AJ Schrafel Paper Corp--
2060
| 4 5 8
Bronx, United States
--AJ Schrafel Paper Corp--

Exploring OpenERP for business

AJ Schrafel Paper Corp
On 4/23/13, 4:08 PM

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>
1
Lucas
On 4/23/13, 12:10 PM

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

0
klacus
On 4/21/13, 2:58 AM

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

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

AJ Schrafel Paper Corp
on 4/21/13, 4:54 PM

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

klacus
on 4/22/13, 1:59 AM

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

Lucas
on 4/23/13, 12:06 PM

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

klacus
on 4/23/13, 2:07 PM

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

Lucas
on 4/23/13, 3:08 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 4/20/13, 7:50 PM
Seen: 8952 times
Last updated: 3/16/15, 8:10 AM