SlideShare uma empresa Scribd logo
1 de 23
Baixar para ler offline
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)
·
·
·
·
·

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

How to Develop your own in App-Purchase Service in Odoo
How to Develop your own in App-Purchase Service in OdooHow to Develop your own in App-Purchase Service in Odoo
How to Develop your own in App-Purchase Service in Odoo
 
VueJS Introduction
VueJS IntroductionVueJS Introduction
VueJS Introduction
 
Empower your App by Inheriting from Odoo Mixins
Empower your App by Inheriting from Odoo MixinsEmpower your App by Inheriting from Odoo Mixins
Empower your App by Inheriting from Odoo Mixins
 
Asynchronous JS in Odoo
Asynchronous JS in OdooAsynchronous JS in Odoo
Asynchronous JS in Odoo
 
Angular
AngularAngular
Angular
 
Angular
AngularAngular
Angular
 
Secure your app with keycloak
Secure your app with keycloakSecure your app with keycloak
Secure your app with keycloak
 
Odoo - Business intelligence: Develop cube views for your own objects
Odoo - Business intelligence: Develop cube views for your own objectsOdoo - Business intelligence: Develop cube views for your own objects
Odoo - Business intelligence: Develop cube views for your own objects
 
Odoo's Test Framework - Learn Best Practices
Odoo's Test Framework - Learn Best PracticesOdoo's Test Framework - Learn Best Practices
Odoo's Test Framework - Learn Best Practices
 
Getting Started with FIDO2
Getting Started with FIDO2Getting Started with FIDO2
Getting Started with FIDO2
 
List Activity Widget in Odoo 14
List Activity Widget in Odoo 14 List Activity Widget in Odoo 14
List Activity Widget in Odoo 14
 
What are Wizards - Defining and Launching in Odoo 15Wizards - Defining and La...
What are Wizards - Defining and Launching in Odoo 15Wizards - Defining and La...What are Wizards - Defining and Launching in Odoo 15Wizards - Defining and La...
What are Wizards - Defining and Launching in Odoo 15Wizards - Defining and La...
 
Create Data Files and Load Data in Odoo 15
Create Data Files and Load Data in Odoo 15Create Data Files and Load Data in Odoo 15
Create Data Files and Load Data in Odoo 15
 
QWeb Report in odoo
QWeb Report in odooQWeb Report in odoo
QWeb Report in odoo
 
Odoo Experience 2018 - Visualizing Data in Odoo: How to Create a New View
Odoo Experience 2018 - Visualizing Data in Odoo: How to Create a New ViewOdoo Experience 2018 - Visualizing Data in Odoo: How to Create a New View
Odoo Experience 2018 - Visualizing Data in Odoo: How to Create a New View
 
Owl: The New Odoo UI Framework
Owl: The New Odoo UI FrameworkOwl: The New Odoo UI Framework
Owl: The New Odoo UI Framework
 
Website Appointment Booking in odoo
Website Appointment Booking in odooWebsite Appointment Booking in odoo
Website Appointment Booking in odoo
 
Odoo Online platform: architecture and challenges
Odoo Online platform: architecture and challengesOdoo Online platform: architecture and challenges
Odoo Online platform: architecture and challenges
 
External dependencies ,pre init hook &amp; post init hook in odoo
External dependencies ,pre init hook &amp; post init hook in odooExternal dependencies ,pre init hook &amp; post init hook in odoo
External dependencies ,pre init hook &amp; post init hook in odoo
 
View Inheritance in Odoo 15
View Inheritance in Odoo 15View Inheritance in Odoo 15
View Inheritance in Odoo 15
 

Destaque

Tips on how to improve the performance of your custom modules for high volume...
Tips on how to improve the performance of your custom modules for high volume...Tips on how to improve the performance of your custom modules for high volume...
Tips on how to improve the performance of your custom modules for high volume...
Odoo
 

Destaque (12)

Tips on how to improve the performance of your custom modules for high volume...
Tips on how to improve the performance of your custom modules for high volume...Tips on how to improve the performance of your custom modules for high volume...
Tips on how to improve the performance of your custom modules for high volume...
 
Improving the performance of Odoo deployments
Improving the performance of Odoo deploymentsImproving the performance of Odoo deployments
Improving the performance of Odoo deployments
 
Odoo 2016 - Retrospective
Odoo 2016 - RetrospectiveOdoo 2016 - Retrospective
Odoo 2016 - Retrospective
 
Odoo (OpenERP) - Creating a module
Odoo (OpenERP) - Creating a moduleOdoo (OpenERP) - Creating a module
Odoo (OpenERP) - Creating a module
 
Odoo Web Services
Odoo Web ServicesOdoo Web Services
Odoo Web Services
 
How to configure PyCharm for Odoo development in Windows?
How to configure PyCharm for Odoo development in Windows?How to configure PyCharm for Odoo development in Windows?
How to configure PyCharm for Odoo development in Windows?
 
Widgets in odoo
Widgets in odooWidgets in odoo
Widgets in odoo
 
Timesheet based payroll
Timesheet based payrollTimesheet based payroll
Timesheet based payroll
 
Xml operations in odoo
Xml operations in odooXml operations in odoo
Xml operations in odoo
 
Development Odoo Basic
Development Odoo BasicDevelopment Odoo Basic
Development Odoo Basic
 
User Manual For Crafito Odoo Theme
User Manual For Crafito Odoo ThemeUser Manual For Crafito Odoo Theme
User Manual For Crafito Odoo Theme
 
Odoo - Create themes for website
Odoo - Create themes for websiteOdoo - Create themes for website
Odoo - Create themes for website
 

Semelhante a Odoo - Backend modules in v8

Introduction to Backbone.js for Rails developers
Introduction to Backbone.js for Rails developersIntroduction to Backbone.js for Rails developers
Introduction to Backbone.js for Rails developers
AoteaStudios
 

Semelhante a Odoo - Backend modules in v8 (20)

MOOC: Python & Web as Architecture
MOOC: Python & Web as ArchitectureMOOC: Python & Web as Architecture
MOOC: Python & Web as Architecture
 
Tutorial mvc (pelajari ini jika ingin tahu mvc) keren
Tutorial mvc (pelajari ini jika ingin tahu mvc) kerenTutorial mvc (pelajari ini jika ingin tahu mvc) keren
Tutorial mvc (pelajari ini jika ingin tahu mvc) keren
 
Services Drupalcamp Stockholm 2009
Services Drupalcamp Stockholm 2009Services Drupalcamp Stockholm 2009
Services Drupalcamp Stockholm 2009
 
Neo4j.pptx
Neo4j.pptxNeo4j.pptx
Neo4j.pptx
 
Azure machine learning service
Azure machine learning serviceAzure machine learning service
Azure machine learning service
 
AngularJS and SPA
AngularJS and SPAAngularJS and SPA
AngularJS and SPA
 
Template rendering in rails
Template rendering in rails Template rendering in rails
Template rendering in rails
 
Develop an App with the Odoo Framework
Develop an App with the Odoo FrameworkDevelop an App with the Odoo Framework
Develop an App with the Odoo Framework
 
Microservices Primer for Monolithic Devs
Microservices Primer for Monolithic DevsMicroservices Primer for Monolithic Devs
Microservices Primer for Monolithic Devs
 
Utilisation de MLflow pour le cycle de vie des projet Machine learning
Utilisation de MLflow pour le cycle de vie des projet Machine learningUtilisation de MLflow pour le cycle de vie des projet Machine learning
Utilisation de MLflow pour le cycle de vie des projet Machine learning
 
Building and Running Your App in the Cloud
Building and Running Your App in the CloudBuilding and Running Your App in the Cloud
Building and Running Your App in the Cloud
 
SahanaCamp NYC Day 3: Eden Technical Workshop
SahanaCamp NYC Day 3: Eden Technical WorkshopSahanaCamp NYC Day 3: Eden Technical Workshop
SahanaCamp NYC Day 3: Eden Technical Workshop
 
Zotonic tutorial EUC 2013
Zotonic tutorial EUC 2013Zotonic tutorial EUC 2013
Zotonic tutorial EUC 2013
 
Django Admin: Widgetry & Witchery
Django Admin: Widgetry & WitcheryDjango Admin: Widgetry & Witchery
Django Admin: Widgetry & Witchery
 
Introduction to Backbone.js for Rails developers
Introduction to Backbone.js for Rails developersIntroduction to Backbone.js for Rails developers
Introduction to Backbone.js for Rails developers
 
Oop objects_classes
Oop objects_classesOop objects_classes
Oop objects_classes
 
Camunda BPM 7.2: Tasklist and Javascript Forms SDK (English)
Camunda BPM 7.2: Tasklist and Javascript Forms SDK (English)Camunda BPM 7.2: Tasklist and Javascript Forms SDK (English)
Camunda BPM 7.2: Tasklist and Javascript Forms SDK (English)
 
PuppetConf 2016: The Long, Twisty Road to Automation: Implementing Puppet at ...
PuppetConf 2016: The Long, Twisty Road to Automation: Implementing Puppet at ...PuppetConf 2016: The Long, Twisty Road to Automation: Implementing Puppet at ...
PuppetConf 2016: The Long, Twisty Road to Automation: Implementing Puppet at ...
 
Laravel 8 export data as excel file with example
Laravel 8 export data as excel file with exampleLaravel 8 export data as excel file with example
Laravel 8 export data as excel file with example
 
Django design-patterns
Django design-patternsDjango design-patterns
Django design-patterns
 

Mais de Odoo

Mais de Odoo (20)

Timesheet Workshop: The Timesheet App People Love!
Timesheet Workshop: The Timesheet App People Love!Timesheet Workshop: The Timesheet App People Love!
Timesheet Workshop: The Timesheet App People Love!
 
Odoo 3D Product View with Google Model-Viewer
Odoo 3D Product View with Google Model-ViewerOdoo 3D Product View with Google Model-Viewer
Odoo 3D Product View with Google Model-Viewer
 
Keynote - Vision & Strategy
Keynote - Vision & StrategyKeynote - Vision & Strategy
Keynote - Vision & Strategy
 
Opening Keynote - Unveilling Odoo 14
Opening Keynote - Unveilling Odoo 14Opening Keynote - Unveilling Odoo 14
Opening Keynote - Unveilling Odoo 14
 
Extending Odoo with a Comprehensive Budgeting and Forecasting Capability
Extending Odoo with a Comprehensive Budgeting and Forecasting CapabilityExtending Odoo with a Comprehensive Budgeting and Forecasting Capability
Extending Odoo with a Comprehensive Budgeting and Forecasting Capability
 
Managing Multi-channel Selling with Odoo
Managing Multi-channel Selling with OdooManaging Multi-channel Selling with Odoo
Managing Multi-channel Selling with Odoo
 
Product Configurator: Advanced Use Case
Product Configurator: Advanced Use CaseProduct Configurator: Advanced Use Case
Product Configurator: Advanced Use Case
 
Accounting Automation: How Much Money We Saved and How?
Accounting Automation: How Much Money We Saved and How?Accounting Automation: How Much Money We Saved and How?
Accounting Automation: How Much Money We Saved and How?
 
Rock Your Logistics with Advanced Operations
Rock Your Logistics with Advanced OperationsRock Your Logistics with Advanced Operations
Rock Your Logistics with Advanced Operations
 
Transition from a cost to a flow-centric organization
Transition from a cost to a flow-centric organizationTransition from a cost to a flow-centric organization
Transition from a cost to a flow-centric organization
 
Synchronization: The Supply Chain Response to Overcome the Crisis
Synchronization: The Supply Chain Response to Overcome the CrisisSynchronization: The Supply Chain Response to Overcome the Crisis
Synchronization: The Supply Chain Response to Overcome the Crisis
 
Running a University with Odoo
Running a University with OdooRunning a University with Odoo
Running a University with Odoo
 
Down Payments on Purchase Orders in Odoo
Down Payments on Purchase Orders in OdooDown Payments on Purchase Orders in Odoo
Down Payments on Purchase Orders in Odoo
 
Odoo Implementation in Phases - Success Story of a Retail Chain 3Sach food
Odoo Implementation in Phases - Success Story of a Retail Chain 3Sach foodOdoo Implementation in Phases - Success Story of a Retail Chain 3Sach food
Odoo Implementation in Phases - Success Story of a Retail Chain 3Sach food
 
Migration from Salesforce to Odoo
Migration from Salesforce to OdooMigration from Salesforce to Odoo
Migration from Salesforce to Odoo
 
Preventing User Mistakes by Using Machine Learning
Preventing User Mistakes by Using Machine LearningPreventing User Mistakes by Using Machine Learning
Preventing User Mistakes by Using Machine Learning
 
Becoming an Odoo Expert: How to Prepare for the Certification
Becoming an Odoo Expert: How to Prepare for the Certification Becoming an Odoo Expert: How to Prepare for the Certification
Becoming an Odoo Expert: How to Prepare for the Certification
 
Instant Printing of any Odoo Report or Shipping Label
Instant Printing of any Odoo Report or Shipping LabelInstant Printing of any Odoo Report or Shipping Label
Instant Printing of any Odoo Report or Shipping Label
 
How Odoo helped an Organization Grow 3 Fold
How Odoo helped an Organization Grow 3 FoldHow Odoo helped an Organization Grow 3 Fold
How Odoo helped an Organization Grow 3 Fold
 
From Shopify to Odoo
From Shopify to OdooFrom Shopify to Odoo
From Shopify to Odoo
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.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) · · · · ·