Odoo Help

1

1
19 Answers
3
Avatar

Atchuthan - Technical Consultant, Sodexis Inc

--Atchuthan - Technical Consultant, Sodexis Inc--
4327
| 6 6 10
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
7/28/15, 5:44 AM

You could try to get your desired output by making few changes in fields_view_get().  (It is similar to a hack) 

 from lxml import etree
 from openerp.osv.orm import setup_modifiers
 class product_template(orm.Model):
    _inherit = "product.template"
    def fields_view_get(self, cr, uid, view_id=None, view_type=False, context=None, toolbar=False, submenu=False):
           if context is None:
               context = {}
           res = super(product_template, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu)
           if view_type == 'form' and self.pool.get('res.users').has_group(cr, uid, 'YOUR_GROUP_ID'):
               doc = etree.XML(res['arch'])
               method_nodes = doc.xpath("//field")
               for node in method_nodes:
                   node.set('readonly', "1")
                   if node.get('name', False) and node.get('name', False) not in ['name','image_medium']:  #Add fields to skip readonly
                       setup_modifiers(node, res['fields'][node.get('name', False)])
               res['arch'] = etree.tostring(doc)
           return res

CREATE 3 groups YOUR_GROUP_ID YOUR_GROUP_CHILD1_ID --> inherits YOUR_GROUP_ID group YOUR_GROUP_CHILD2_ID --> inherits YOUR_GROUP_ID group
You can check whether the user has access for a particular group by doing this self.pool.get('res.users').has_group(cr, uid, 'YOUR_GROUP_CHILD1_ID')
10 Comments
Atchuthan - Technical Consultant, Sodexis Inc
7/28/15, 5:48 AM

I have edited my code to help you in case of having different groups with different field edit access

Sankar
7/28/15, 5:53 AM

Nice idea. .And By using this function is it possible to control one2many or many2many fields too ?

Atchuthan - Technical Consultant, Sodexis Inc
7/28/15, 5:55 AM

I didn't have an opportunity to check whether this works for one2many or many2many. I'll let you know if it works for these 2 fields.

Sankar
7/28/15, 7:11 AM

getting KeyError: 'product.product'

Atchuthan - Technical Consultant, Sodexis Inc
7/28/15, 7:38 AM

then add product module as a dependent module in your __openerp__.py file

Sankar
7/28/15, 7:50 AM

Thanks it works and it throws NameError: global name 'etree' is not defined error

Atchuthan - Technical Consultant, Sodexis Inc
7/28/15, 8:00 AM

add this import statement: from lxml import etree

Sankar
7/28/15, 8:15 AM

You rocks it works. . product.product did not worked for me. so i used product.template. What about security ? is it a just view modification ?

Atchuthan - Technical Consultant, Sodexis Inc
7/28/15, 8:23 AM

Yes, you need to use product.template for v8 and you need to create security.xml file with security records in it and add it to __openerp__.py

Sankar
7/29/15, 5:09 AM

It it possible to make UI for this instead hard coding groups and field name. ?

1
Avatar

Ivan Elizaryev

--Ivan Elizaryev--
805
| 4 3 9
Ufa, Russian Federation
--Ivan Elizaryev--

I tried odoo at the end of 2013. I fell in love in it and have been working with odoo as a freelancer for almost two years. In September 2015 I began operate as a Company and have 5 developers for now.

Ivan, March 2016.

Ivan Elizaryev
7/30/15, 12:27 AM

You can make whole model readonly and add a button "Edit FIELD", which would launch wizard to modify field you need to be writable. That wizard will update a record as SUPERUSER_ID 

1 Comment
Sankar
7/30/15, 1:05 AM

Thanks Ivan, I want to make multiple groups. each groups has write access to specific fields only and other fields should be readonly. Thats why i asked how to make write access to specific fields only and other fields readonly. is it possible make a fine access control like ACL or Record Rules. so it can be applied to any model.

1
Avatar

Rihene

--Rihene--

1273
| 5 2 9
Tunis, France
--Rihene--


Rihene
7/25/15, 4:22 AM

As far as i m concerned, either in front of every field you make readonly=True for those you need to make readonly and those you need them writable, dont put anything or you can make a function that transform your fields either readonly or writable.

Regards!!

1 Comment
Sankar
7/27/15, 1:15 AM

HI , Can you tell how to make a function that transform fields either readonly or writable.

0
Avatar
--Qutechs, Ahmed M.Elmubarak--


Qutechs, Ahmed M.Elmubarak
7/26/15, 3:31 AM

Hello,

If you'd like to add a readonly attribute to specific group you can inherit that view, 
kindly check this , also you can give a group a read access right . BTW the question is not clear also the title is ambiguous.

Regards .... 

3 Comments
Sankar
7/27/15, 1:06 AM

Since the question not clear for you . let me explain. lets take products. i want to make a group that is allowed only edit the title of the product. other than title all fields should be read only. hope you can help me.

Qutechs, Qutechs, Ahmed M.Elmubarak
7/27/15, 3:15 AM

So I think the first link is helpful, You'll need to inherit the product's view then specify the groups_id the change the attribute of the field that you want to change ...

Sankar
7/27/15, 5:52 AM

Sorry i cant get you. . how it will make only one field writable. because . odoo applies Access rights for all fields (whole model ). if you can please explain me.

0
Sankar
7/25/15, 5:09 AM

Thanks for your tip. @ Dress Far. readonly makes a field read  only to all groups. i need it for specific group only.


can you give example to make a function that transform fields either readonly or writable.

Ask a Question
Writer
Keep Informed
2 follower(s)
About This Community

This platform 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.

Register
Odoo Training Center

Access to our eLearning platform and experience all Odoo Apps through learning videos, use cases and quizzes.

Test it now