Odoo Technical Interview Questions and Answers
Odoo Interview Questions
Odoo has two main editions:
- Odoo Community Edition (CE): Open-source and free.
- Odoo Enterprise Edition (EE): Paid, with additional features like Studio, multi-company features, and more advanced financial tools.
Models in Odoo are used to represent the database tables. Each model corresponds to a table, and fields in the model represent the columns in that table. Models are typically defined in Python and are used to perform various operations such as create, read, update, and delete (CRUD).
The Odoo ORM allows developers to interact with the database using Python objects rather than SQL queries. This abstraction simplifies database manipulation. Odoo’s ORM manages all the necessary SQL queries, data fetching, and relationship handling.
To create a custom module:
- Define a new directory under the
addons
folder. - Add
__init__.py
and__manifest__.py
files. - Define models and views within this directory.
- Import the module through the Odoo interface and install it.
__manifest__.py
file.The __manifest__.py
file is a dictionary that contains metadata about the module. It typically includes fields like:
name
: The module name.version
: The version number of the module.author
: The author of the module.depends
: List of modules that this module depends on.data
: List of XML files like views and security rules.installable
: Whether the module can be installed.
Some commonly used field types are:
Char
: Used for string fields.Integer
: Stores integer values.Boolean
: Stores True/False values.Date
: Stores date values.Many2one
: Creates a relationship to another model (foreign key).One2many
: Creates a one-to-many relationship with another model.
@api.model
, @api.multi
, and @api.depends
.@api.model
: Used to define methods that work on a model level (i.e., methods that don’t rely on record sets).@api.multi
: It was used in older versions of Odoo to define methods that operate on multiple records, but it’s deprecated now in newer versions.
@api.multi
was used in older versions (before Odoo 13) to handle methods that work on recordsets. However, @api.multi
has been removed in Odoo 13 and later. Now, Odoo automatically iterates over records in methods, so @api.multi
is no longer necessary.
@api.depends
: Used to specify that a computed field depends on other fields. This ensures that the field is recalculated when the dependent fields are changed.
Security and access rights in Odoo are managed through security groups and rules. You can define access rights for models in the security/ir.model.access.csv
file and record rules to manage record-level access.
Access control and security rules in Odoo control who can read, write, create, or delete records. They ensure that users have the appropriate permissions based on their role or group.
A view in Odoo is how the user sees and interacts with the data. Common view types in Odoo include:
- Form views: For displaying individual records.
- Tree views: For listing multiple records.
- Kanban views: For a card-based layout.
- Calendar views: For scheduling and tracking tasks.
- Regular models: Store persistent data in the database.
- Transient models: Store temporary data that is not meant to be persisted across sessions. These are used for wizards or temporary operations. They are automatically deleted after a set period.
Odoo Scheduler automates recurring tasks like sending reminders, generating reports, and processing orders. You can create scheduled actions (cron jobs) to run Python methods at specific intervals.
Performance optimization can involve:
- Optimizing database queries by reducing the number of queries or using the right indices.
- Caching data where appropriate.
- Running background tasks asynchronously.
- Reducing view rendering time by optimizing the front-end code.
Debugging in Odoo can be done by:
- Using
print()
statements to track variables. - Enabling the Odoo debug mode via the interface by adding
?debug
to the URL. - Using Python debuggers like
pdb
. - Using tools like PyCharm’s remote debugger to step through the code.
Server actions allow users to execute specific Python code or pre-configured actions (e.g., sending emails, creating records) in response to certain triggers like button clicks or scheduled intervals.
Workflow systems in older versions of Odoo managed business processes (e.g., invoice validation). However, newer Odoo versions replaced workflows with automation through business logic using server actions and automated activities.
Super
in Odoo? How is it used?Super()
in Odoo is used to call the parent class’s method when a method is overridden. It ensures that the original functionality is not lost while extending it.
Example:
def create(self, vals):
record = super(MyModel, self).create(vals)
# Custom logic after calling parent method
return record
compute
parameter in the field definition and defining a compute method.@api.depends('quantity', 'price')
def _compute_total(self):
for record in self:
record.total_price = record.quantity * record.price
Dependencies are managed using the depends
field in the __manifest__.py
file. These ensure that required modules are installed before the custom module.
Some common pitfalls include:
Not considering record rules and access control, leading to security vulnerabilities.
Not handling concurrency issues in multi-user environments.
Many2one
field is a relational field in Odoo that creates a many-to-one relationship between two models. For example, a product may belong to a specific category22. How can you add a custom button to a form view in Odoo?
You can add a custom button in the form view using XML, and you can define its functionality in Python by creating a method and linking it to the button.
XML:
<button name="action_custom" string="Custom Action" type="object"/>
Python:
def action_custom(self):
# Custom button action
return
write()
and create()
methods in Odoocreate()
: Used to insert new records into the database.write()
: Used to update existing records.
_inherit = 'product.model'
new_field = fields.Char('New Field')
self.env
in Odoo?self.env
in Odoo provides access to the environment in which a method is running. It includes useful attributes like self.env['model_name']
to access other models, self.env.context
to access the context, and self.env.uid
to get the current user ID.<field name="model">my.model</field>
<field name="arch" type="xml">
<form>
<sheet>
<group>
<field name="name"/>
<field name="age"/>
</group>
</sheet>
</form>
</field>
</record>
fields.One2many()
field in the model. You can create a many-to-one relationship using the fields.Many2one()
field.
parent_id = fields.Many2one('parent.model', string="Parent Record")
30. How do you define a form view in Odoo?
<record id="view_form_example" model="ir.ui.view">
<field name="name">example.form</field>
<field name="model">example.model</field>
<field name="arch" type="xml">
<form string="Example">
<group>
<field name="name"/>
<field name="description"/>
</group>
</form>
</field>
</record>
31. What is the purpose of the @api.depends()
decorator?
The @api.depends()
decorator is used to specify dependencies for computed fields. It helps Odoo automatically recalculate the field when any of the dependencies change.
32 . What is a domain in Odoo?
A domain is a condition used to filter records. It is a list of tuples in the format ('field_name', 'operator', 'value')
.
domain = [('state', '=', 'draft')]
33.What is the purpose of the @api.onchange
decorator?
The @api.onchange
decorator is used to trigger an action when the value of a field changes.
@api.onchange('partner_id')
def _onchange_partner(self):
self.address = self.partner_id.address
34.How do you override the create method in Odoo?
You can override the create()
method to customize the record creation process.
@api.model
def create(self, vals):
# Custom logic here
return super(MyModel, self).create(vals)
35.How do you add a record rule in Odoo?
Record rules are defined in XML and are used to control access to specific records.
<record id="rule_example" model="ir.rule">
<record id="rule_example" model="ir.rule">
<field name="name">Example Rule</field>
<field name="model_id" ref="model_example"/>
<field name="domain_force">[('user_id', '=', user.id)]</field>
</record>
36. What is the purpose of the @api.constrains
decorator?
The @api.constrains
decorator is used to add validation logic on fields when records are created or updated.
@api.constrains('field1', 'field2')
def _check_field(self):
if self.field1 < 0:
raise ValidationError("Field1 cannot be negative")
37.What is a wizard in Odoo?
A wizard in Odoo is a transient model used for user interaction, such as dialog boxes. They are not stored permanently in the database.
38. How do you debug in Odoo?
You can debug by using PyCharm with breakpoints, enabling developer mode in Odoo, or using logging.
39. How do you add a custom module to Odoo?
A custom module is added by placing it in the Odoo addons folder and installing it through the Odoo interface.
40. What is the purpose of super()
in Odoo?
super()
is used to call the parent method in case you are overriding a method but still want to preserve the original functionality.
41. What are server actions in Odoo?
Server actions allow you to perform automated tasks like sending emails or updating records.
42.What is a scheduled action?
A scheduled action is an automated job that runs periodically, defined in the Technical settings.
43.How do you install a new module in Odoo?
You can install a new module by navigating to the Apps menu, searching for the module, and clicking the install button.
44. How do you manage database operations in Odoo?
Database operations in Odoo are managed through PostgreSQL, and you can handle them using the psql
command-line tool.
45. What are the key differences between Odoo Community and Enterprise editions?
Odoo Community is free and open-source, while Odoo Enterprise offers additional features like advanced reporting, dashboards, and faster support.
46. What is Odoo SH?
Odoo SH is Odoo’s cloud platform for hosting, maintaining, and deploying Odoo instances with a focus on scalability.
47.How do you create a Many2many relationship in Odoo?
In Odoo, a Many2many
relationship allows for a many-to-many relationship between two models. This means that each record in the first model can be linked to multiple records in the second model, and vice versa.
Key Components:
comodel_name
: This defines the model that is being related to.relation
: The name of the table that stores the relationship between the two models. If not provided, Odoo will automatically generate a table name.column1
andcolumn2
: These define the columns in the relation table that store the IDs from each model. Odoo will auto-generate these if not provided.
- Courses: A course can have many students.
- Students: A student can attend many courses.
_name = 'academy.student'
_description = 'Student'
course_ids = fields.Many2many('academy.course', 'student_course_rel', 'student_id', 'course_id', string='Courses')
class Course(models.Model):
_description = 'Course'
name = fields.Char(string='Course Name')
student_ids = fields.Many2many('academy.student', 'student_course_rel', 'course_id', 'student_id', string='Students')
academy.student
: Model for students.academy.course
: Model for courses.student_course_rel
: The name of the relation table (many-to-many bridge table).student_id
: Field representing the student ID in the relation table.course_id
: Field representing the course ID in the relation table. In the above example, a third table student_course_rel
is automatically created in the database, which contains two columns:
student_id
: Links to theacademy.student
model.course_id
: Links to theacademy.course
model.
The Many2many
fields course_ids
in the academy.student
model and student_ids
in the academy.course
model manage this relationship.
_name = 'academy.student'
name = fields.Char(string='Student Name')
course_ids = fields.Many2many('academy.course', string='Courses')
class Course(models.Model):
_name = 'academy.course'
name = fields.Char(string='Course Name')
student_ids = fields.Many2many('academy.student', string='Students')
In this case, Odoo will automatically create a table with a name like academy_student_academy_course_rel
.
SQL Representation of the Many2many Table
CREATE TABLE student_course_rel (
student_id INT NOT NULL,
course_id INT NOT NULL,
PRIMARY KEY(student_id, course_id),
FOREIGN KEY (student_id) REFERENCES academy_student(id),
FOREIGN KEY (course_id) REFERENCES academy_course(id)
);
This is how Odoo manages the Many2many relationship internally by maintaining a relational table.
Comments