SlideShare a Scribd company logo
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

PDF
Solr's Search Relevancy (Understand Solr's query debug)
PPTX
Devoxx 2012 hibernate envers
PDF
Day 8: Dealing with Lists and ListViews
PDF
50 Laravel Tricks in 50 Minutes
PDF
Advanced Django
PDF
Oracle helpdesk database shema
PDF
Class-based views with Django
PPTX
Open Hack NYC Yahoo Social SDKs
Solr's Search Relevancy (Understand Solr's query debug)
Devoxx 2012 hibernate envers
Day 8: Dealing with Lists and ListViews
50 Laravel Tricks in 50 Minutes
Advanced Django
Oracle helpdesk database shema
Class-based views with Django
Open Hack NYC Yahoo Social SDKs

What's hot (20)

ODP
Test du futur avec Spock
PPTX
Mysql python
PDF
Mysql python
PDF
Django tutorial 2009
PDF
Rapid Prototyping with Solr
PDF
Introduction to SQLAlchemy ORM
PPTX
Django: Advanced Models
PDF
Phactory
PDF
Ajax nested form and ajax upload in rails
PDF
SegapRESTAPI1.0 specifications
DOCX
Sql full tutorial
PPTX
Django in the Office: Get Your Admin for Nothing and Your SQL for Free
PDF
Dig Deeper into WordPress - WD Meetup Cairo
PPT
Django Forms: Best Practices, Tips, Tricks
PPTX
Jsoup Tutorial for Beginners - Javatpoint
PDF
Django tutorial
PDF
Who's afraid of ML -V2- Hello MLKit
PDF
PofEAA and SQLAlchemy
PDF
Quebec pdo
PPT
displaytag
Test du futur avec Spock
Mysql python
Mysql python
Django tutorial 2009
Rapid Prototyping with Solr
Introduction to SQLAlchemy ORM
Django: Advanced Models
Phactory
Ajax nested form and ajax upload in rails
SegapRESTAPI1.0 specifications
Sql full tutorial
Django in the Office: Get Your Admin for Nothing and Your SQL for Free
Dig Deeper into WordPress - WD Meetup Cairo
Django Forms: Best Practices, Tips, Tricks
Jsoup Tutorial for Beginners - Javatpoint
Django tutorial
Who's afraid of ML -V2- Hello MLKit
PofEAA and SQLAlchemy
Quebec pdo
displaytag
Ad

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

PDF
OpenERP Technical Memento V0.7.3
PDF
Open Source RAD with OpenERP 7.0
PDF
Functional training day1
PDF
Presentation of the new OpenERP API. Raphael Collet, OpenERP
PPTX
Open erp
PDF
Open erp technical_memento_v0.6.3_a4
PDF
OpenERP Technical Memento
PDF
OpenERP Partnership Program - OpenERP Enterprise
PDF
OpenERP Functional Training Day2
PDF
OpenERP data integration in an entreprise context: a war story
PDF
OpenERP Functional Memento
PPT
Openerp rise
PDF
OpenERP R&D
PDF
OpenERP and Perl
PPTX
Build restful ap is with python and flask
PDF
OpenERP Training with Apagen Solutions
PDF
Openerp Rise Web
PDF
Training Program
PDF
3 openerp hr-book.complete
PDF
OpenERP Technical Memento V0.7.3
Open Source RAD with OpenERP 7.0
Functional training day1
Presentation of the new OpenERP API. Raphael Collet, OpenERP
Open erp
Open erp technical_memento_v0.6.3_a4
OpenERP Technical Memento
OpenERP Partnership Program - OpenERP Enterprise
OpenERP Functional Training Day2
OpenERP data integration in an entreprise context: a war story
OpenERP Functional Memento
Openerp rise
OpenERP R&D
OpenERP and Perl
Build restful ap is with python and flask
OpenERP Training with Apagen Solutions
Openerp Rise Web
Training Program
3 openerp hr-book.complete
Ad

More from raimonesteve (15)

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

Connecting your Python App to OpenERP through OOOP