Odoo Help


I have a huge doubt on Domain filter for many2many fields?

on 6/13/14, 1:24 AM 2,376 views

I have created one class named invoice.type which has fields like:

class invoice_type(osv.osv):
    _name = "invoice.type"
    _columns = {
        'name': fields.char('Name',size=32),
        'code': fields.char('Code',size=32),
        'acc_journal_id': fields.many2many('account.journal','account_journal_rele','journal_id','invoice_id','Account Journal'),

In customer Invoice i have created a many2one class like this:

'invoice_type': fields.many2one('invoice.type','Invoice'),

'journal_id': fields.many2one('account.journal', 'Journal', required=True, readonly=True, states={'draft':[('readonly',False)]}),
        'company_id': fields.many2one('res.company', 'Company', required=True, change_default=True, readonly=True, states={'draft':[('readonly',False)]})

In customer Invoice i have to assign all journal_ids to default journal_id field based on this name selection:

 I will create name fields as domestic and journal in many2one and i will map sale journals for that.when i select that name field in invoice i need to assign all those journals in journal_id column in invoice where i have mapped journals against that name.Can anyone help me please as soon as possible!!!!!!!!!!!!!!Thanks in advance...


Serpent Consulting Services Pvt. Ltd.

--Serpent Consulting Services Pvt. Ltd.--
| 6 6 8
Gandhinagar, India
--Serpent Consulting Services Pvt. Ltd.--

Serpent Consulting Services Pvt. Ltd. Your Odoo/OpenERP Solution, just an email away!

Serpent Consulting Services Pvt. Ltd.
On 6/13/14, 5:50 AM


You have source info as many2many and target journal_id is many2one, so you can surely not assign ALL journals to journal_id column.

As a solution, you can do any of the following:

1. On selecting the invoice_type, write an on_change which will set value on journal_id.

2. On selecting the invoice_type, write an on_change which will set value on journal_id, and set domain for that field so you can only have limited choices of journal ids based on invoice_type.

3. Add a field many2many inside journal_id, which links to invoice.type. On customer invoice, use the domain like

: [('invoice_type_ids','in',[invoice_type])]

Hope this helps.

Addition in the answer:

- You can use the onchange and set the 0th value.

- Or, override default_get()


This works ok. in my case, I used the syntax domain="[('partner_ids', '=', partner_id)]. But now suppose that I want to have a default value... should be "the first in the list". Is there a way to do directly in the view? If not, how should I?

Daniel Blanco
on 4/10/15, 5:56 PM

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

1 follower(s)


Asked: 6/13/14, 1:24 AM
Seen: 2376 times
Last updated: 4/11/15, 4:12 AM