Connecting your Python App    to OpenERP through OOOP                             Raimon Esteve                           ...
ERPEnterprise Resource PlanningManagement / organization of our company              All company:               Customer  ...
OpenERP           ERP application client­server  Official modules: product, sale, account, stock,..Extra modules: see addo...
Client / GTK
Launchpad Tool develop: code, bug, translations, blueprints, etc                 Community work        OpenERP is develop ...
OpenObject
MODULE STRUCTURE. Basic
MODULE STRUCTURE. All
MODEL. Name/Inherit1.  _name = model.modelCreate a database table: model_modelExamples:res.partner = res_partnerres.partne...
MODEL. Fields1.  _columns = {2.     name: fields.char(Name, size=100, required=True),3.     date_create: fields.date(Creat...
MODEL. Default Values   1.    _defaults = {   2.       active: lambda *a: 1,   3.       state: lambda *a: draft,   4.     ...
ORM Methods          Create    Write       Search       Browse        Unlink      …                       self.pool.get(re...
Functions1.   def _default_company(self, cr, uid, context={}):2.        user = self.pool.get(res.users).browse(cr, uid, ui...
OOOPConnecting your Python App to OpenERP through OOOP                     How to?
Connection1.  $ python2.  >>> from ooop import OOOP3.  >>> o = OOOP(user=user4, pwd=admin, dbname=user4, uri=http://localh...
All1.  $ python2.  >>> from ooop import OOOP3.  >>> o = OOOP(dbname=demo)4.  >>> partners = o.ResPartner.all()5.  >>> prin...
Get      1.  $ python      2.  >>> from ooop import OOOP      3.  >>> o = OOOP(dbname=demo)      4.  >>> n = o.ResPartner....
Delete / Deleting multiple records          1.  $ python          2.  >>> from ooop import OOOP          3.  >>> o = OOOP(...
Filtering    1.  $ python    2.  >>> from ooop import OOOP    3.  >>> o = OOOP(dbname=demo)    4.  >>> o.ResPartner.filter...
New  1.  $ python  2.  >>> from ooop import OOOP  3.  >>> o = OOOP(dbname=demo)  4.  >>> n = o.ResPartner.new()  5.  >>> n...
New with related objects. Part I        1.  $ python        2.  >>> from ooop import OOOP        3.  >>> o = OOOP(dbname=d...
New with related objects. Part II  1.  $ python  2.  >>> from ooop import OOOP  3.  >>> o = OOOP(dbname=demo)  4.  >>> m =...
www               OpenERP            www.openerp.com            www.openerp.cat                    OOOP      https://githu...
Upcoming SlideShare
Loading in …5
×

Connecting your Python App to OpenERP through OOOP

4,844 views
4,643 views

Published on

Presentation OpenERP and OOOP API

0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
4,844
On SlideShare
0
From Embeds
0
Number of Embeds
345
Actions
Shares
0
Downloads
291
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Connecting your Python App to OpenERP through OOOP

  1. 1. Connecting your Python App to OpenERP through OOOP Raimon Esteve January 2011 Licence Creative Commons: Attribution-NonCommercial 3.0 Unported (CC BY-NC 3.0More 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 mustattribute the work in the manner specified by the author or licensor (but not in any way that suggests that theyendorse 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.
  2. 2. ERPEnterprise Resource PlanningManagement / organization of our company All company: Customer Account Sale … Custom management
  3. 3. 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
  4. 4. Client / GTK
  5. 5. 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!
  6. 6. OpenObject
  7. 7. MODULE STRUCTURE. Basic
  8. 8. MODULE STRUCTURE. All
  9. 9. MODEL. Name/Inherit1.  _name = model.modelCreate a database table: model_modelExamples:res.partner = res_partnerres.partner.address = res_partner_addressproduct.product = product_product2.  _inherit = res,partner­ Add more fields or functions in other model exist.­ Change functions or fields defined by other modules.
  10. 10. MODEL. Fields1.  _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.}
  11. 11. 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.    }
  12. 12. 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)
  13. 13. Functions1.   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.id5.        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.    }
  14. 14. OOOPConnecting your Python App to OpenERP through OOOP How to?
  15. 15. Connection1.  $ python2.  >>> from ooop import OOOP3.  >>> o = OOOP(user=user4, pwd=admin, dbname=user4, uri=http://localhost, port=8070)4.  >>> from ooop import OOOP5.  >>> o = OOOP(dbname=demo)  # Default values
  16. 16. All1.  $ python2.  >>> from ooop import OOOP3.  >>> o = OOOP(dbname=demo)4.  >>> partners = o.ResPartner.all()5.  >>> print partners[0]6.  <res.partner:2 nou partner> data instance7.  >>> print partners[0].name8.  Zikzakmedia OpenObject      |      OOOP res.partner               |      ResPartner
  17. 17. 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
  18. 18. 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()
  19. 19. 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])
  20. 20. 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()
  21. 21. 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()
  22. 22. 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()
  23. 23. www OpenERP www.openerp.com www.openerp.cat OOOP https://github.com/lasarux/ooop Launchpad https://launchpad.net/openobject

×