0% found this document useful (0 votes)
40 views5 pages

Odoo Excercise

Uploaded by

areebanaeem044
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views5 pages

Odoo Excercise

Uploaded by

areebanaeem044
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Here are some practical exercises focused on form development in Odoo

ERP module development. These exercises will help you understand how to
create, customize, and extend forms in Odoo.

Exercise 1: Basic Form View

1. Objective: Create a custom form view for a new model.

2. Steps:

o Create a custom module named library_management.

o Define a new model, e.g., library.book, with fields like name,


author, genre, and publication_date.

o Create a form view for this model.

o Add the form view to a menu under a new application.

Exercise 2: Add Fields to Existing Forms

1. Objective: Add custom fields to the existing Partner form


(res.partner).

2. Steps:

o Extend the res.partner model to include new fields, such as


membership_id and membership_expiry_date.

o Modify the existing Partner form view using XML inheritance to


display these fields in a new tab or group.

o Test the form to ensure the fields are saved correctly.

Exercise 3: Conditional Field Visibility

1. Objective: Make a field visible based on the value of another field.

2. Steps:

o Add a new field is_premium_member (boolean) to the res.partner


model.
o Add a dependent field, such as premium_benefits, which should
only be visible when is_premium_member is checked.

o Use the attrs attribute in the form view to control visibility


dynamically.

Exercise 4: Computed Fields in Forms

1. Objective: Create a computed field and display it on a form.

2. Steps:

o Add a computed field age to the library.book model, which


calculates the book's age based on its publication_date.

o Define the compute method for the field in Python.

o Display the age field on the form view as a readonly field.

Exercise 5: Form with Related Fields

1. Objective: Show related fields on a form view.

2. Steps:

o Add a Many2one field publisher_id to the library.book model,


linking to a new model library.publisher.

o Add related fields like publisher_address and publisher_phone to


the library.book model.

o Display these related fields on the book form view.

Exercise 6: Add Buttons with Server Actions

1. Objective: Add a custom button to perform a server-side action.

2. Steps:

o Add a button Mark as Bestseller to the library.book form view.

o Write a method in the model to update a field is_bestseller when


the button is clicked.
o Use the type="object" attribute in the button to trigger the
server-side action.

Exercise 7: Form with Inline Tree Views

1. Objective: Add an inline tree view to a form for a One2many


relationship.

2. Steps:

o Add a One2many field chapter_ids to the library.book model,


linking to a new model library.chapter.

o Define a tree view for library.chapter.

o Embed the tree view in the library.book form view.

Exercise 8: Form Validation

1. Objective: Add custom validation logic to a form.

2. Steps:

o Add a stock_quantity field to the library.book model.

o Add a price field and ensure that it is greater than 0 using


constraints or the @api.constrains decorator.

o Raise a validation error if stock_quantity is less than 0.

Exercise 9: Wizard with Form View

1. Objective: Create a wizard form to perform batch operations.

2. Steps:

o Create a wizard model library.batch_update.

o Add fields like genre and author to the wizard.

o Add a button that applies the values entered in the wizard to all
selected books.

o Test the wizard by linking it to an action in the book list view.


Exercise 10: Form Styling and Action Icons

1. Objective: Customize the appearance of a form view.

2. Steps:

o Add colored status indicators to a state field using widgets like


statusbar.

o Add icons to action buttons.

o Use decoration- attributes to highlight records based on


conditions (e.g., highlight overdue books).

Exercise 11: Dynamic Domain in Forms

1. Objective: Apply a dynamic domain to a Many2one field.

2. Steps:

o Add a Many2one field category_id to the library.book model.

o Add a Many2one field subcategory_id and filter the available


subcategories based on the selected category.

o Use the domain attribute to apply this dynamic filtering.

Exercise 12: Tabs in Forms

1. Objective: Organize fields in a form using tabs.

2. Steps:

o Create tabs for General Information, Chapters, and Additional


Details in the library.book form view.

o Move fields into the respective tabs.

o Test the form to ensure usability.

Exercise 13: Action Buttons to Trigger Reports

1. Objective: Add a button to generate a report from a form view.


2. Steps:

o Add a button Print Details to the library.book form.

o Create a report template to display the book's details.

o Link the button to the report action.

Exercise 14: Security and Access Controls

1. Objective: Ensure form security based on user roles.

2. Steps:

o Define access control rules for the library.book model.

o Restrict certain fields in the form to specific user groups using


the groups attribute.

o Test the form with users in different roles.

Exercise 15: Multi-language Support in Forms

1. Objective: Add multi-language support for field labels and help texts.

2. Steps:

o Add translatable string and help attributes for fields in the XML
view.

o Update translations using the Odoo translation interface.

o Test the form in different languages.

These exercises provide a comprehensive way to master form development


in Odoo. Let me know if you'd like more details or examples for any specific
exercise!

You might also like