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

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

By
vadivel
on 6/13/14, 1:24 AM 1,233 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'),
    }
invoice_type()

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...

3

Serpent Consulting Services Pvt. Ltd.

--Serpent Consulting Services Pvt. Ltd.--
4341
| 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

Vadivel,

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()

Thanks.

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

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

1 follower(s)

Stats

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