OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How can I correctly set the work_email field to be read-only only for the Sales Executive group?

  • Thread starter Thread starter Bharathikannan
  • Start date Start date
B

Bharathikannan

Guest
I have a custom new module in odoo 17 , I want to set 'work_email' field set as read only for employees, the work_email field is already have in hr module (res_users.py) and it the employee user profile it have a many field so i want to customize

so i tried create a new group in sales employee category the name is sales executive .

in hr group it alreadery have two groups are admin and officer. these are have full access in the profile . if the normal employees go to the profile , they are only have read mode option if they are not have any group selected in the hr category.

so i want to try set full access by using officer group from hr and i add additionally sales executive group in the employee users , and i now i want to declare if the user has sales executive group , the work email only want to go read only so How to achieve this task?

Profile page

group in groups page

my codes:

module : custom_sales_module

models:custom_res_users.py:

[```class CustomUserProfile(models.Model): _inherit = 'res.users'

Code:
security/ir_model_group :


[```<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data>
        <record model="ir.module.category" id="module_category_custom_sales">
            <field name="name">Sales Role</field>
            <field name="sequence">10</field>
        </record>
        <record id="custom_sales_security_executive_group" model="res.groups">
            <field name="name">Sales Executive</field>          
            <field name="category_id" ref="custom_sales_group.module_category_custom_sales" />
        </record>
    </data>
</odoo>```]

views:
custom_res_users_views:

[```
<odoo>
    <data>
        <record id="custom_user_profile_security_view" model="ir.ui.view">
            <field name="name">custom.user.profile.security.view</field>
            <field name="model">res.users</field>
            <field name="inherit_id" ref="hr.res_users_view_form_profile" />
            <field name="arch" type="xml">
                 <!-- <page name="personal_information" position="attributes">
                    <attribute name="invisible">1</attribute>
                </page> -->
                <xpath expr="//field[@name='work_email']" position="attributes">
                    <t groups="custom_sales_group.custom_sales_security_executive_group">
                        <attribute name="readonly">1</attribute>
                    </t>
                </xpath>
          </field>
        </record>
    </data>
</odoo>
```]




but by this code ,this field not set readonly for sales executive group it set globally.


so check my code and give correct code:
<p>I have a custom new module in odoo 17 , I want to set 'work_email' field set as read only for employees, the work_email field is already have in hr module (res_users.py) and it the employee user profile it have a many field so i want to customize</p>
<p>so i tried create a new group in sales employee category the name is sales executive .</p>
<p>in hr group it alreadery have two groups are admin and officer. these are have full access in the profile . if the normal employees go to the profile , they are only have read mode option if they are not have any group selected in the hr category.</p>
<p>so i want to try set full access by using officer group from hr and i add additionally sales executive group in the employee users , and i now i want to declare if the user has sales executive group , the work email only want to go read only so How to achieve this task?</p>
<p><a href="https://i.sstatic.net/v8GBUE1o.png" rel="nofollow noreferrer">Profile page</a></p>
<p><a href="https://i.sstatic.net/oJTMrwGA.png" rel="nofollow noreferrer">group in groups page</a></p>
<p>my codes:</p>
<p>module : custom_sales_module</p>
<p>models:custom_res_users.py:</p>
<p>[```class CustomUserProfile(models.Model):
_inherit = 'res.users'</p>
<pre><code>

security/ir_model_group :


[```<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record model="ir.module.category" id="module_category_custom_sales">
<field name="name">Sales Role</field>
<field name="sequence">10</field>
</record>
<record id="custom_sales_security_executive_group" model="res.groups">
<field name="name">Sales Executive</field>
<field name="category_id" ref="custom_sales_group.module_category_custom_sales" />
</record>
</data>
</odoo>```]

views:
custom_res_users_views:

[```
<odoo>
<data>
<record id="custom_user_profile_security_view" model="ir.ui.view">
<field name="name">custom.user.profile.security.view</field>
<field name="model">res.users</field>
<field name="inherit_id" ref="hr.res_users_view_form_profile" />
<field name="arch" type="xml">
<!-- <page name="personal_information" position="attributes">
<attribute name="invisible">1</attribute>
</page> -->
<xpath expr="//field[@name='work_email']" position="attributes">
<t groups="custom_sales_group.custom_sales_security_executive_group">
<attribute name="readonly">1</attribute>
</t>
</xpath>
</field>
</record>
</data>
</odoo>
```]




but by this code ,this field not set readonly for sales executive group it set globally.


so check my code and give correct code:


</code></pre>
 

Latest posts

Top