I encountered strange behavior of custom access rule and it happens at only one database (don't know how it is different from others).
So I created this record rule (on res.partner object for read, write, create and delete):
['|',('user_id','=',user.id),('user_id','=',False)]
When I create new user and give it group with this rule it gives me error when I try to create new partner (or when I try to open that users window, for example through salesperson field (it looks like that user don't have access to himself..)):

The stranger thing is that this error does not show up with old users. When I give them same access rights, it creates new partners without problems. Also if I duplicate old user it also bypasses this error. So it seems something is wrong with creating new users.
I also tried to backup and restore that database to another server where are no such problems, but it gives this error there too. So it seems modules are fine. Something has to be with configuration in database, but I don't know what could be wrong.
Any ideas?
EDIT:
I managed to pinpoint why this rule was behaving so strange with newly created users. The problems seems to be with module I created. That module sets default salesman on partner when it presses create button in partners view. For example if John Doe presses button to create new partner he will be automatically assigned as salesman to that partner.
Somehow this module blocks new users as being default ones for salesman on any partner. With old users (before installing that module) it works even when that module is installed.
My module is very simple, but I don't see it why it corrupts newly created users (and only when record rule that I talked earlier about is applied).
Code looks like this:
from openerp.osv import osv
class res_partner(osv.osv):
_name = 'res.partner'
_inherit = 'res.partner'
_defaults = {
'user_id': lambda obj, cr, uid, context: uid,
}
res_partner()
Should such module have to be defined somehow differently? Or did I miss something?
↧