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

"many2many_tags" show a refrence of the tag not the name !!

By
nuha almadani
on 7/10/13, 8:12 AM 3,066 views

I'm trying to make a tag field in my module and whenever I try to show it in the XML view it shows a reference of the tag not the name of the tag it self

this is my code:

PYTHON

class podcast(osv.osv): _name = 'podcast'
_columns ={ ... fields.....

http:// (image description) 'tag':fields.many2many('podcast.tag','tag_realation','podcast_tag','podcast_name','Podcasts') }

class tag_name(osv.osv): _name = 'podcast.tag'
_columns ={ 'tag_name':fields.char('tag Name', size=64, required=True), 'tag':fields.many2many('podcast','tag_realation','podcast_name','podcast_tag','Tags')
}

XML FILE (VIEW) <field name="tag" widget="many2many_tags"/>

Hi, I think that I have the same question http://help.openerp.com/question/42855/how-to-put-taxes-name-in-seletion-on-sale-order-line-creation/... But I didn't realize that could be from many2many_tags -.-' Hope that someone answer us ...

Versão Integral, Anabela Damas
on 1/30/14, 1:32 PM
0
user0780987
On 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>

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

Mohamed Essakali
on 10/31/14, 6:25 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: 7/10/13, 8:12 AM
Seen: 3066 times
Last updated: 3/16/15, 8:10 AM