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.

1

Write method

By
Ajeng Shilvie
on 12/20/14, 4:47 AM 765 views

i want to update my field depend on current user's group , but when i execute the method it update all the record even it has the other group .

here's the code :

def wtc_approval(self, cr, uid, ids,vals, context=None):
        user = self.pool.get("res.users").browse(cr, uid, uid)['groups_id']
        data = self.pool.get("wtc.approval.line").browse(cr,uid,user)
        line = self.browse(cr, uid, ids, context=context)
   
        for user in line.app_line:
            line.app_line.write({
                                   'sts':'2',
                                   'pelaksana':uid,
                                   'tanggal':datetime.today()
                                   })
           return True

i don't know how to get current user group , the code always catch all group ..

anybody know how to resolve it ?

Thanks in advance

0

Atchuthan - Technical Consultant, Sodexis Inc

--Atchuthan - Technical Consultant, Sodexis Inc--
3918
| 5 3 8
Puducherry, India
--Atchuthan - Technical Consultant, Sodexis Inc--
Passionate coder in Python/Odoo(formerly known as OpenERP).

Contact me via GMail: atchuthantu@gmail.com via Skype: atchuthan_skype
via Linkedin: http://in.linkedin.com/in/atchuthantu
Atchuthan - Technical Consultant, Sodexis Inc
On 12/22/14, 12:44 AM

You can try to find whether the user has Group access for a particular group.

Flag = self.pool.get('res.users').has_group(cr,create_uid.id , 'base.group_sale_manager')

If access is available, then it is TRUE.

0

Ben Bernard

--Ben Bernard--
1083
| 4 3 6
Jakarta, Indonesia
--Ben Bernard--
Ben Bernard
On 12/22/14, 1:35 AM

Openerp has a build in mechanism to restrict access per model / record:

  • Access Control List
  • Record Rule

Generally you can configure access control per model (ex. write access for certain group), openerp will do the checking for you.

The other is condition in workflow transition: you can set group in workflow transition, so that it can be triggered only by that group.

So in many cases you don't have to write some code to check user's group.

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

1 follower(s)

Stats

Asked: 12/20/14, 4:47 AM
Seen: 765 times
Last updated: 3/16/15, 8:10 AM