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

Domain on selection field

By
José
on 1/6/15, 8:38 PM 1,141 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?

Ivan
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')])

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

José
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?

Ivan
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 ?

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

Ivan
on 1/8/15, 6:19 AM

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

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

Ivan
on 1/8/15, 6:48 AM
0

Ahmed M.Elmubarak

--Ahmed M.Elmubarak--
2988
| 5 3 5
Sudan
--Ahmed M.Elmubarak--


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

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

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

3 follower(s)

Stats

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