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.
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- 客户关系管理
- e-Commerce
- 会计
- 库存
- PoS
- Project
- MRP
此问题已终结
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. :)