Odoo 18 Form View attributes are used to control overall Form behavior. It allows users to interact with individual records of a model. Here are four types of attributes we are going to discuss in this blog.
Create Attribute
It controls whether users can create new records in a form view. In the case of set to false, the ‘Create’ button will be hidden, preventing users from adding new records through that specific form view.
It is simply useful when you want to allow users to edit or delete records but restrict their ability to create new ones.
Use Cases
Suppose you want users to only manage existing records but not create new entries or records. Here records should only be created through automated processes or via other views, not manually through the form.
Example:
Odoo 18 XML form view customization
<form create="false">
<field name="name"/>
<field name="description"/>
</form>
In the above example, users can directly see and edit the name and description fields, but they are not allowed to create a new record in this form.
Edit Attribute
The edit attribute shows whether users can change current records in a Custom form view Odoo. When you set it to false, the form becomes read-only for existing records, preventing any changes to the fields. It’s useful when the records should not be editable once they have been created or imported from another platform.
Use Cases
If you are searching for records after they’ve reached a certain stage (e.g., finalized invoices or completed orders). Then only specific users should be allowed to edit records, but all users can view them.
Example
xml
<form edit="false">
<field name="name"/>
<field name="state"/>
</form>
In the above example, users can view the form and see the name and state fields, but they will not be able to edit or change the values of any fields in this form.
Delete Attribute
The delete attribute controls whether users can delete records through the form view. If set to false, here the ‘Delete’ button is hidden, and users are not allowed to remove the records using that form.
This attribute is useful when data should be kept intact for audit reasons or when deletion is not allowed through the user interface.
Use Cases
Limiting the deletion of important records such as invoices, sales orders, or any entity that needs to be archived rather than deleted.
Example
xml
<form delete="false">
<field name="name"/>
<field name="description"/>
</form>
In the above example, users can view and possibly edit the name and description fields, but they cannot delete the record from this form.
Groups Attribute
The groups attribute is used to restrict access to the form (or specific fields in Odoo form view) to users who belong to specified user groups.
Generally, it is used to control who can view, edit, or manage data based on roles within the businesses. Only users who are members of the specified groups will be able to see or interact with the form or field.
- groups on Form Level: Limit access to the complete from view.
- groups on Field Level: Limit access to a specific Field attributes Odoo 18 in the form.
Use Cases
Limiting access to sensitive data, such as financial information, to people with certain responsibilities, such as managers or accountants. Only specified users, such as management or HR officials, can modify or view certain forms for employee records.
Example 1: Restricting Form Visibility
xml
<form groups="base.group_user">
<field name="name"/>
<field name="email"/>
</form>
In this example, only users in the group base.group_user (which is the internal group for regular users) will be able to access this form. Other users who are not in the group won’t see this form at all.
Example 2: Restricting Field Visibility
xml
<form>
<field name="name"/>
<field name="salary" groups="hr.group_hr_manager"/>
</form>
In the above example, all users can see the name field, but only users in the hr.group_hr_manager (HR managers) group can see or edit the salary field. For other users, the salary field will be hidden.
Conclusion:
These attributes provide a high level of control over how users interact with records in Odoo, allowing for customized workflows, improved data integrity, and secure access control.