SlideShare a Scribd company logo
1 of 52
Use case:
Plant Nursery
— Classy Cool Dev
Thanks Classy Cool Dev!
But, how can
you be so sure
Odoo is the
perfect
choice?
Architecture
● Three-tier client/server/database
Three-tier
● Presentation Layer (Client):
HTML5, JavaScript, CSS
● Application Layer (Server):
Python3
● Data Layer (Database):
PostgreSQL
Architecture
● Webclient in Javascript
Architecture
● Server and backend modules in Python
○ MVC framework
MVC framework
● Model: Data logic
● View: UI logic
● Controller: Interface
Architecture
● Server and backend modules in Python
○ ORM to interact with database
ORM:
Bridges the gap
between python
and postgreSQL.
class MyAwesomeCharacter(models.Model):
_name = 'my.awesome.character'
name = fields.Char(string="name",
required=True)
friend =
fields.Many2one('my.awesome.character',
string='Best Friend')
Model definition:
ORM
Table definition:
ORM Pros
● Less SQL
● Abstracts the DB
● Advanced features (cache, security, …)
● Better SQL queries
ORM Cons
● Performance (?)
● Training
● Initial config
● Less deep understanding
The Feature
Manage a plant nursery:
● List of plants
● Manage orders
● Keep a customers list
Technically
you will learn:
● Structure of a module
● Definition of data models
● Definition of views and menus
An Odoo module is:
● A manifest file
● Python code (models, logic)
● Data files, XML and CSV (base data, views, menus)
● Frontend resources (Javascript, CSS)
Plant
Nursery
The manifest file:
__manifest__.py
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and
licensing details.
{
'name': 'Plant Nursery',
'version': '1.0',
'category': 'Tools',
'summary': 'Plants and customers management',
'depends': ['web'],
'data': [
'security/ir.model.access.csv',
'data/data.xml',
'views/views.xml',
],
'demo': [
'data/demo.xml',
],
'css': [],
'installable': True,
'auto_install': False,
'application': True,
}
Describe the
models
plant_nursery/models.p
y
from odoo import fields, models
class Plants(models.Model):
_name = 'nursery.plant'
name = fields.Char("Plant Name")
price = fields.Float()
class Customer(models.Model):
_name = 'nursery.customer'
name = fields.Char("Customer Name", required=True)
email = fields.Char(help="To receive the newsletter")
Define the security
plant_nursery/security/ir.model.access.csv
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_nursery_plant,access_nursery_plant,plant_nursery.model_nursery_plant,base.group_user,1,1,1,1
access_nursery_customer,access_nursery_customer,plant_nursery.model_nursery_customer,base.group_user,
1,1,1,1
Define the
action
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<record model="ir.actions.act_window"
id="action_nursery_plant">
<field name="name">Plants</field>
<field name="res_model">nursery.plant</field>
<field name="view_mode">tree,form</field>
</record>
<menuitem name="Plant Nursery"
id="nursery_root_menu"
web_icon="plant_nursery,static/description/icon.png"/
>
<menuitem name="Plants" id="nursery_plant_menu"
parent="nursery_root_menu"
action="action_nursery_plant"
sequence="1"/>
</odoo>
plant_nursery/views/nursery_views.xml
Define a form view
plant_nursery/views/nursery_views.xml
<record model="ir.ui.view" id="nursery_plant_view_form">
<field name="name">nursery.plant.view.form</field>
<field name="model">nursery.plant</field>
<field name="arch" type="xml">
<form string="Plant">
<sheet>
<h1>
<field name="name" placeholder="Plant Name"/>
</h1>
<notebook>
<page string="Shop">
<group>
<field name="price"/>
</group>
</page>
</notebook>
</sheet>
</form>
</field>
</record>
Auto generated views
Relations:
● Many2one
● One2many
● Many2many
Relations
class Order(models.Model):
_name = 'nursery.order'
plant_id = fields.Many2one("nursery.plant", required=True)
customer_id = fields.Many2one("nursery.customer")
class Plants(models.Model):
_name = 'nursery.plant'
order_ids = fields.One2many("nursery.order", "plant_id", string="Orders")
Auto generated views
Basic Operations:
● Read
● Write
● Create
● Unlink
● Search
ORM Interactions
class Order(models.Model):
_name = 'nursery.order'
name = fields.Datetime(default=fields.Datetime.now)
plant_id = fields.Many2one("nursery.plant", required=True)
customer_id = fields.Many2one("nursery.customer")
state = fields.Selection([
('draft', 'Draft'),
('confirm', 'Confirmed'),
('cancel', 'Canceled')
], default='draft')
last_modification = fields.Datetime(readonly=True)
ORM Interactionsclass Order(model.Models):
_name = 'nursery.order'
def write(self, values):
# helper to "YYYY-MM-DD"
values['last_modification'] = fields.Datetime.now()
return super(Order, self).write(values)
def unlink(self):
# self is a recordset
for order in self:
if order.state == 'confirm':
raise UserError("You can not delete confirmed orders")
return super(Order, self).unlink()
ORM Interactions
<record model="ir.ui.view" id="nursery_order_form">
<field name="name">Order Form View</field>
<field name="model">nursery.order</field>
<field name="arch" type="xml">
<form string="Plant Order">
<header>
<field name="state" widget="statusbar" options="{'clickable': '1'}"/>
</header>
<sheet>
<group col="4">
<group colspan="2">
<field name="plant_id" />
<field name="customer_id" />
</group>
<group colspan="2">
<field name="last_modification" />
</group>
</group>
</sheet>
</form>
</field>
</record>
Auto generated views
— Classy Cool Dev
Thanks Classy Cool Dev!
What else
could you
show us?
Computed Fields:
● For complex values
● Trigger for recompute
● Stored or not in the
database
Computed Fields
class Plants(models.Model):
_name = 'nursery.plant'
order_count = fields.Integer(compute='_compute_order_count',
store=True,
string="Total sold")
@api.depends('order_ids')
def _compute_order_count(self):
for plant in self:
plant.order_count = len(plant.order_ids)
Model Constraints
● Triggered after every creation or
modification.
● Instead of overriding create & write
Model Constraints
class Plants(models.Model):
_name = 'nursery.plant'
number_in_stock = fields.Integer()
@api.constrains('order_count', 'number_in_stock')
def _check_available_in_stock(self):
for plant in self:
if plant.number_in_stock and 
plant.order_count > plant.number_in_stock:
raise UserError("There is only %s %s in stock but %s were sold"
% (plant.number_in_stock, plant.name, plant.order_count))
Kanban View:
● Display information
● Add pictures
● Aggregated view
Define a Kanban View:
class Plants(models.Model):
_name = 'nursery.plant'
image = fields.Binary("Plant Image", attachment=True)
<record model="ir.actions.act_window"
id="action_nursery_order">
<field name="name">Orders</field>
<field name="res_model">nursery.order</field>
<field name="view_mode">kanban,tree,form</field>
</record>
<record id="nursery_plant_view_kanban" model="ir.ui.view">
<field name="name">nursery.plant.view.kanban</field>
<field name="model">nursery.plant</field>
<field name="arch" type="xml">
<kanban>
<field name="id"/>
<field name="image"/>
<templates>
<t t-name="kanban-box">
<div class="oe_kanban_global_click">
<div class="o_kanban_image">
<img t-att-src="kanban_image('nursery.plant', 'image', record.id.raw_value)"/>
</div>
<div class="oe_kanban_details">
<strong class="o_kanban_record_title"><field name="name"/></strong>
<ul><li><strong>Price: <field name="price"></field></strong></li</ul>
</div>
</div>
</t>
</templates>
</kanban>
</field>
</record>
Define a Kanban View:
Auto generated views
Auto generated views
Define a Search View:
<record id="nursery_order_view_search" model="ir.ui.view">
<field name="name">nursery.order.view.search</field>
<field name="model">nursery.order</field>
<field name="arch" type="xml">
<search string="Search Orders">
<field name="plant_id" string="Plant"/>
<field name="customer_id" string="Customer"/>
<field name="state"/>
<filter string="Confirmed" name="confirmed"
domain="[('state', '=', 'confirm')]"/>
<separator />
<group expand="0" string="Group By">
<filter string="State" name="group_by_state"
domain="[]" context="{'group_by':'state'}"/>
</group>
</search>
</field>
</record>
Display all the states
class Order(models.Model):
_name = 'nursery.order'
state = fields.Selection([
('draft', 'Draft'),
('confirm', 'Confirmed'),
('cancel', 'Canceled')
], default='draft', group_expand="_expand_states")
def _expand_states(self, states, domain, order):
return [key for key, val in
type(self).state.selection]
Always group by state:
<record model="ir.actions.act_window"
id="action_nursery_order">
<field name="name">Orders</field>
<field name="res_model">nursery.order</field>
<field name="view_mode">kanban,tree,form</field>
<field
name="context">{'search_default_group_by_state': 1}</field>
</record>
Auto generated views
Onchange methods:
class Customer(models.Model):
_name = 'nursery.customer'
_description = 'Nursery Customer'
name = fields.Char('Customer Name', required=True)
email = fields.Char(help="To receive the newsletter")
mobile = fields.Char('Mobile')
image = fields.Binary('Photo', attachment=True)
address = fields.Char('Address')
country_id = fields.Many2one('res.country',
string='Country')
partner_id = fields.Many2one('res.partner',
string='Customer Address')
Onchange methods:
@api.onchange('partner_id')
def _onchange_partner_id(self):
if self.partner_id:
if self.partner_id.image_1920:
self.image = self.partner_id.image_1920
if self.partner_id.email:
self.email = self.partner_id.email
if self.partner_id.mobile:
self.mobile = self.partner_id.mobile
if self.partner_id.country_id:
self.country_id = self.partner_id.country_id.id
if not self.address:
self.address =
self.partner_id.with_context(show_address_only=True)._get_name()
Auto generated views
Sequences
<!-- Sequences for plant.orders -->
<record id="seq_plant_order" model="ir.sequence">
<field name="name">Plant Orders</field>
<field name="code">plant.order</field>
<field name="prefix">Order</field>
<field name="padding">3</field>
<field name="company_id" eval="False"/>
</record>
Sequences
@api.model
def create(self, vals):
if vals.get('name', _('New')) == _('New'):
if 'company_id' in vals:
vals['name'] = self.env['ir.sequence'].with_context(
force_company=vals['company_id']
).next_by_code('plant.order') or _('New')
else:
vals['name'] =
self.env['ir.sequence'].next_by_code('plant.order') or _('New')
return super(Order, self).create(vals)
Thank You
https://github.com/tivisse/odoodays-
2020

More Related Content

What's hot

Tools for Solving Performance Issues
Tools for Solving Performance IssuesTools for Solving Performance Issues
Tools for Solving Performance IssuesOdoo
 
Odoo icon smart buttons
Odoo   icon smart buttonsOdoo   icon smart buttons
Odoo icon smart buttonsTaieb Kristou
 
Odoo (Build module, Security, ORM)
Odoo (Build module, Security, ORM)Odoo (Build module, Security, ORM)
Odoo (Build module, Security, ORM)sroo galal
 
View Inheritance in Odoo 16
View Inheritance in Odoo 16View Inheritance in Odoo 16
View Inheritance in Odoo 16Celine George
 
View Inheritance in Odoo 15
View Inheritance in Odoo 15View Inheritance in Odoo 15
View Inheritance in Odoo 15Celine George
 
Asynchronous JS in Odoo
Asynchronous JS in OdooAsynchronous JS in Odoo
Asynchronous JS in OdooOdoo
 
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...Celine George
 
Defining Kanban View in Odoo15 | Advanced Views
Defining Kanban View in Odoo15 | Advanced ViewsDefining Kanban View in Odoo15 | Advanced Views
Defining Kanban View in Odoo15 | Advanced ViewsCeline George
 
Bi email-alert-notification - Fusion Alert
Bi email-alert-notification - Fusion AlertBi email-alert-notification - Fusion Alert
Bi email-alert-notification - Fusion AlertFeras Ahmad
 
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 15Celine George
 
Odoo Experience 2018 - Inherit from These 10 Mixins to Empower Your App
Odoo Experience 2018 - Inherit from These 10 Mixins to Empower Your AppOdoo Experience 2018 - Inherit from These 10 Mixins to Empower Your App
Odoo Experience 2018 - Inherit from These 10 Mixins to Empower Your AppElínAnna Jónasdóttir
 
Updating Client Interface 'on change' @api.onchange in Odoo 15
Updating Client Interface 'on change' @api.onchange in Odoo 15Updating Client Interface 'on change' @api.onchange in Odoo 15
Updating Client Interface 'on change' @api.onchange in Odoo 15Celine George
 
Oracle Fusion Cloud HCM Payroll Query
Oracle Fusion Cloud HCM Payroll QueryOracle Fusion Cloud HCM Payroll Query
Oracle Fusion Cloud HCM Payroll QueryFeras Ahmad
 
Object Relation Mapping in Odoo 16
Object Relation Mapping in Odoo 16Object Relation Mapping in Odoo 16
Object Relation Mapping in Odoo 16Celine George
 
How to Use Constraint and SQL Constraint in Odoo 15
How to Use Constraint and SQL Constraint in Odoo 15How to Use Constraint and SQL Constraint in Odoo 15
How to Use Constraint and SQL Constraint in Odoo 15Celine George
 
Odoo - From v7 to v8: the new api
Odoo - From v7 to v8: the new apiOdoo - From v7 to v8: the new api
Odoo - From v7 to v8: the new apiOdoo
 
The Goal with performance details Oracle Fusion Cloud
The Goal with performance details Oracle Fusion CloudThe Goal with performance details Oracle Fusion Cloud
The Goal with performance details Oracle Fusion CloudFeras Ahmad
 
odoo 11.0 development (CRUD)
odoo 11.0 development (CRUD)odoo 11.0 development (CRUD)
odoo 11.0 development (CRUD)Mohamed Magdy
 
Query to get the geography information using bi report
Query to get the geography information using bi reportQuery to get the geography information using bi report
Query to get the geography information using bi reportFeras Ahmad
 
Odoo - Smart buttons
Odoo - Smart buttonsOdoo - Smart buttons
Odoo - Smart buttonsOdoo
 

What's hot (20)

Tools for Solving Performance Issues
Tools for Solving Performance IssuesTools for Solving Performance Issues
Tools for Solving Performance Issues
 
Odoo icon smart buttons
Odoo   icon smart buttonsOdoo   icon smart buttons
Odoo icon smart buttons
 
Odoo (Build module, Security, ORM)
Odoo (Build module, Security, ORM)Odoo (Build module, Security, ORM)
Odoo (Build module, Security, ORM)
 
View Inheritance in Odoo 16
View Inheritance in Odoo 16View Inheritance in Odoo 16
View Inheritance in Odoo 16
 
View Inheritance in Odoo 15
View Inheritance in Odoo 15View Inheritance in Odoo 15
View Inheritance in Odoo 15
 
Asynchronous JS in Odoo
Asynchronous JS in OdooAsynchronous JS in Odoo
Asynchronous JS in Odoo
 
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...
 
Defining Kanban View in Odoo15 | Advanced Views
Defining Kanban View in Odoo15 | Advanced ViewsDefining Kanban View in Odoo15 | Advanced Views
Defining Kanban View in Odoo15 | Advanced Views
 
Bi email-alert-notification - Fusion Alert
Bi email-alert-notification - Fusion AlertBi email-alert-notification - Fusion Alert
Bi email-alert-notification - Fusion Alert
 
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
 
Odoo Experience 2018 - Inherit from These 10 Mixins to Empower Your App
Odoo Experience 2018 - Inherit from These 10 Mixins to Empower Your AppOdoo Experience 2018 - Inherit from These 10 Mixins to Empower Your App
Odoo Experience 2018 - Inherit from These 10 Mixins to Empower Your App
 
Updating Client Interface 'on change' @api.onchange in Odoo 15
Updating Client Interface 'on change' @api.onchange in Odoo 15Updating Client Interface 'on change' @api.onchange in Odoo 15
Updating Client Interface 'on change' @api.onchange in Odoo 15
 
Oracle Fusion Cloud HCM Payroll Query
Oracle Fusion Cloud HCM Payroll QueryOracle Fusion Cloud HCM Payroll Query
Oracle Fusion Cloud HCM Payroll Query
 
Object Relation Mapping in Odoo 16
Object Relation Mapping in Odoo 16Object Relation Mapping in Odoo 16
Object Relation Mapping in Odoo 16
 
How to Use Constraint and SQL Constraint in Odoo 15
How to Use Constraint and SQL Constraint in Odoo 15How to Use Constraint and SQL Constraint in Odoo 15
How to Use Constraint and SQL Constraint in Odoo 15
 
Odoo - From v7 to v8: the new api
Odoo - From v7 to v8: the new apiOdoo - From v7 to v8: the new api
Odoo - From v7 to v8: the new api
 
The Goal with performance details Oracle Fusion Cloud
The Goal with performance details Oracle Fusion CloudThe Goal with performance details Oracle Fusion Cloud
The Goal with performance details Oracle Fusion Cloud
 
odoo 11.0 development (CRUD)
odoo 11.0 development (CRUD)odoo 11.0 development (CRUD)
odoo 11.0 development (CRUD)
 
Query to get the geography information using bi report
Query to get the geography information using bi reportQuery to get the geography information using bi report
Query to get the geography information using bi report
 
Odoo - Smart buttons
Odoo - Smart buttonsOdoo - Smart buttons
Odoo - Smart buttons
 

Similar to Tutorial: Develop an App with the Odoo Framework

Odoo Experience 2018 - Develop an App with the Odoo Framework
Odoo Experience 2018 - Develop an App with the Odoo FrameworkOdoo Experience 2018 - Develop an App with the Odoo Framework
Odoo Experience 2018 - Develop an App with the Odoo FrameworkElínAnna Jónasdóttir
 
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 FrameworkOdoo
 
RubyOnRails-Cheatsheet-BlaineKendall
RubyOnRails-Cheatsheet-BlaineKendallRubyOnRails-Cheatsheet-BlaineKendall
RubyOnRails-Cheatsheet-BlaineKendalltutorialsruby
 
RubyOnRails-Cheatsheet-BlaineKendall
RubyOnRails-Cheatsheet-BlaineKendallRubyOnRails-Cheatsheet-BlaineKendall
RubyOnRails-Cheatsheet-BlaineKendalltutorialsruby
 
Ajax nested form and ajax upload in rails
Ajax nested form and ajax upload in railsAjax nested form and ajax upload in rails
Ajax nested form and ajax upload in railsTse-Ching Ho
 
날로 먹는 Django admin 활용
날로 먹는 Django admin 활용날로 먹는 Django admin 활용
날로 먹는 Django admin 활용KyeongMook "Kay" Cha
 
ADO.NET Entity Framework by Jose A. Blakeley and Michael Pizzo
ADO.NET Entity Framework by Jose A. Blakeley and Michael PizzoADO.NET Entity Framework by Jose A. Blakeley and Michael Pizzo
ADO.NET Entity Framework by Jose A. Blakeley and Michael PizzoHasnain Iqbal
 
Java Web Development with Stripes
Java Web Development with StripesJava Web Development with Stripes
Java Web Development with StripesSamuel Santos
 
How to disassemble one monster app into an ecosystem of 30
How to disassemble one monster app into an ecosystem of 30How to disassemble one monster app into an ecosystem of 30
How to disassemble one monster app into an ecosystem of 30fiyuer
 
Connecting your Python App to OpenERP through OOOP
Connecting your Python App to OpenERP through OOOPConnecting your Python App to OpenERP through OOOP
Connecting your Python App to OpenERP through OOOPraimonesteve
 
Tips On Trick Odoo Add-On.pptx
Tips On Trick Odoo Add-On.pptxTips On Trick Odoo Add-On.pptx
Tips On Trick Odoo Add-On.pptxAgusto Sipahutar
 
Odoo Experience 2018 - From a Web Controller to a Full CMS
Odoo Experience 2018 - From a Web Controller to a Full CMSOdoo Experience 2018 - From a Web Controller to a Full CMS
Odoo Experience 2018 - From a Web Controller to a Full CMSElínAnna Jónasdóttir
 
Optimization in django orm
Optimization in django ormOptimization in django orm
Optimization in django ormDenys Levchenko
 
Solr's Search Relevancy (Understand Solr's query debug)
Solr's Search Relevancy (Understand Solr's query debug)Solr's Search Relevancy (Understand Solr's query debug)
Solr's Search Relevancy (Understand Solr's query debug)Wongnai
 
Java Web Programming on Google Cloud Platform [2/3] : Datastore
Java Web Programming on Google Cloud Platform [2/3] : DatastoreJava Web Programming on Google Cloud Platform [2/3] : Datastore
Java Web Programming on Google Cloud Platform [2/3] : DatastoreIMC Institute
 

Similar to Tutorial: Develop an App with the Odoo Framework (20)

Odoo Experience 2018 - Develop an App with the Odoo Framework
Odoo Experience 2018 - Develop an App with the Odoo FrameworkOdoo Experience 2018 - Develop an App with the Odoo Framework
Odoo Experience 2018 - Develop an App with the Odoo Framework
 
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
 
Django design-patterns
Django design-patternsDjango design-patterns
Django design-patterns
 
RubyOnRails-Cheatsheet-BlaineKendall
RubyOnRails-Cheatsheet-BlaineKendallRubyOnRails-Cheatsheet-BlaineKendall
RubyOnRails-Cheatsheet-BlaineKendall
 
RubyOnRails-Cheatsheet-BlaineKendall
RubyOnRails-Cheatsheet-BlaineKendallRubyOnRails-Cheatsheet-BlaineKendall
RubyOnRails-Cheatsheet-BlaineKendall
 
Ajax nested form and ajax upload in rails
Ajax nested form and ajax upload in railsAjax nested form and ajax upload in rails
Ajax nested form and ajax upload in rails
 
날로 먹는 Django admin 활용
날로 먹는 Django admin 활용날로 먹는 Django admin 활용
날로 먹는 Django admin 활용
 
ADO.NET Entity Framework by Jose A. Blakeley and Michael Pizzo
ADO.NET Entity Framework by Jose A. Blakeley and Michael PizzoADO.NET Entity Framework by Jose A. Blakeley and Michael Pizzo
ADO.NET Entity Framework by Jose A. Blakeley and Michael Pizzo
 
Active record(1)
Active record(1)Active record(1)
Active record(1)
 
Java Web Development with Stripes
Java Web Development with StripesJava Web Development with Stripes
Java Web Development with Stripes
 
How to disassemble one monster app into an ecosystem of 30
How to disassemble one monster app into an ecosystem of 30How to disassemble one monster app into an ecosystem of 30
How to disassemble one monster app into an ecosystem of 30
 
Connecting your Python App to OpenERP through OOOP
Connecting your Python App to OpenERP through OOOPConnecting your Python App to OpenERP through OOOP
Connecting your Python App to OpenERP through OOOP
 
Stripes Framework
Stripes FrameworkStripes Framework
Stripes Framework
 
Tips On Trick Odoo Add-On.pptx
Tips On Trick Odoo Add-On.pptxTips On Trick Odoo Add-On.pptx
Tips On Trick Odoo Add-On.pptx
 
Django
DjangoDjango
Django
 
Odoo Experience 2018 - From a Web Controller to a Full CMS
Odoo Experience 2018 - From a Web Controller to a Full CMSOdoo Experience 2018 - From a Web Controller to a Full CMS
Odoo Experience 2018 - From a Web Controller to a Full CMS
 
Optimization in django orm
Optimization in django ormOptimization in django orm
Optimization in django orm
 
Django Vs Rails
Django Vs RailsDjango Vs Rails
Django Vs Rails
 
Solr's Search Relevancy (Understand Solr's query debug)
Solr's Search Relevancy (Understand Solr's query debug)Solr's Search Relevancy (Understand Solr's query debug)
Solr's Search Relevancy (Understand Solr's query debug)
 
Java Web Programming on Google Cloud Platform [2/3] : Datastore
Java Web Programming on Google Cloud Platform [2/3] : DatastoreJava Web Programming on Google Cloud Platform [2/3] : Datastore
Java Web Programming on Google Cloud Platform [2/3] : Datastore
 

More from Odoo

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
 
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-ViewerOdoo
 
Keynote - Vision & Strategy
Keynote - Vision & StrategyKeynote - Vision & Strategy
Keynote - Vision & StrategyOdoo
 
Opening Keynote - Unveilling Odoo 14
Opening Keynote - Unveilling Odoo 14Opening Keynote - Unveilling Odoo 14
Opening Keynote - Unveilling Odoo 14Odoo
 
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 CapabilityOdoo
 
Managing Multi-channel Selling with Odoo
Managing Multi-channel Selling with OdooManaging Multi-channel Selling with Odoo
Managing Multi-channel Selling with OdooOdoo
 
Product Configurator: Advanced Use Case
Product Configurator: Advanced Use CaseProduct Configurator: Advanced Use Case
Product Configurator: Advanced Use CaseOdoo
 
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?Odoo
 
Rock Your Logistics with Advanced Operations
Rock Your Logistics with Advanced OperationsRock Your Logistics with Advanced Operations
Rock Your Logistics with Advanced OperationsOdoo
 
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 organizationOdoo
 
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 CrisisOdoo
 
Running a University with Odoo
Running a University with OdooRunning a University with Odoo
Running a University with OdooOdoo
 
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 OdooOdoo
 
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 foodOdoo
 
Migration from Salesforce to Odoo
Migration from Salesforce to OdooMigration from Salesforce to Odoo
Migration from Salesforce to OdooOdoo
 
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 LearningOdoo
 
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 Odoo
 
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 LabelOdoo
 
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 FoldOdoo
 
From Shopify to Odoo
From Shopify to OdooFrom Shopify to Odoo
From Shopify to OdooOdoo
 

More from 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
 

Recently uploaded

8447779800, Low rate Call girls in Shivaji Enclave Delhi NCR
8447779800, Low rate Call girls in Shivaji Enclave Delhi NCR8447779800, Low rate Call girls in Shivaji Enclave Delhi NCR
8447779800, Low rate Call girls in Shivaji Enclave Delhi NCRashishs7044
 
Digital Transformation in the PLM domain - distrib.pdf
Digital Transformation in the PLM domain - distrib.pdfDigital Transformation in the PLM domain - distrib.pdf
Digital Transformation in the PLM domain - distrib.pdfJos Voskuil
 
FULL ENJOY Call girls in Paharganj Delhi | 8377087607
FULL ENJOY Call girls in Paharganj Delhi | 8377087607FULL ENJOY Call girls in Paharganj Delhi | 8377087607
FULL ENJOY Call girls in Paharganj Delhi | 8377087607dollysharma2066
 
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu MenzaYouth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu Menzaictsugar
 
8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR
8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR
8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCRashishs7044
 
Call US-88OO1O2216 Call Girls In Mahipalpur Female Escort Service
Call US-88OO1O2216 Call Girls In Mahipalpur Female Escort ServiceCall US-88OO1O2216 Call Girls In Mahipalpur Female Escort Service
Call US-88OO1O2216 Call Girls In Mahipalpur Female Escort Servicecallgirls2057
 
Pitch Deck Teardown: Geodesic.Life's $500k Pre-seed deck
Pitch Deck Teardown: Geodesic.Life's $500k Pre-seed deckPitch Deck Teardown: Geodesic.Life's $500k Pre-seed deck
Pitch Deck Teardown: Geodesic.Life's $500k Pre-seed deckHajeJanKamps
 
Islamabad Escorts | Call 03070433345 | Escort Service in Islamabad
Islamabad Escorts | Call 03070433345 | Escort Service in IslamabadIslamabad Escorts | Call 03070433345 | Escort Service in Islamabad
Islamabad Escorts | Call 03070433345 | Escort Service in IslamabadAyesha Khan
 
8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR
8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR
8447779800, Low rate Call girls in New Ashok Nagar Delhi NCRashishs7044
 
Marketplace and Quality Assurance Presentation - Vincent Chirchir
Marketplace and Quality Assurance Presentation - Vincent ChirchirMarketplace and Quality Assurance Presentation - Vincent Chirchir
Marketplace and Quality Assurance Presentation - Vincent Chirchirictsugar
 
Kenya Coconut Production Presentation by Dr. Lalith Perera
Kenya Coconut Production Presentation by Dr. Lalith PereraKenya Coconut Production Presentation by Dr. Lalith Perera
Kenya Coconut Production Presentation by Dr. Lalith Pereraictsugar
 
Call Girls In Radisson Blu Hotel New Delhi Paschim Vihar ❤️8860477959 Escorts...
Call Girls In Radisson Blu Hotel New Delhi Paschim Vihar ❤️8860477959 Escorts...Call Girls In Radisson Blu Hotel New Delhi Paschim Vihar ❤️8860477959 Escorts...
Call Girls In Radisson Blu Hotel New Delhi Paschim Vihar ❤️8860477959 Escorts...lizamodels9
 
BEST Call Girls In Greater Noida ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,
BEST Call Girls In Greater Noida ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,BEST Call Girls In Greater Noida ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,
BEST Call Girls In Greater Noida ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,noida100girls
 
(Best) ENJOY Call Girls in Faridabad Ex | 8377087607
(Best) ENJOY Call Girls in Faridabad Ex | 8377087607(Best) ENJOY Call Girls in Faridabad Ex | 8377087607
(Best) ENJOY Call Girls in Faridabad Ex | 8377087607dollysharma2066
 
International Business Environments and Operations 16th Global Edition test b...
International Business Environments and Operations 16th Global Edition test b...International Business Environments and Operations 16th Global Edition test b...
International Business Environments and Operations 16th Global Edition test b...ssuserf63bd7
 
Cybersecurity Awareness Training Presentation v2024.03
Cybersecurity Awareness Training Presentation v2024.03Cybersecurity Awareness Training Presentation v2024.03
Cybersecurity Awareness Training Presentation v2024.03DallasHaselhorst
 
APRIL2024_UKRAINE_xml_0000000000000 .pdf
APRIL2024_UKRAINE_xml_0000000000000 .pdfAPRIL2024_UKRAINE_xml_0000000000000 .pdf
APRIL2024_UKRAINE_xml_0000000000000 .pdfRbc Rbcua
 
Market Sizes Sample Report - 2024 Edition
Market Sizes Sample Report - 2024 EditionMarket Sizes Sample Report - 2024 Edition
Market Sizes Sample Report - 2024 EditionMintel Group
 
Annual General Meeting Presentation Slides
Annual General Meeting Presentation SlidesAnnual General Meeting Presentation Slides
Annual General Meeting Presentation SlidesKeppelCorporation
 

Recently uploaded (20)

8447779800, Low rate Call girls in Shivaji Enclave Delhi NCR
8447779800, Low rate Call girls in Shivaji Enclave Delhi NCR8447779800, Low rate Call girls in Shivaji Enclave Delhi NCR
8447779800, Low rate Call girls in Shivaji Enclave Delhi NCR
 
Digital Transformation in the PLM domain - distrib.pdf
Digital Transformation in the PLM domain - distrib.pdfDigital Transformation in the PLM domain - distrib.pdf
Digital Transformation in the PLM domain - distrib.pdf
 
FULL ENJOY Call girls in Paharganj Delhi | 8377087607
FULL ENJOY Call girls in Paharganj Delhi | 8377087607FULL ENJOY Call girls in Paharganj Delhi | 8377087607
FULL ENJOY Call girls in Paharganj Delhi | 8377087607
 
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu MenzaYouth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
 
8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR
8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR
8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR
 
Call US-88OO1O2216 Call Girls In Mahipalpur Female Escort Service
Call US-88OO1O2216 Call Girls In Mahipalpur Female Escort ServiceCall US-88OO1O2216 Call Girls In Mahipalpur Female Escort Service
Call US-88OO1O2216 Call Girls In Mahipalpur Female Escort Service
 
Pitch Deck Teardown: Geodesic.Life's $500k Pre-seed deck
Pitch Deck Teardown: Geodesic.Life's $500k Pre-seed deckPitch Deck Teardown: Geodesic.Life's $500k Pre-seed deck
Pitch Deck Teardown: Geodesic.Life's $500k Pre-seed deck
 
Islamabad Escorts | Call 03070433345 | Escort Service in Islamabad
Islamabad Escorts | Call 03070433345 | Escort Service in IslamabadIslamabad Escorts | Call 03070433345 | Escort Service in Islamabad
Islamabad Escorts | Call 03070433345 | Escort Service in Islamabad
 
8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR
8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR
8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR
 
Marketplace and Quality Assurance Presentation - Vincent Chirchir
Marketplace and Quality Assurance Presentation - Vincent ChirchirMarketplace and Quality Assurance Presentation - Vincent Chirchir
Marketplace and Quality Assurance Presentation - Vincent Chirchir
 
Kenya Coconut Production Presentation by Dr. Lalith Perera
Kenya Coconut Production Presentation by Dr. Lalith PereraKenya Coconut Production Presentation by Dr. Lalith Perera
Kenya Coconut Production Presentation by Dr. Lalith Perera
 
Corporate Profile 47Billion Information Technology
Corporate Profile 47Billion Information TechnologyCorporate Profile 47Billion Information Technology
Corporate Profile 47Billion Information Technology
 
Call Girls In Radisson Blu Hotel New Delhi Paschim Vihar ❤️8860477959 Escorts...
Call Girls In Radisson Blu Hotel New Delhi Paschim Vihar ❤️8860477959 Escorts...Call Girls In Radisson Blu Hotel New Delhi Paschim Vihar ❤️8860477959 Escorts...
Call Girls In Radisson Blu Hotel New Delhi Paschim Vihar ❤️8860477959 Escorts...
 
BEST Call Girls In Greater Noida ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,
BEST Call Girls In Greater Noida ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,BEST Call Girls In Greater Noida ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,
BEST Call Girls In Greater Noida ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,
 
(Best) ENJOY Call Girls in Faridabad Ex | 8377087607
(Best) ENJOY Call Girls in Faridabad Ex | 8377087607(Best) ENJOY Call Girls in Faridabad Ex | 8377087607
(Best) ENJOY Call Girls in Faridabad Ex | 8377087607
 
International Business Environments and Operations 16th Global Edition test b...
International Business Environments and Operations 16th Global Edition test b...International Business Environments and Operations 16th Global Edition test b...
International Business Environments and Operations 16th Global Edition test b...
 
Cybersecurity Awareness Training Presentation v2024.03
Cybersecurity Awareness Training Presentation v2024.03Cybersecurity Awareness Training Presentation v2024.03
Cybersecurity Awareness Training Presentation v2024.03
 
APRIL2024_UKRAINE_xml_0000000000000 .pdf
APRIL2024_UKRAINE_xml_0000000000000 .pdfAPRIL2024_UKRAINE_xml_0000000000000 .pdf
APRIL2024_UKRAINE_xml_0000000000000 .pdf
 
Market Sizes Sample Report - 2024 Edition
Market Sizes Sample Report - 2024 EditionMarket Sizes Sample Report - 2024 Edition
Market Sizes Sample Report - 2024 Edition
 
Annual General Meeting Presentation Slides
Annual General Meeting Presentation SlidesAnnual General Meeting Presentation Slides
Annual General Meeting Presentation Slides
 

Tutorial: Develop an App with the Odoo Framework

  • 1.
  • 3. — Classy Cool Dev Thanks Classy Cool Dev! But, how can you be so sure Odoo is the perfect choice?
  • 5. Three-tier ● Presentation Layer (Client): HTML5, JavaScript, CSS ● Application Layer (Server): Python3 ● Data Layer (Database): PostgreSQL
  • 7. Architecture ● Server and backend modules in Python ○ MVC framework
  • 8. MVC framework ● Model: Data logic ● View: UI logic ● Controller: Interface
  • 9. Architecture ● Server and backend modules in Python ○ ORM to interact with database
  • 10. ORM: Bridges the gap between python and postgreSQL. class MyAwesomeCharacter(models.Model): _name = 'my.awesome.character' name = fields.Char(string="name", required=True) friend = fields.Many2one('my.awesome.character', string='Best Friend') Model definition:
  • 12. ORM Pros ● Less SQL ● Abstracts the DB ● Advanced features (cache, security, …) ● Better SQL queries
  • 13. ORM Cons ● Performance (?) ● Training ● Initial config ● Less deep understanding
  • 14. The Feature Manage a plant nursery: ● List of plants ● Manage orders ● Keep a customers list
  • 15. Technically you will learn: ● Structure of a module ● Definition of data models ● Definition of views and menus
  • 16. An Odoo module is: ● A manifest file ● Python code (models, logic) ● Data files, XML and CSV (base data, views, menus) ● Frontend resources (Javascript, CSS)
  • 17. Plant Nursery The manifest file: __manifest__.py # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. { 'name': 'Plant Nursery', 'version': '1.0', 'category': 'Tools', 'summary': 'Plants and customers management', 'depends': ['web'], 'data': [ 'security/ir.model.access.csv', 'data/data.xml', 'views/views.xml', ], 'demo': [ 'data/demo.xml', ], 'css': [], 'installable': True, 'auto_install': False, 'application': True, }
  • 18. Describe the models plant_nursery/models.p y from odoo import fields, models class Plants(models.Model): _name = 'nursery.plant' name = fields.Char("Plant Name") price = fields.Float() class Customer(models.Model): _name = 'nursery.customer' name = fields.Char("Customer Name", required=True) email = fields.Char(help="To receive the newsletter")
  • 20. Define the action <?xml version="1.0" encoding="UTF-8"?> <odoo> <record model="ir.actions.act_window" id="action_nursery_plant"> <field name="name">Plants</field> <field name="res_model">nursery.plant</field> <field name="view_mode">tree,form</field> </record> <menuitem name="Plant Nursery" id="nursery_root_menu" web_icon="plant_nursery,static/description/icon.png"/ > <menuitem name="Plants" id="nursery_plant_menu" parent="nursery_root_menu" action="action_nursery_plant" sequence="1"/> </odoo> plant_nursery/views/nursery_views.xml
  • 21.
  • 22. Define a form view plant_nursery/views/nursery_views.xml <record model="ir.ui.view" id="nursery_plant_view_form"> <field name="name">nursery.plant.view.form</field> <field name="model">nursery.plant</field> <field name="arch" type="xml"> <form string="Plant"> <sheet> <h1> <field name="name" placeholder="Plant Name"/> </h1> <notebook> <page string="Shop"> <group> <field name="price"/> </group> </page> </notebook> </sheet> </form> </field> </record>
  • 25. Relations class Order(models.Model): _name = 'nursery.order' plant_id = fields.Many2one("nursery.plant", required=True) customer_id = fields.Many2one("nursery.customer") class Plants(models.Model): _name = 'nursery.plant' order_ids = fields.One2many("nursery.order", "plant_id", string="Orders")
  • 27. Basic Operations: ● Read ● Write ● Create ● Unlink ● Search
  • 28. ORM Interactions class Order(models.Model): _name = 'nursery.order' name = fields.Datetime(default=fields.Datetime.now) plant_id = fields.Many2one("nursery.plant", required=True) customer_id = fields.Many2one("nursery.customer") state = fields.Selection([ ('draft', 'Draft'), ('confirm', 'Confirmed'), ('cancel', 'Canceled') ], default='draft') last_modification = fields.Datetime(readonly=True)
  • 29. ORM Interactionsclass Order(model.Models): _name = 'nursery.order' def write(self, values): # helper to "YYYY-MM-DD" values['last_modification'] = fields.Datetime.now() return super(Order, self).write(values) def unlink(self): # self is a recordset for order in self: if order.state == 'confirm': raise UserError("You can not delete confirmed orders") return super(Order, self).unlink()
  • 30. ORM Interactions <record model="ir.ui.view" id="nursery_order_form"> <field name="name">Order Form View</field> <field name="model">nursery.order</field> <field name="arch" type="xml"> <form string="Plant Order"> <header> <field name="state" widget="statusbar" options="{'clickable': '1'}"/> </header> <sheet> <group col="4"> <group colspan="2"> <field name="plant_id" /> <field name="customer_id" /> </group> <group colspan="2"> <field name="last_modification" /> </group> </group> </sheet> </form> </field> </record>
  • 32. — Classy Cool Dev Thanks Classy Cool Dev! What else could you show us?
  • 33. Computed Fields: ● For complex values ● Trigger for recompute ● Stored or not in the database
  • 34. Computed Fields class Plants(models.Model): _name = 'nursery.plant' order_count = fields.Integer(compute='_compute_order_count', store=True, string="Total sold") @api.depends('order_ids') def _compute_order_count(self): for plant in self: plant.order_count = len(plant.order_ids)
  • 35. Model Constraints ● Triggered after every creation or modification. ● Instead of overriding create & write
  • 36. Model Constraints class Plants(models.Model): _name = 'nursery.plant' number_in_stock = fields.Integer() @api.constrains('order_count', 'number_in_stock') def _check_available_in_stock(self): for plant in self: if plant.number_in_stock and plant.order_count > plant.number_in_stock: raise UserError("There is only %s %s in stock but %s were sold" % (plant.number_in_stock, plant.name, plant.order_count))
  • 37. Kanban View: ● Display information ● Add pictures ● Aggregated view
  • 38. Define a Kanban View: class Plants(models.Model): _name = 'nursery.plant' image = fields.Binary("Plant Image", attachment=True) <record model="ir.actions.act_window" id="action_nursery_order"> <field name="name">Orders</field> <field name="res_model">nursery.order</field> <field name="view_mode">kanban,tree,form</field> </record>
  • 39. <record id="nursery_plant_view_kanban" model="ir.ui.view"> <field name="name">nursery.plant.view.kanban</field> <field name="model">nursery.plant</field> <field name="arch" type="xml"> <kanban> <field name="id"/> <field name="image"/> <templates> <t t-name="kanban-box"> <div class="oe_kanban_global_click"> <div class="o_kanban_image"> <img t-att-src="kanban_image('nursery.plant', 'image', record.id.raw_value)"/> </div> <div class="oe_kanban_details"> <strong class="o_kanban_record_title"><field name="name"/></strong> <ul><li><strong>Price: <field name="price"></field></strong></li</ul> </div> </div> </t> </templates> </kanban> </field> </record> Define a Kanban View:
  • 42. Define a Search View: <record id="nursery_order_view_search" model="ir.ui.view"> <field name="name">nursery.order.view.search</field> <field name="model">nursery.order</field> <field name="arch" type="xml"> <search string="Search Orders"> <field name="plant_id" string="Plant"/> <field name="customer_id" string="Customer"/> <field name="state"/> <filter string="Confirmed" name="confirmed" domain="[('state', '=', 'confirm')]"/> <separator /> <group expand="0" string="Group By"> <filter string="State" name="group_by_state" domain="[]" context="{'group_by':'state'}"/> </group> </search> </field> </record>
  • 43. Display all the states class Order(models.Model): _name = 'nursery.order' state = fields.Selection([ ('draft', 'Draft'), ('confirm', 'Confirmed'), ('cancel', 'Canceled') ], default='draft', group_expand="_expand_states") def _expand_states(self, states, domain, order): return [key for key, val in type(self).state.selection]
  • 44. Always group by state: <record model="ir.actions.act_window" id="action_nursery_order"> <field name="name">Orders</field> <field name="res_model">nursery.order</field> <field name="view_mode">kanban,tree,form</field> <field name="context">{'search_default_group_by_state': 1}</field> </record>
  • 46. Onchange methods: class Customer(models.Model): _name = 'nursery.customer' _description = 'Nursery Customer' name = fields.Char('Customer Name', required=True) email = fields.Char(help="To receive the newsletter") mobile = fields.Char('Mobile') image = fields.Binary('Photo', attachment=True) address = fields.Char('Address') country_id = fields.Many2one('res.country', string='Country') partner_id = fields.Many2one('res.partner', string='Customer Address')
  • 47. Onchange methods: @api.onchange('partner_id') def _onchange_partner_id(self): if self.partner_id: if self.partner_id.image_1920: self.image = self.partner_id.image_1920 if self.partner_id.email: self.email = self.partner_id.email if self.partner_id.mobile: self.mobile = self.partner_id.mobile if self.partner_id.country_id: self.country_id = self.partner_id.country_id.id if not self.address: self.address = self.partner_id.with_context(show_address_only=True)._get_name()
  • 49. Sequences <!-- Sequences for plant.orders --> <record id="seq_plant_order" model="ir.sequence"> <field name="name">Plant Orders</field> <field name="code">plant.order</field> <field name="prefix">Order</field> <field name="padding">3</field> <field name="company_id" eval="False"/> </record>
  • 50. Sequences @api.model def create(self, vals): if vals.get('name', _('New')) == _('New'): if 'company_id' in vals: vals['name'] = self.env['ir.sequence'].with_context( force_company=vals['company_id'] ).next_by_code('plant.order') or _('New') else: vals['name'] = self.env['ir.sequence'].next_by_code('plant.order') or _('New') return super(Order, self).create(vals)
  • 51.