Hi all,
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?
my codes:
module : custom_sales_module
models:custom_res_users.py:
```class CustomUserProfile(models.Model):
_inherit = 'res.users'
```
security/ir_model_group :
```
Sales Role
10
Sales Executive
```
views:
custom_res_users_views:
```
custom.user.profile.security.view
res.users
1
```
but by this code ,this field not set readonly for sales executive group it set globally.
so check my code and give correct code:
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Kế toán
- Tồn kho
- PoS
- Project
- MRP
Câu hỏi này đã bị gắn cờ
1
Trả lời
1273
Lượt xem
Hi,
Please check the code below:
Group for sale executive:
<record id="sales_executive_group" model="res.groups">
<field name="name">Sales Executive</field>
</record>
Python:
from odoo import fields, models
class HrEmployee(models.Model):
_inherit = 'hr.employee'
is_sales_executive = fields.Boolean(string="Is Sale Executive",
compute="_compute_is_sales_executive")
def is_sale_executive(self):
"""
Compute method to determine whether the current user belongs
to the 'sales_executive_group'. Sets 'is_sales_executive' to True
if the user has the group, otherwise False."""
for rec in self:
if self.env.user.has_group('Module_Name.sales_executive_group'):
rec.is_sale_executive = True
else:
rec.is_sale_executive = False
XML
<record id="view_employee_form" model="ir.ui.view">
<field name="name">hr.employee.view.form</field>
<field name="model">hr.employee</field>
<field name="inherit_id" ref="hr.view_employee_form"/>
<field name="arch" type="xml">
<field name="work_phone" position="after">
<field name="is_sales_executive" invisible="1"/>
</field>
<field name="work_email" position='attributes'>
<attribute name="readonly">is_sales_executive</attribute>
</field>
</field>
</record>
Hope it helps.
Bạn có hứng thú với cuộc thảo luận không? Đừng chỉ đọc, hãy tham gia nhé!
Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!
Đăng kýBài viết liên quan | Trả lời | Lượt xem | Hoạt động | |
---|---|---|---|---|
|
0
thg 6 24
|
861 | ||
|
1
thg 6 23
|
3101 | ||
|
2
thg 6 25
|
1733 | ||
|
0
thg 8 24
|
1778 | ||
|
2
thg 7 24
|
1703 |