SlideShare a Scribd company logo
1 of 23
Download to read offline
Connecting your Python App
    to OpenERP through OOOP

                             Raimon Esteve
                                         January 2011
                  Licence Creative Commons: Attribution-NonCommercial 3.0 Unported (CC BY-NC 3.0
More information to http://creativecommons.org/licenses/by-nc/3.0/
To Share — to copy, distribute and transmit the work. To Remix — to adapt the work. Attribution — You must
attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they
endorse you or your use of the work). Noncommercial — You may not use this work for commercial purposes.
Logos are OpenERP S.A and OOOP project.
ERP
Enterprise Resource Planning
Management / organization of our company

              All company:
               Customer
                 Account
                   Sale
                    …
          Custom management
OpenERP
           ERP application client­server
  Official modules: product, sale, account, stock,..
Extra modules: see addons­extra, addons­community 
            or other projects in Launchpad



               OpenObject
            Framework written by python
Client / GTK
Launchpad
 Tool develop: code, bug, translations, blueprints, etc
                 Community work

        OpenERP is develop community users 
          (behind this users are entreprises)

Other applications: MySQL, Ubuntu.... to 20241 projects!
OpenObject
MODULE STRUCTURE. Basic
MODULE STRUCTURE. All
MODEL. Name/Inherit


1.  _name = 'model.model'

Create a database table: model_model

Examples:
res.partner = res_partner
res.partner.address = res_partner_address
product.product = product_product

2.  _inherit = 'res,partner'

­ Add more fields or functions in other model exist.
­ Change functions or fields defined by other modules.
MODEL. Fields


1.  _columns = {
2.     'name': fields.char('Name', size=100, required=True),
3.     'date_create': fields.date('Create', required=True),
4.     'date_expire': fields.function(_date_expire_days_get, method=True, 
type="date", string="Date expired"),
5.     'partner_id': fields.many2one('res.partner', 'Partner', required=True),
6.     'active': fields.boolean('Active'),
7.     'field_ids': fields.one2many('model.other', 'model_id', string='Field'),
8.     'prod_ids':
            fields.many2many('product.product','model_mod_rel','model_id',
            'product_id','Products'),
9.}
MODEL. Default Values




   1.    _defaults = {
   2.       'active': lambda *a: 1,
   3.       'state': lambda *a: 'draft',
   4.       'company_id': _default_company,
   5.       'date': lambda *a:time.strftime('%Y­%m­%d'),
   6.    }
ORM Methods


          Create    Write       Search       Browse        Unlink      …

                       self.pool.get('res.users') + ORM()




1.  self.pool.get('res.users').browse(cr, uid, id, context=context)
2.  self.pool.get('res.company').search(cr, uid, [('parent_id', '=', False)])
3.  self.pool.get('res.partner').create(cr, uid, {'name' : 'Zikzakmedia'} )
4.  self.pool.get('res.partner').unlink(cr, uid, ids, context=context)
Functions


1.   def _default_company(self, cr, uid, context={}):
2.        user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
3.        if user.company_id:
4.            return user.company_id.id
5.        return self.pool.get('res.company').search(cr, uid, [('parent_id', '=', 
False)])[0]


6.    _defaults = {
7.        'active': lambda *a: 1,
8.        'company_id': _default_company,
9.    }
OOOP
Connecting your Python App to OpenERP through OOOP

                     How to?
Connection




1.  $ python
2.  >>> from ooop import OOOP
3.  >>> o = OOOP(user='user4', pwd='admin', dbname='user4', 
uri='http://localhost', port=8070)

4.  >>> from ooop import OOOP
5.  >>> o = OOOP(dbname='demo')  # Default values
All


1.  $ python
2.  >>> from ooop import OOOP
3.  >>> o = OOOP(dbname='demo')

4.  >>> partners = o.ResPartner.all()
5.  >>> print partners[0]
6.  <res.partner:2 'nou partner'> data instance

7.  >>> print partners[0].name
8.  Zikzakmedia


                 OpenObject      |      OOOP
             res.partner               |      ResPartner
Get


      1.  $ python
      2.  >>> from ooop import OOOP
      3.  >>> o = OOOP(dbname='demo')

      4.  >>> n = o.ResPartner.get(1)
      6.  >>> print n.name
      7.  Zikzakmedia

      8.  >>> print n.country.name # country: many2one field
      9.  Spain

      10.  >>> print n.country.id
      11.  67
Delete / Deleting multiple records


          1.  $ python
          2.  >>> from ooop import OOOP
          3.  >>> o = OOOP(dbname='demo')

          4.  >>> n = o.ResPartner.get(1)
          6.  >>> n.delete()

          1.  $ python
          2.  >>> from ooop import OOOP
          3.  >>> o = OOOP(dbname='demo')

          4.  >>> n = o.ResPartner.all()
          6.  >>> n[1:100].delete()
Filtering

    1.  $ python
    2.  >>> from ooop import OOOP
    3.  >>> o = OOOP(dbname='demo')

    4.  >>> o.ResPartner.filter(name='Zikzakmedia')
    5.  >>> o.ResPartner.filter(name__ne='Zikzakmedia')
    6.  >>> o.ResPartner.filter(name__lt='Zikzakmedia')
    7.  >>> o.ResPartner.filter(name__lte='Zikzakmedia')
    8.  >>> o.ResPartner.filter(name__gt='Zikzakmedia')
    9.  >>> o.ResPartner.filter(name_gte='Zikzakmedia')
    10.  >>> o.ResPartner.filter(name__like='Zikzakmedia')
    11.  >>> o.ResPartner.filter(name_ilike='Zikzakmedia')
    12.  >>> o.ResPartner.filter(id_in=[1,2,5,7])
    13.  >>> o.ResPartner.filter(id_not_in=[1,2,5,7])
New

  1.  $ python
  2.  >>> from ooop import OOOP
  3.  >>> o = OOOP(dbname='demo')

  4.  >>> n = o.ResPartner.new()
  5.  >>> n.name = 'Partner created with OOOP'
  5.  >>> n.save()

  1.  $ python
  2.  >>> from ooop import OOOP

  3.  >>> o = OOOP(dbname='demo')
  4.  >>> n = o.ResPartner.new(name='Zikzakmedia', active=True)
  6.  >>> n.save()
New with related objects. Part I



        1.  $ python
        2.  >>> from ooop import OOOP
        3.  >>> o = OOOP(dbname='demo')

        4.  >>> n = o.ResPartner.new()
        5.  >>> n.name = 'Partner created with OOOP'

        6.  >>> addr = o.ResPartnerAddress.new()
        7.  >>> addr.street = 'New Address'

        8.  >>> n.address.append(addr)
        9.  >>> n.save_all()
New with related objects. Part II



  1.  $ python
  2.  >>> from ooop import OOOP
  3.  >>> o = OOOP(dbname='demo')

  4.  >>> m = [o.ResPartnerAddress.new(name='New Address', 
  street='New Street', active=True)]
  5.  >>> n = o.ResPartner.new(name='Zikzakmedia', address=m, 
  active=True)

  6.  >>> n.save_all()
www




               OpenERP
            www.openerp.com
            www.openerp.cat

                    OOOP
      https://github.com/lasarux/ooop

                 Launchpad
      https://launchpad.net/openobject

More Related Content

What's hot

Test du futur avec Spock
Test du futur avec SpockTest du futur avec Spock
Test du futur avec SpockCARA_Lyon
 
Django tutorial 2009
Django tutorial 2009Django tutorial 2009
Django tutorial 2009Ferenc Szalai
 
Rapid Prototyping with Solr
Rapid Prototyping with SolrRapid Prototyping with Solr
Rapid Prototyping with SolrErik Hatcher
 
Introduction to SQLAlchemy ORM
Introduction to SQLAlchemy ORMIntroduction to SQLAlchemy ORM
Introduction to SQLAlchemy ORMJason Myers
 
Django: Advanced Models
Django: Advanced ModelsDjango: Advanced Models
Django: Advanced ModelsYing-An Lai
 
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 in the Office: Get Your Admin for Nothing and Your SQL for Free
Django in the Office: Get Your Admin for Nothing and Your SQL for FreeDjango in the Office: Get Your Admin for Nothing and Your SQL for Free
Django in the Office: Get Your Admin for Nothing and Your SQL for FreeHarvard Web Working Group
 
Dig Deeper into WordPress - WD Meetup Cairo
Dig Deeper into WordPress - WD Meetup CairoDig Deeper into WordPress - WD Meetup Cairo
Dig Deeper into WordPress - WD Meetup CairoMohamed Mosaad
 
Django Forms: Best Practices, Tips, Tricks
Django Forms: Best Practices, Tips, TricksDjango Forms: Best Practices, Tips, Tricks
Django Forms: Best Practices, Tips, TricksShawn Rider
 
Jsoup Tutorial for Beginners - Javatpoint
Jsoup Tutorial for Beginners - JavatpointJsoup Tutorial for Beginners - Javatpoint
Jsoup Tutorial for Beginners - JavatpointJavaTpoint.Com
 
Django tutorial
Django tutorialDjango tutorial
Django tutorialKsd Che
 
Who's afraid of ML -V2- Hello MLKit
Who's afraid of ML -V2- Hello MLKitWho's afraid of ML -V2- Hello MLKit
Who's afraid of ML -V2- Hello MLKitBritt Barak (HIRING)
 
PofEAA and SQLAlchemy
PofEAA and SQLAlchemyPofEAA and SQLAlchemy
PofEAA and SQLAlchemyInada Naoki
 

What's hot (20)

Test du futur avec Spock
Test du futur avec SpockTest du futur avec Spock
Test du futur avec Spock
 
Mysql python
Mysql pythonMysql python
Mysql python
 
Mysql python
Mysql pythonMysql python
Mysql python
 
Django tutorial 2009
Django tutorial 2009Django tutorial 2009
Django tutorial 2009
 
Rapid Prototyping with Solr
Rapid Prototyping with SolrRapid Prototyping with Solr
Rapid Prototyping with Solr
 
Introduction to SQLAlchemy ORM
Introduction to SQLAlchemy ORMIntroduction to SQLAlchemy ORM
Introduction to SQLAlchemy ORM
 
Django: Advanced Models
Django: Advanced ModelsDjango: Advanced Models
Django: Advanced Models
 
Phactory
PhactoryPhactory
Phactory
 
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
 
SegapRESTAPI1.0 specifications
SegapRESTAPI1.0 specificationsSegapRESTAPI1.0 specifications
SegapRESTAPI1.0 specifications
 
Sql full tutorial
Sql full tutorialSql full tutorial
Sql full tutorial
 
Django in the Office: Get Your Admin for Nothing and Your SQL for Free
Django in the Office: Get Your Admin for Nothing and Your SQL for FreeDjango in the Office: Get Your Admin for Nothing and Your SQL for Free
Django in the Office: Get Your Admin for Nothing and Your SQL for Free
 
Dig Deeper into WordPress - WD Meetup Cairo
Dig Deeper into WordPress - WD Meetup CairoDig Deeper into WordPress - WD Meetup Cairo
Dig Deeper into WordPress - WD Meetup Cairo
 
Django Forms: Best Practices, Tips, Tricks
Django Forms: Best Practices, Tips, TricksDjango Forms: Best Practices, Tips, Tricks
Django Forms: Best Practices, Tips, Tricks
 
Jsoup Tutorial for Beginners - Javatpoint
Jsoup Tutorial for Beginners - JavatpointJsoup Tutorial for Beginners - Javatpoint
Jsoup Tutorial for Beginners - Javatpoint
 
Django tutorial
Django tutorialDjango tutorial
Django tutorial
 
Who's afraid of ML -V2- Hello MLKit
Who's afraid of ML -V2- Hello MLKitWho's afraid of ML -V2- Hello MLKit
Who's afraid of ML -V2- Hello MLKit
 
PofEAA and SQLAlchemy
PofEAA and SQLAlchemyPofEAA and SQLAlchemy
PofEAA and SQLAlchemy
 
Quebec pdo
Quebec pdoQuebec pdo
Quebec pdo
 
displaytag
displaytagdisplaytag
displaytag
 

Similar to Connecting your Python App to OpenERP through OOOP

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
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to DjangoJoaquim Rocha
 
Api's and ember js
Api's and ember jsApi's and ember js
Api's and ember jsEdwin Cruz
 
Build restful ap is with python and flask
Build restful ap is with python and flaskBuild restful ap is with python and flask
Build restful ap is with python and flaskJeetendra singh
 
Ben ford intro
Ben ford introBen ford intro
Ben ford introPuppet
 
Telemetry doesn't have to be scary; Ben Ford
Telemetry doesn't have to be scary; Ben FordTelemetry doesn't have to be scary; Ben Ford
Telemetry doesn't have to be scary; Ben FordPuppet
 
Googleappengineintro 110410190620-phpapp01
Googleappengineintro 110410190620-phpapp01Googleappengineintro 110410190620-phpapp01
Googleappengineintro 110410190620-phpapp01Tony Frame
 
Rapid prototyping search applications with solr
Rapid prototyping search applications with solrRapid prototyping search applications with solr
Rapid prototyping search applications with solrLucidworks (Archived)
 
Automating Performance Monitoring at Microsoft
Automating Performance Monitoring at MicrosoftAutomating Performance Monitoring at Microsoft
Automating Performance Monitoring at MicrosoftThousandEyes
 
OpenERP e l'arte della gestione aziendale con Python
OpenERP e l'arte della gestione aziendale con PythonOpenERP e l'arte della gestione aziendale con Python
OpenERP e l'arte della gestione aziendale con PythonPyCon Italia
 
Open erp technical_memento_v0.6.3_a4
Open erp technical_memento_v0.6.3_a4Open erp technical_memento_v0.6.3_a4
Open erp technical_memento_v0.6.3_a4openerpwiki
 
Dicoding Developer Coaching #20: Android | Apa itu Content Provider?
Dicoding Developer Coaching #20: Android | Apa itu Content Provider?Dicoding Developer Coaching #20: Android | Apa itu Content Provider?
Dicoding Developer Coaching #20: Android | Apa itu Content Provider?DicodingEvent
 
Zotonic tutorial EUC 2013
Zotonic tutorial EUC 2013Zotonic tutorial EUC 2013
Zotonic tutorial EUC 2013Arjan
 
Beginning Native Android Apps
Beginning Native Android AppsBeginning Native Android Apps
Beginning Native Android AppsGil Irizarry
 
Volley lab btc_bbit
Volley lab btc_bbitVolley lab btc_bbit
Volley lab btc_bbitCarWash1
 
От Rails-way к модульной архитектуре
От Rails-way к модульной архитектуреОт Rails-way к модульной архитектуре
От Rails-way к модульной архитектуреIvan Nemytchenko
 
Symfony2 Introduction Presentation
Symfony2 Introduction PresentationSymfony2 Introduction Presentation
Symfony2 Introduction PresentationNerd Tzanetopoulos
 

Similar to Connecting your Python App to OpenERP through OOOP (20)

Django
DjangoDjango
Django
 
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
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
Api's and ember js
Api's and ember jsApi's and ember js
Api's and ember js
 
Build restful ap is with python and flask
Build restful ap is with python and flaskBuild restful ap is with python and flask
Build restful ap is with python and flask
 
.Net template solution architecture
.Net template solution architecture.Net template solution architecture
.Net template solution architecture
 
Ben ford intro
Ben ford introBen ford intro
Ben ford intro
 
Telemetry doesn't have to be scary; Ben Ford
Telemetry doesn't have to be scary; Ben FordTelemetry doesn't have to be scary; Ben Ford
Telemetry doesn't have to be scary; Ben Ford
 
Googleappengineintro 110410190620-phpapp01
Googleappengineintro 110410190620-phpapp01Googleappengineintro 110410190620-phpapp01
Googleappengineintro 110410190620-phpapp01
 
Rapid prototyping search applications with solr
Rapid prototyping search applications with solrRapid prototyping search applications with solr
Rapid prototyping search applications with solr
 
Automating Performance Monitoring at Microsoft
Automating Performance Monitoring at MicrosoftAutomating Performance Monitoring at Microsoft
Automating Performance Monitoring at Microsoft
 
OpenERP e l'arte della gestione aziendale con Python
OpenERP e l'arte della gestione aziendale con PythonOpenERP e l'arte della gestione aziendale con Python
OpenERP e l'arte della gestione aziendale con Python
 
Open erp technical_memento_v0.6.3_a4
Open erp technical_memento_v0.6.3_a4Open erp technical_memento_v0.6.3_a4
Open erp technical_memento_v0.6.3_a4
 
Dicoding Developer Coaching #20: Android | Apa itu Content Provider?
Dicoding Developer Coaching #20: Android | Apa itu Content Provider?Dicoding Developer Coaching #20: Android | Apa itu Content Provider?
Dicoding Developer Coaching #20: Android | Apa itu Content Provider?
 
SOLID Ruby, SOLID Rails
SOLID Ruby, SOLID RailsSOLID Ruby, SOLID Rails
SOLID Ruby, SOLID Rails
 
Zotonic tutorial EUC 2013
Zotonic tutorial EUC 2013Zotonic tutorial EUC 2013
Zotonic tutorial EUC 2013
 
Beginning Native Android Apps
Beginning Native Android AppsBeginning Native Android Apps
Beginning Native Android Apps
 
Volley lab btc_bbit
Volley lab btc_bbitVolley lab btc_bbit
Volley lab btc_bbit
 
От Rails-way к модульной архитектуре
От Rails-way к модульной архитектуреОт Rails-way к модульной архитектуре
От Rails-way к модульной архитектуре
 
Symfony2 Introduction Presentation
Symfony2 Introduction PresentationSymfony2 Introduction Presentation
Symfony2 Introduction Presentation
 

More from raimonesteve

Tryton Point of Sale - POS
Tryton Point of Sale - POSTryton Point of Sale - POS
Tryton Point of Sale - POSraimonesteve
 
Training. Módolos para centros educativos
Training. Módolos para centros educativosTraining. Módolos para centros educativos
Training. Módolos para centros educativosraimonesteve
 
Zzsaas - OpenERP SaaS
Zzsaas - OpenERP SaaSZzsaas - OpenERP SaaS
Zzsaas - OpenERP SaaSraimonesteve
 
Zoook - Comercio electrónico de OpenERP
Zoook - Comercio electrónico de OpenERPZoook - Comercio electrónico de OpenERP
Zoook - Comercio electrónico de OpenERPraimonesteve
 
OpenERP. L'ERP lliure
OpenERP. L'ERP lliureOpenERP. L'ERP lliure
OpenERP. L'ERP lliureraimonesteve
 
Fernando Estructuras. OpenERP
Fernando Estructuras. OpenERPFernando Estructuras. OpenERP
Fernando Estructuras. OpenERPraimonesteve
 
JasperReports, informes con diseño
JasperReports, informes con diseñoJasperReports, informes con diseño
JasperReports, informes con diseñoraimonesteve
 
Poweremail, el gestor de correo de OpenERP
Poweremail, el gestor de correo de OpenERPPoweremail, el gestor de correo de OpenERP
Poweremail, el gestor de correo de OpenERPraimonesteve
 
Magento - Magquè?
Magento - Magquè?Magento - Magquè?
Magento - Magquè?raimonesteve
 
OpenErp 5 Novedades para el usuario
OpenErp 5 Novedades para el usuarioOpenErp 5 Novedades para el usuario
OpenErp 5 Novedades para el usuarioraimonesteve
 
Migración de datos con OpenERP-Kettle
Migración de datos con OpenERP-KettleMigración de datos con OpenERP-Kettle
Migración de datos con OpenERP-Kettleraimonesteve
 
Generación de informes usando Jasper Reports
Generación de informes usando Jasper ReportsGeneración de informes usando Jasper Reports
Generación de informes usando Jasper Reportsraimonesteve
 
OpenErp - osCommerce y Magento (integración)
OpenErp - osCommerce y Magento (integración)OpenErp - osCommerce y Magento (integración)
OpenErp - osCommerce y Magento (integración)raimonesteve
 
¿Openerp y CMS? RadioTV
¿Openerp y CMS? RadioTV¿Openerp y CMS? RadioTV
¿Openerp y CMS? RadioTVraimonesteve
 

More from raimonesteve (15)

Tryton Point of Sale - POS
Tryton Point of Sale - POSTryton Point of Sale - POS
Tryton Point of Sale - POS
 
Training. Módolos para centros educativos
Training. Módolos para centros educativosTraining. Módolos para centros educativos
Training. Módolos para centros educativos
 
Zzsaas - OpenERP SaaS
Zzsaas - OpenERP SaaSZzsaas - OpenERP SaaS
Zzsaas - OpenERP SaaS
 
Zoook - Comercio electrónico de OpenERP
Zoook - Comercio electrónico de OpenERPZoook - Comercio electrónico de OpenERP
Zoook - Comercio electrónico de OpenERP
 
OpenERP. L'ERP lliure
OpenERP. L'ERP lliureOpenERP. L'ERP lliure
OpenERP. L'ERP lliure
 
Fernando Estructuras. OpenERP
Fernando Estructuras. OpenERPFernando Estructuras. OpenERP
Fernando Estructuras. OpenERP
 
JasperReports, informes con diseño
JasperReports, informes con diseñoJasperReports, informes con diseño
JasperReports, informes con diseño
 
Poweremail, el gestor de correo de OpenERP
Poweremail, el gestor de correo de OpenERPPoweremail, el gestor de correo de OpenERP
Poweremail, el gestor de correo de OpenERP
 
Magento - Magquè?
Magento - Magquè?Magento - Magquè?
Magento - Magquè?
 
OpenErp 5 Novedades para el usuario
OpenErp 5 Novedades para el usuarioOpenErp 5 Novedades para el usuario
OpenErp 5 Novedades para el usuario
 
Migración de datos con OpenERP-Kettle
Migración de datos con OpenERP-KettleMigración de datos con OpenERP-Kettle
Migración de datos con OpenERP-Kettle
 
Generación de informes usando Jasper Reports
Generación de informes usando Jasper ReportsGeneración de informes usando Jasper Reports
Generación de informes usando Jasper Reports
 
¿Que es Openerp?
¿Que es Openerp?¿Que es Openerp?
¿Que es Openerp?
 
OpenErp - osCommerce y Magento (integración)
OpenErp - osCommerce y Magento (integración)OpenErp - osCommerce y Magento (integración)
OpenErp - osCommerce y Magento (integración)
 
¿Openerp y CMS? RadioTV
¿Openerp y CMS? RadioTV¿Openerp y CMS? RadioTV
¿Openerp y CMS? RadioTV
 

Connecting your Python App to OpenERP through OOOP