Odoo Help


make two one2many fields that relate to the same model are mutually exclusive

Yanina Aular
on 10/30/13, 4:59 PM 1,343 views

The model "model.name" has two one2many fields that relate to the same model "model.name". I would like that to have added a register in the c1 field(one2many to "model.name"), and may not be available in my c2 field(other one2many to "model.name") list when I click add item.

Yanina Aular
On 10/31/13, 1:42 PM

How to make a more specific domain or how to filter one2many or Many2Many field with complex parameters?

Hi friends, i find the way to resolve my problem. I have two one2many fields (invoice_ids and aml_ids), invoice_ids related with account.invoice and aml_ids related with account.move.line. So, you wish that to add a new item into aml_ids to make click in Add Item, the account.move.line options list be filtrered and not show the account.move.lines that is related with the invoices_ids.

So, i rewrote the _search method, which is called when you have domain into the field (in our case aml_ids). I pass invoice_ids value for context in aml_ids field of view.

<field name='invoice_ids'/>
<field name='aml_ids'  domain="[('partner_id','=',partner_id) ]" context="{'has_invoice_ids':invoice_ids}" />

So, to make click on aml_ids Add Item, it makes the call to _search in account.move.line model. We added the argument to args variable ['id', 'not in', ids_list_not_be_included ] , and so not be show in list.

    class account_move_line(osv.Model):                                                             
    _inherit = 'account.move.line'

    def _search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, 
              count=False, access_rights_uid=None):

        move_obj = self.pool.get('account.move.line')

        lista_invoice = context.get('has_invoice_ids', False)
        lista_invoice = lista_invoice and lista_invoice[0] or []
        lista_invoice = lista_invoice and lista_invoice[2] or []

        no_incluir = ['id', 'not in', [] ] 
        l_ids = []

        if lista_invoice:
            for inv in lista_invoice:
                moves_up = move_obj.search(cr, uid,[('invoice','=',inv)] )
                l_ids = l_ids + moves_up



        return super(account_move_line, self)._search(cr, uid, args, offset=offset,
             limit=limit, order=order, context=context, count=count,

Hope you like it. :)

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.


Odoo Training Center

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

Test it now

Question tools

0 follower(s)


Asked: 10/30/13, 4:59 PM
Seen: 1343 times
Last updated: 3/16/15, 8:10 AM