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.

0

many2many automaticly filled

By
Francisco Castro
on 3/7/14, 5:27 AM 4,782 views

Hi guys Help me I want to fill the many2many filled automaticly withou have to click on the add button

image description

I want fo fill the mannu "Lista de Pets" with the records on the "pets" when I click on the "Lista de Pets"

It is possible?

Show me an example please

5

René Schuster

--René Schuster--
1560
| 5 5 8
Weinheim, Germany
--René Schuster--

Challenge Everything!

René Schuster
On 3/7/14, 5:53 AM

If you just want to view a list of all the pets, I recommend a wizard (osv.osv_memory).

Anyway, wizard or not:
Add a default value for your many2many field and use a function to get all pets.

_columns = {
    'pet_ids' = fields.many2many(.....),
}

def _get_default_pet_ids(self, cr, uid, context=None):
    return self.pool.get('your_pet_module').search(cr, uid, [])

_defaults = {
    'pet_ids' = _get_default_pet_ids,
}

That's it.

EDIT:

The standard way to filter your data is using a search view.
But if you want to use a selection field do something like this:

def onchange_onwer_id(self, cr, uid, ids, val):
    ids = self.pool.get('your_pet_module').search(cr, uid, [('owner_id','=',val)])
    return {'value' : {'pet_ids' : ids}} 

_columns = {
    'pet_ids' = fields.many2many(.....),
    'owner_id' = fields.many2one(.......),
}

and in your .xml:

<field name="owner_id" on_change="onchange_owner_id(owner_id)"/>

thank you very much man. And if I want to put a selection filed to filter the records how can I do it?

Francisco Castro
on 3/7/14, 6:17 AM

I have the 'owner_id' many2one filed I want to filter the pets by owner

Francisco Castro
on 3/7/14, 6:27 AM

another question if u could help me... I want to put checkbox into the rows and when it are check load buttons to delete the records from the database. like in tree view when you check the checkbox, pops up a button and we can delete the records. I want the same and with the same button if its possible

Francisco Castro
on 3/7/14, 8:06 AM

I guess I don't know the answer to this question. Try removing the widget on your many to many field, or something. ^^

René Schuster
on 3/7/14, 8:11 AM

ok thanks a lot you helped very much :)

Francisco Castro
on 3/7/14, 8:26 AM

If I want to remove the 2 first rows on the many2many field by clicking on a button ("Remove") wich function I have to do? (btw you have to put here your email or skype eheh I have some questions and you help a lot)

Francisco Castro
on 3/7/14, 8:55 AM

could you help me in another problem? hehe pls go to my question "many2many button action" if you know it pls explain me :)

Francisco Castro
on 3/12/14, 6:48 AM

Great sample :) It missed a : at the function so I corrected that. Thanks René

Yenthe
on 6/29/15, 10:23 AM

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: 3/7/14, 5:27 AM
Seen: 4782 times
Last updated: 6/29/15, 10:23 AM