Unit 3
Unit 3
SEMESTER: 4
PREPARED BY: Ms. Kiran Rajput
Introduction to ORM in Odoo
•What is Odoo?
• An open-source ERP Enterprise Resource Planning)
software
• Modular architecture with a wide range of business
applications
•Key Features:
• Customizable and scalable
• User-friendly interface
2
History of Odoo
•Timeline:
• Founded in 2005 as TinyERP
• Renamed to OpenERP in 2010
• Rebranded to Odoo in 2014
•Evolution:
• Growth from a single application to a full suite of business
applications
• Community-driven development
3
Add-on Module Structure
•Module Structure:
•Directory structure: __init__.py, __manifest__.py, models, views, etc.
{
'name': 'My Module',
'version': '1.0',
'depends': ['base'],
'data': ['views/my_view.xml'],
} 4
Writing Your First Module
5
Relation Fields with Fields
•Example:
class MyModel(models.Model):
_name = 'my.model'
partner_id = fields.Many2one('res.partner', string='Partner')
6
Views, Functions, and Menus
•Defining Views:
•XML files to define how data is presented
•Creating Menus:
•Example of a menu item in XML
•Functions:
• Define business logic in Python methods
7
Widgets and Controls in UI
•Common Widgets:
•Many2one, One2many, Datepicker, etc.
•Example:
8
Domain - Dynamic UI Visions
•What is a Domain?
•Filters applied to fields to limit data displayed
9
Views and View Attributes
•Types of Views:
•Form View, Tree View, Kanban View, Calendar View
•View Attributes:
•create, edit, delete, search, etc.
•Diagram View:
•Visual representation of data relationships
•Graph View:
•Used for displaying data in a graphical format
•Example:
<graph>
<field name="date"/>
<field name="amount"/>
</graph>
11
Calendar View
•Example:
12
Model and Class Level Attributes
Model Attributes:
class MyModel(models.Model):
_name = 'my.model'
_description = 'My Model Description'
13
Creating a Base Module
•Steps to Create:
• Define core models and views
• Ensure proper dependencies in the
manifest file
14
Field Parameters
•Example:
15
Complex Fields
•Examples:
•Computed fields, related fields, and function fields
total_amount = fields.Float(compute='_compute_total_amount')
@api.depends('line_ids.price_total')
def _compute_total_amount(self):
for record in self:
record.total_amount = sum(line.price_total for line in record.line_ids) 16
Designing Kanban Views
<kanban>
<field name="name"/>
<field name="state"/>
</kanban>
17
Introduction to Constraints
•Types of Constraints:
•SQL constraints, Python constraints
_sql_constraints = [
('unique_name', 'UNIQUE(name)', 'Name must be unique!')
]
18
Automatic Reserve Fields
•Examples:
•create_uid, write_uid, create_date, write_date
•Usage:
•Useful for tracking record creation and modification
history
19