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

How to set a field readonly for a employee group ?

By
Odoo
on 5/15/15, 12:48 AM 1,713 views

Hi all,

I have a custom module in hr , I want to set  'remarks' field set as read only for employees, and  I want to set read and write operation access  for manager user .How to achieve this task?


This is my code---------


lass hr_general(osv.osv):

_name = 'hr.general'

_columns = {

'name':fields.many2one('hr.employee','Name',required=True),

'state': fields.selection([('draft', 'To Submit'), ('reject', 'Rejected'), ('validate_hr', 'HR Approved'),('validate_mgr','Manager Approved')],'State'),

'description':fields.char('Subject',required=True),

'date_issue':fields.date('Date'),

'details':fields.text('Details',required=True),

'remarks':fields.text('Remarks')

}

_defaults={

'state':lambda *a: 'draft',

'date_issue': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),

'name': lambda s, cr, uid, c: uid,

}





xml ---------------------


<record model="ir.ui.view" id="hrgeneral_form_view">

<field name="name">hr.general.form</field>

<field name="model">hr.general</field>

<field name="type">form</field>

<field name="arch" type="xml">

<form string="Genaral" version="7.0">

<header>

<button name="action_button_manager" class="oe_highlight" states="draft" string="Manager Approval" type="object" groups="base.group_hr_user"/>

<button name="action_button_reject" string="Reject" type="object" groups="base.group_hr_user"/>

<button name="action_button_validate" states="validate_mgr" class="oe_highlight" string="HR Approval" type="object" groups="base.group_hr_user"/>

<button name="action_button_draft" string="Reset to Draft" type="object" groups="base.group_hr_user"/>

<field name="state" widget="statusbar" statusbar_visible="draft,reject,validate_hr,validate_mgr" statusbar_colors='{"draft":"blue","reject":"blue","validate_hr":"blue","validate_mgr":"blue"}'/>

</header>

<sheet>

<group>

<field name="name"/>

<field name="description"/>

<field name="date_issue"/>

<field name="details"/>

<field name="remarks"/></group>

</sheet>

</form>

</field>

</record>




=======================

 These are the existing groups ,so how to apply this groups to  my code  groups="base.group_hr_manager,base.group_hr_user,base.group_user"

 

Hello deep, hr.general.form hr.general form

hr.general.form hr.general <xpath expr="//field[@name='remarks']" position="attributes"> 0 when user have access rights for groups "group_hr_manager" after the fields "remarks" is editable othewize it's not editable

Jaydeep Barot (jar)
on 5/15/15, 2:55 AM
1

Atchuthan - Technical Consultant, Sodexis Inc

--Atchuthan - Technical Consultant, Sodexis Inc--
3883
| 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 5/15/15, 1:21 AM

Sample code with similar scenario available here

First, set remarks as READONLY in XML and add this view in your XML file


 <record model="ir.ui.view" id="hr_manager_form_view">
	<field name="name">hr.general.form</field>
	<field name="model">hr.general</field>
	<field name="inherit_id" ref="hrgeneral_form_view" />
	<field name="groups_id" eval="[(6,0,[ref('base.group_hr_manager')])]" />
	<field name="arch" type="xml">
		<xpath expr="//field[@name='remarks']" position="attributes">
			<attribute name="readonly">0</attribute>
		</xpath>
	</field>
</record>

i have some daught why you are using inherit_id, this is not an independent model not depending any existing model like (hr.employee ..) i just want to add read only for employees and all other permission given to manager.....

Odoo
on 5/15/15, 1:28 AM

This is done to overwrite the field properties/attributes with a new one but with a group linked to it. Thus the changes are only applied if the group is enabled for the user. Normally, if we have to do a change in XML, we normally inherit the view and do so, the same logic applies here.

Atchuthan - Technical Consultant, Sodexis Inc
on 5/15/15, 1:47 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

2 follower(s)

Stats

Asked: 5/15/15, 12:48 AM
Seen: 1713 times
Last updated: 8/30/16, 10:05 AM