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

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

By
Yanina Aular
on 10/30/13, 4:59 PM 840 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.

1
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

        no_incluir[2]+=l_ids

        args.append(no_incluir)

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

Hope you like it. :)

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: 10/30/13, 4:59 PM
Seen: 840 times
Last updated: 3/16/15, 8:10 AM