acc returns None, but I know this account exists, so it should return the account. Running the above code with logging enabled, I see that the generated SQL statement for the search has the following WHERE clause:
WHERE ((("a"."code" = \'100-500\')) AND ((false))) ORDER BY "a"."code" ASC, "a"."name" ASC, "a"."id" ASC LIMIT 1
There is a additional AND ((false)) statement that is the cause that no records are returned, and I don’t know where is being generated or why. Does anyone know where the problems is?
I dug a little bit deeper and found out that the cause of this AND ((false)) statement may be due to the a call to Rule.domain_get(cls.__name__) in ModelSQL.__search_query(); and for the account.account, it generates a domain clause like ['company', 'in', []] which might eventually evaluates to False. How do I avoid this call from generating this clause?
In the my sample code, I have added the company that I want to the context, but that didn’t work. So my guess is that I have to set the user’s current company too? How do I do that?
Thank you for the tip. It appears that not only the user needs to have the company added to his list of companies in order to have access, but also, the user’s current company needs to be set. Maybe a little bit of documentation would be nice to have to know which models depend on ir.user → companies and company fields and which depends on the context company to be set. It is sometimes a bit confusing, but I have figured out.