Odoo Help


Domain on selection field

on 1/6/15, 8:38 PM 2,199 views

Hello, I am using Odoo8 and I want to define a domain in a many2many field, for a selection field. Specifically, the field is 'type' of model 'account.voucher'. I try ('type', '=', 'purchase') but not works; also I try ('type', 'like', 'purchase') but not works.

Is there a way to do this domain? Thanks!

From your description alone, it should work. Providing if you set the domain as [('type', '=', 'purchase')] or [('type', 'like', 'purchase')], i.e. don't forget to put the tuple in a list. So, if it does not work, you need to provide a greater detail on how you apply the domain, in a view? From fields definition? From Record Rules?

on 1/6/15, 11:22 PM

My domain is in the field definition. This is my code: pays = fields.Many2many('account.voucher', domain=[('es_acopio', '=', True), ('type', '=', 'purchase')])

on 1/7/15, 10:07 AM

Using this domain, I can't see any 'account.voucher' (of course I have various account.voucher of type purchase). If I quit ('type', '=', 'purchase'), I can see the records.

on 1/7/15, 10:13 AM

Your domain is a combination of 2 rules, and it is operating with and AND operator (the default). Maybe it is because you don't have data that satisfy both?

on 1/7/15, 11:41 PM

I have various records that satisfy both rules. Is this real: https://www.odoo.com/forum/help-1/question/domain-in-hardcoded-selection-field-21767 ?

on 1/8/15, 6:02 AM

It is correct that selection fields cannot have it's selections be filtered by domain. But what you are trying to achieve is to domain account.voucher using a selection field, which is different. I'm running out ideas. If you really have records that satisfy both rules (SELECT * FROM account_voucher WHERE type = 'purchase' AND es_acopio = TRUE returns record that belongs to the company the user is currently logged in), I can't think of any other reasons. Try to increase your level of debugging to debug_sql and see that SQL command that is issued.

on 1/8/15, 6:19 AM

How can I see the SQL command and the result of this?

on 1/8/15, 6:24 AM

To see the SQL command you need to set the log_level (either from the command line [--log-level] or configuration file [log_level], to 'debug_sql').

on 1/8/15, 6:48 AM
--Ahmed M.Elmubarak--

Ahmed M.Elmubarak
On 1/8/15, 7:01 AM

Actually it is working fine ...

first define your many2many field with the domain just like:

_columns = {
        'voucher_ids': fields.many2many('account.voucher','voucher_test_rel','test_id', 'voucher_id','Voucher',domain="[('type','=','purchase')]"),

then to be sure create a new voucher with type(Default Type) purchase from  Accounting->Journal Entries->Journal Vouchers

also you can test it from postgresql ..
loggin as postgres: sudo su postgres
then enter sql mode : psql
then connect to your database name : \c db_name
then query your account_voucher: select type from account_voucher;

I hope this could help

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

3 follower(s)


Asked: 1/6/15, 8:38 PM
Seen: 2199 times
Last updated: 3/16/15, 8:10 AM