Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
1 Rispondi
8199 Visualizzazioni

Hey there!

Let's suppose that I'm working on a system that allows the user to create a product and assign different tags for that product (as a many2many relationship - a lot of tags already exist and the user can assign as many as he wants to a specific product). I want, however, to also create a field that will make one of these assigned tags "special". I want the user to be able to select one tag among all the tags he have previously assigned to this specific product. How can I do that? so far, I've tried to create a many2one field with a "compute" function, returning all tags assigned to the product as a list of (id, tag_name) pairs, but it didn't work. 


Anyone know how to do it? Thanks in advance.

Avatar
Abbandona
Risposta migliore

Hello Henrique,

Try this:

create fields in python file :

'contact_person_many': fields.many2many('dispatch.contact.person', string='Contact Persons', required=True),        'contact_person_one': fields.many2one('dispatch.contact.person', string='Contact Person'),


def onchange_contact_person_many(self, cr, uid, ids, contact_person_many, context=None):
        if contact_person_many:
            li_emp = []

            for i in contact_person_many[0][2]:
                li_emp.append(i)           

            emp = tuple(li_emp)     

           return {'domain': {'contact_person_one': [('id', 'in', emp)]}}

     In xml file:

<field name="contact_person_many" widget="many2many_tags" on_change="onchange_contact_person_many(contact_person_many)"/>                      

<field name="contact_person_one"/>

Avatar
Abbandona
Post correlati Risposte Visualizzazioni Attività
0
ott 20
3166
1
ago 17
3616
0
ago 17
3669
1
mar 15
17952
1
mar 15
6137