This question has been flagged
1 Reply
14054 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!
 

Avatar
Discard

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?

Author

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

Author

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.

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?

Author

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 ?

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.

Author

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

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

Best Answer

Hello,
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

Avatar
Discard