SlideShare a Scribd company logo
Backend Modules in V8
Raphael Collet (rco@odoo.com)
Agenda
Architecture of Odoo
Module Open Academy
·
·
Architecture of Odoo
Architecture of Odoo
Three-tier client/server/database
Web client in Javascript
Server and backend modules in Python
MVC framework
·
·
·
·
Module Open Academy
The Module
Manage courses, sessions, and subscriptions
Learn
Structure of a module
Definition of data models
Definition of views and menus
·
·
·
·
·
Structure of a Module
An Odoo module is
a python module (data models), with
a manifest file,
XML and CSV data files (base data, views, menus),
frontend resources (Javascript, CSS).
·
·
·
·
The Open Academy Module
The manifest file __odoo__.py:
{{
'name':: 'Open Academy',,
'version':: '1.0',,
'category':: 'Tools',,
'summary':: 'Courses, Sessions, Subscriptions',,
'description':: "...",,
'depends' :: [['base'],],
'data' :: [['view/menu.xml'],],
'images':: [],[],
'demo':: [],[],
'application':: True,,
}}
The Course Model
A model and its fields are defined in a Python class:
fromfrom odoo importimport Model,, fields
classclass Course((Model):):
_name == 'openacademy.course'
name == fields..Char((string=='Title',, required==True))
description == fields..Text()()
The Menu as XML data
<?xml version="1.0" encoding="UTF-8"?>
<openerp><openerp>
<data><data>
<menuitem<menuitem name="Open Academy" id="menu_root" sequence="110"/>/>
<menuitem<menuitem name="General" id="menu_general" parent="menu_root"/>/>
<record<record model="ir.actions.act_window" id="action_courses">>
<field<field name="name">>Courses</field></field>
<field<field name="res_model">>openacademy.course</field></field>
<field<field name="view_mode">>tree,form</field></field>
</record></record>
<menuitem<menuitem name="Courses" id="menu_courses" parent="menu_general"
sequence="1" action="action_courses"/>/>
</data></data>
</openerp></openerp>
Let's add a Form View
<record<record model="ir.ui.view" id="course_form">>
<field<field name="name">>course form view</field></field>
<field<field name="model">>openacademy.course</field></field>
<field<field name="arch" type="xml">>
<form<form string="Course" version="7.0">>
<sheet><sheet>
<h1><h1>
<field<field name="name" placeholder="Course Title"/>/>
</h1></h1>
<notebook><notebook>
<page<page string="Description">>
<field<field name="description"/>/>
</page></page>
</notebook></notebook>
</sheet></sheet>
</form></form>
</field></field>
</record></record>
The Session Model
classclass Session((Model):):
_name == 'openacademy.session'
name == fields..Char((required==True))
start_date == fields..Date()()
duration == fields..Integer((help=="Duration in days"))
seats == fields..Integer((string=="Number of Seats"))
Relational Fields
Let us link sessions to courses and instructors:
classclass Session((Model):):
_name == 'openacademy.session'
......
course == fields..Many2one(('openacademy.course',, required==True))
instructor == fields..Many2one(('res.partner'))
Relational Fields
Let us back-link courses and sessions:
classclass Course((Model):):
_name == 'openacademy.course'
......
responsible == fields..Many2one(('res.users'))
sessions == fields..One2many(('openacademy.session',, 'course'))
Relational Fields
Let us link sessions to partners for attendee subscription:
classclass Session((Model):):
_name == 'openacademy.session'
......
attendees == fields..Many2many(('res.partner'))
Computed Fields
The value of those fields is computed:
classclass Session((Model):):
_name == 'openacademy.session'
......
taken_seats == fields..Float((compute=='_compute_taken_seats'))
@api.one@api.one
@api.depends@api.depends(('attendees',, 'seats'))
defdef _compute_taken_seats((self):):
ifif self..seats::
self..taken_seats == 100.0100.0 ** len((self..attendees)) // self..seats
elseelse::
self..taken_seats == 0.00.0
About self
Model instances are recordsetsrecordsets.
A recordset is an hybrid concept:
collection of records
record
forfor session inin self::
printprint session..name
printprint session..course..name
assertassert self..name ==== self[[00]]..name
·
·
Feedback with "Onchange"
Methods
Modify form values when some field is filled in:
classclass Session((Model):):
_name == 'openacademy.session'
......
@api.onchange@api.onchange(('course'))
defdef _onchange_course((self):):
ifif notnot self..name::
self..name == self..course..name
Default Values
Specify the initial value to use in a form:
classclass Session((Model):):
_name == 'openacademy.session'
......
active == fields..Boolean((default==True))
start_date == fields..Date((default==fields..Date..today))
......
Model Constraints
Prevent bad data:
fromfrom odoo.exceptions importimport WarningWarning
classclass Session((Model):):
_name == 'openacademy.session'
......
@api.one@api.one
@api.constrains@api.constrains(('instructor',, 'attendees'))
defdef _check_instructor((self):):
ifif self..instructor inin self..attendees::
raiseraise WarningWarning(("Instructor of session '%s' "
"cannot attend its own session" %% self..name))
More Stuff
Extend existing models
Many view types
Workflows
Reports
Security
Translations
·
·
·
·
·
·
Backend Modules in V8
Conclusion
Modules have a simple structure
Model definition intuitive and efficient
uses Python standards (decorators, descriptors)
recordsets provide support for "batch" processing
many model hooks (default values, constraints,
computed fields)
·
·
·
·
·

More Related Content

PPTX
Python Lambda Function
PDF
Odoo - From v7 to v8: the new api
PPTX
Python
PPT
inheritance in python with full detail.ppt
PDF
Cours python avancé
PPTX
Python Functions
PDF
Empower your App by Inheriting from Odoo Mixins
Python Lambda Function
Odoo - From v7 to v8: the new api
Python
inheritance in python with full detail.ppt
Cours python avancé
Python Functions
Empower your App by Inheriting from Odoo Mixins

What's hot (20)

PPT
Regular Expressions
PPTX
Unit Testing with Python
PPTX
Python: Polymorphism
PPT
Object-Oriented Programming Concepts
PDF
Cours python
PDF
Python avancé : Lecture et écriture de fichiers
PPTX
Introduction à l’orienté objet en Python
PPTX
Advanced Python : Static and Class Methods
PDF
Python recursion
DOCX
Python unit 3 and Unit 4
PDF
Python exception handling
PPTX
Chapter 07 inheritance
PPTX
Functions in python
PPSX
Modules and packages in python
PPT
Biconnected components (13024116056)
PDF
Lab report for Prolog program in artificial intelligence.
PPTX
Queue in Data Structure
PPTX
Python programming
PPTX
Looping Statements and Control Statements in Python
Regular Expressions
Unit Testing with Python
Python: Polymorphism
Object-Oriented Programming Concepts
Cours python
Python avancé : Lecture et écriture de fichiers
Introduction à l’orienté objet en Python
Advanced Python : Static and Class Methods
Python recursion
Python unit 3 and Unit 4
Python exception handling
Chapter 07 inheritance
Functions in python
Modules and packages in python
Biconnected components (13024116056)
Lab report for Prolog program in artificial intelligence.
Queue in Data Structure
Python programming
Looping Statements and Control Statements in Python
Ad

Viewers also liked (13)

PDF
Odoo Online platform: architecture and challenges
PDF
Tips on how to improve the performance of your custom modules for high volume...
PDF
Improving the performance of Odoo deployments
PDF
Odoo 2016 - Retrospective
PPTX
Odoo (OpenERP) - Creating a module
PPTX
Odoo Web Services
PPTX
How to configure PyCharm for Odoo development in Windows?
PPTX
Widgets in odoo
PPTX
Timesheet based payroll
PPTX
Xml operations in odoo
PDF
Development Odoo Basic
PDF
User Manual For Crafito Odoo Theme
PDF
Odoo - Create themes for website
Odoo Online platform: architecture and challenges
Tips on how to improve the performance of your custom modules for high volume...
Improving the performance of Odoo deployments
Odoo 2016 - Retrospective
Odoo (OpenERP) - Creating a module
Odoo Web Services
How to configure PyCharm for Odoo development in Windows?
Widgets in odoo
Timesheet based payroll
Xml operations in odoo
Development Odoo Basic
User Manual For Crafito Odoo Theme
Odoo - Create themes for website
Ad

Similar to Odoo - Backend modules in v8 (20)

PPTX
HOW TO CREATE A MODULE IN ODOO
PPTX
Tips On Trick Odoo Add-On.pptx
PPTX
Building a Module in Odoo 16
PDF
Odoo Technical Concepts Summary
PPTX
Running a University with Odoo
PPTX
Tips On Trick Odoo Add-On.pptx
PDF
Odoo Experience 2018 - Odoo Studio: A Functional Approach
PDF
PPT. Introduction & Views - Documentation.pdf
PDF
Odoo from 7.0 to 8.0 API
PPTX
Odoo (Build module, Security, ORM)
PPTX
Django in the Office: Get Your Admin for Nothing and Your SQL for Free
PPTX
Why Browser Debugger is a Developer's Best Friend
PPTX
Object Relation Mapping in Odoo 16
PPTX
odoo 11.0 development (CRUD)
PPTX
Model Attributes in Odoo 18 - Odoo 18 Slides
PDF
OrientDB: Unlock the Value of Document Data Relationships
PPTX
Method and decorator
PPT
Spsl vi unit final
PPT
Spsl v unit - final
HOW TO CREATE A MODULE IN ODOO
Tips On Trick Odoo Add-On.pptx
Building a Module in Odoo 16
Odoo Technical Concepts Summary
Running a University with Odoo
Tips On Trick Odoo Add-On.pptx
Odoo Experience 2018 - Odoo Studio: A Functional Approach
PPT. Introduction & Views - Documentation.pdf
Odoo from 7.0 to 8.0 API
Odoo (Build module, Security, ORM)
Django in the Office: Get Your Admin for Nothing and Your SQL for Free
Why Browser Debugger is a Developer's Best Friend
Object Relation Mapping in Odoo 16
odoo 11.0 development (CRUD)
Model Attributes in Odoo 18 - Odoo 18 Slides
OrientDB: Unlock the Value of Document Data Relationships
Method and decorator
Spsl vi unit final
Spsl v unit - final

More from Odoo (20)

PPTX
Timesheet Workshop: The Timesheet App People Love!
PPTX
Odoo 3D Product View with Google Model-Viewer
PPTX
Keynote - Vision & Strategy
PPTX
Opening Keynote - Unveilling Odoo 14
PDF
Extending Odoo with a Comprehensive Budgeting and Forecasting Capability
PDF
Managing Multi-channel Selling with Odoo
PPTX
Product Configurator: Advanced Use Case
PDF
Accounting Automation: How Much Money We Saved and How?
PPTX
Rock Your Logistics with Advanced Operations
PPTX
Transition from a cost to a flow-centric organization
PDF
Synchronization: The Supply Chain Response to Overcome the Crisis
PPTX
Down Payments on Purchase Orders in Odoo
PPTX
Odoo Implementation in Phases - Success Story of a Retail Chain 3Sach food
PPTX
Migration from Salesforce to Odoo
PPTX
Preventing User Mistakes by Using Machine Learning
PPTX
Becoming an Odoo Expert: How to Prepare for the Certification
PPTX
Instant Printing of any Odoo Report or Shipping Label
PPTX
How Odoo helped an Organization Grow 3 Fold
PPTX
From Shopify to Odoo
PPTX
Digital Transformation at Old MacDonald Farms: A Personal Story
Timesheet Workshop: The Timesheet App People Love!
Odoo 3D Product View with Google Model-Viewer
Keynote - Vision & Strategy
Opening Keynote - Unveilling Odoo 14
Extending Odoo with a Comprehensive Budgeting and Forecasting Capability
Managing Multi-channel Selling with Odoo
Product Configurator: Advanced Use Case
Accounting Automation: How Much Money We Saved and How?
Rock Your Logistics with Advanced Operations
Transition from a cost to a flow-centric organization
Synchronization: The Supply Chain Response to Overcome the Crisis
Down Payments on Purchase Orders in Odoo
Odoo Implementation in Phases - Success Story of a Retail Chain 3Sach food
Migration from Salesforce to Odoo
Preventing User Mistakes by Using Machine Learning
Becoming an Odoo Expert: How to Prepare for the Certification
Instant Printing of any Odoo Report or Shipping Label
How Odoo helped an Organization Grow 3 Fold
From Shopify to Odoo
Digital Transformation at Old MacDonald Farms: A Personal Story

Recently uploaded (20)

PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Machine learning based COVID-19 study performance prediction
PDF
KodekX | Application Modernization Development
PPTX
Cloud computing and distributed systems.
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
sap open course for s4hana steps from ECC to s4
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPT
Teaching material agriculture food technology
PDF
Encapsulation theory and applications.pdf
Encapsulation_ Review paper, used for researhc scholars
Machine learning based COVID-19 study performance prediction
KodekX | Application Modernization Development
Cloud computing and distributed systems.
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
MYSQL Presentation for SQL database connectivity
20250228 LYD VKU AI Blended-Learning.pptx
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Reach Out and Touch Someone: Haptics and Empathic Computing
sap open course for s4hana steps from ECC to s4
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Review of recent advances in non-invasive hemoglobin estimation
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Agricultural_Statistics_at_a_Glance_2022_0.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Per capita expenditure prediction using model stacking based on satellite ima...
Teaching material agriculture food technology
Encapsulation theory and applications.pdf

Odoo - Backend modules in v8

  • 1. Backend Modules in V8 Raphael Collet (rco@odoo.com)
  • 4. Architecture of Odoo Three-tier client/server/database Web client in Javascript Server and backend modules in Python MVC framework · · · ·
  • 6. The Module Manage courses, sessions, and subscriptions Learn Structure of a module Definition of data models Definition of views and menus · · · · ·
  • 7. Structure of a Module An Odoo module is a python module (data models), with a manifest file, XML and CSV data files (base data, views, menus), frontend resources (Javascript, CSS). · · · ·
  • 8. The Open Academy Module The manifest file __odoo__.py: {{ 'name':: 'Open Academy',, 'version':: '1.0',, 'category':: 'Tools',, 'summary':: 'Courses, Sessions, Subscriptions',, 'description':: "...",, 'depends' :: [['base'],], 'data' :: [['view/menu.xml'],], 'images':: [],[], 'demo':: [],[], 'application':: True,, }}
  • 9. The Course Model A model and its fields are defined in a Python class: fromfrom odoo importimport Model,, fields classclass Course((Model):): _name == 'openacademy.course' name == fields..Char((string=='Title',, required==True)) description == fields..Text()()
  • 10. The Menu as XML data <?xml version="1.0" encoding="UTF-8"?> <openerp><openerp> <data><data> <menuitem<menuitem name="Open Academy" id="menu_root" sequence="110"/>/> <menuitem<menuitem name="General" id="menu_general" parent="menu_root"/>/> <record<record model="ir.actions.act_window" id="action_courses">> <field<field name="name">>Courses</field></field> <field<field name="res_model">>openacademy.course</field></field> <field<field name="view_mode">>tree,form</field></field> </record></record> <menuitem<menuitem name="Courses" id="menu_courses" parent="menu_general" sequence="1" action="action_courses"/>/> </data></data> </openerp></openerp>
  • 11. Let's add a Form View <record<record model="ir.ui.view" id="course_form">> <field<field name="name">>course form view</field></field> <field<field name="model">>openacademy.course</field></field> <field<field name="arch" type="xml">> <form<form string="Course" version="7.0">> <sheet><sheet> <h1><h1> <field<field name="name" placeholder="Course Title"/>/> </h1></h1> <notebook><notebook> <page<page string="Description">> <field<field name="description"/>/> </page></page> </notebook></notebook> </sheet></sheet> </form></form> </field></field> </record></record>
  • 12. The Session Model classclass Session((Model):): _name == 'openacademy.session' name == fields..Char((required==True)) start_date == fields..Date()() duration == fields..Integer((help=="Duration in days")) seats == fields..Integer((string=="Number of Seats"))
  • 13. Relational Fields Let us link sessions to courses and instructors: classclass Session((Model):): _name == 'openacademy.session' ...... course == fields..Many2one(('openacademy.course',, required==True)) instructor == fields..Many2one(('res.partner'))
  • 14. Relational Fields Let us back-link courses and sessions: classclass Course((Model):): _name == 'openacademy.course' ...... responsible == fields..Many2one(('res.users')) sessions == fields..One2many(('openacademy.session',, 'course'))
  • 15. Relational Fields Let us link sessions to partners for attendee subscription: classclass Session((Model):): _name == 'openacademy.session' ...... attendees == fields..Many2many(('res.partner'))
  • 16. Computed Fields The value of those fields is computed: classclass Session((Model):): _name == 'openacademy.session' ...... taken_seats == fields..Float((compute=='_compute_taken_seats')) @api.one@api.one @api.depends@api.depends(('attendees',, 'seats')) defdef _compute_taken_seats((self):): ifif self..seats:: self..taken_seats == 100.0100.0 ** len((self..attendees)) // self..seats elseelse:: self..taken_seats == 0.00.0
  • 17. About self Model instances are recordsetsrecordsets. A recordset is an hybrid concept: collection of records record forfor session inin self:: printprint session..name printprint session..course..name assertassert self..name ==== self[[00]]..name · ·
  • 18. Feedback with "Onchange" Methods Modify form values when some field is filled in: classclass Session((Model):): _name == 'openacademy.session' ...... @api.onchange@api.onchange(('course')) defdef _onchange_course((self):): ifif notnot self..name:: self..name == self..course..name
  • 19. Default Values Specify the initial value to use in a form: classclass Session((Model):): _name == 'openacademy.session' ...... active == fields..Boolean((default==True)) start_date == fields..Date((default==fields..Date..today)) ......
  • 20. Model Constraints Prevent bad data: fromfrom odoo.exceptions importimport WarningWarning classclass Session((Model):): _name == 'openacademy.session' ...... @api.one@api.one @api.constrains@api.constrains(('instructor',, 'attendees')) defdef _check_instructor((self):): ifif self..instructor inin self..attendees:: raiseraise WarningWarning(("Instructor of session '%s' " "cannot attend its own session" %% self..name))
  • 21. More Stuff Extend existing models Many view types Workflows Reports Security Translations · · · · · ·
  • 23. Conclusion Modules have a simple structure Model definition intuitive and efficient uses Python standards (decorators, descriptors) recordsets provide support for "batch" processing many model hooks (default values, constraints, computed fields) · · · · ·