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

Strange behavior of record rule

By
Tomas Parnarauskas
on 6/17/13, 4:38 AM 1,633 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?

2

Sandeep

--Sandeep--
6083
| 6 5 8
Delhi, India
--Sandeep--
Python OpenERP Developer http://in.linkedin.com/pub/sandeep-rana/3b/a16/786/
Sandeep
On 6/17/13, 5:27 AM

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

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?

NOD Baltic, UAB, Tomas Parnarauskas
on 6/17/13, 5:48 AM

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

Sandeep
on 6/17/13, 6:54 AM

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.

NOD Baltic, UAB, Tomas Parnarauskas
on 6/17/13, 8:37 AM

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

0 follower(s)

Stats

Asked: 6/17/13, 4:38 AM
Seen: 1633 times
Last updated: 3/16/15, 8:10 AM