This question has been flagged
1 Reply
4839 Views

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

image description

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?

Avatar
Discard
Best Answer

Hi

this problem happen many time because, there is a security rule already added for this case

for solved it you have to do one thing

  1.  your user company should be false (means no company selected )  or the main company  in ` user record`
   or
  2 . you will have to create a complete rule for that company if company is change and you want to select new company for this user

then there will be no error's

even you can check it, just inactive that rule (a default rule) from settings - --> technical --> security --> records rules menu , then you will see that this error never happen

Thanks
Sandeep

Avatar
Discard
Author

I tried to make inactive 'user rule'. But problem is still here (I tried to disable default company rule too). Also in my database there is only one company. And it seems strange that old users don't get this error, when they are added to the same company as new users. Am I doing something wrong?

must check res.partner company rule , for same company there should not be any problem

Author

I disabled that rule, but still getting this error. Don't understand what's wrong. Also it does not happen in any other database (record rules are the same) with or wthout checking res.partner company rule.