Odoo Help

2

1
1 Answer
0
user0780987 France
9/25/14, 9:56 AM

Suppose you have:

 <group>
    <field name="inspection_ids">
        <tree version="7.0">
            <field name="xxx" />
            <field name="xxx" />
            <field name="work_order_ids" string="Work Orders" widget="many2many_tags" />
        </tree>
    </field>
 </group>

and :

_columns = {
  'work_order_ids': fields.one2many('crm.work_order', 'inspection_id', 'Work orders'),
}

Each work order has a "name" like "YYMM1234". Instead of "14090059, 14090060", you see: "59,60" where 59 and 60 are the row ids. Modify your python and add a new column:

_columns = {
  'work_order_ids': fields.one2many('crm.work_order', 'inspection_id', 'Work orders'),
  'work_order_codes': fields.function(_get_work_order_codes, method=True, type='char', string='Work orders', store=False),
}

On top, add this function to transform reference objects to whatever you want to display, like "name".

def _get_work_order_codes(self, cr, uid, ids, field_name, arg, context):
  res = {}
  for ct_inspection in self.browse(cr, uid, ids, context):
    if ct_inspection.work_order_ids:
      res[ct_inspection.id] = [x.name for x in ct_inspection.work_order_ids]
    else:
      res[ct_inspection.id] = _(u'(No work order yet)')
  return res

Of course in your XML file, you have to replace "work_order_ids" with "work_order_codes":

 <group>
    <field name="inspection_ids">
        <tree version="7.0">
            <field name="xxx" />
            <field name="xxx" />
            <field name="work_order_codes" string="W.O." widget="many2many_tags" />
        </tree>
    </field>
 </group>

1 Comment
SYSMART Morocco
10/31/14, 6:25 PM

thanks that solve my pb to show name of o2m field in tree view using m2m_tags

Ask a Question
Writer
Tags
Keep Informed
0 follower(s)
About This Community

This platform 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.

Register
Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now