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?
My domain is in the field definition. This is my code: pays = fields.Many2many('account.voucher', domain=[('es_acopio', '=', True), ('type', '=', 'purchase')])
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?
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.
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').