connecting your python app to openerp through ooop
DESCRIPTION
Presentation OpenERP and OOOP APITRANSCRIPT
![Page 1: Connecting your Python App to OpenERP through OOOP](https://reader034.vdocument.in/reader034/viewer/2022042813/54b7692d4a795957768b4667/html5/thumbnails/1.jpg)
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 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.
![Page 2: Connecting your Python App to OpenERP through OOOP](https://reader034.vdocument.in/reader034/viewer/2022042813/54b7692d4a795957768b4667/html5/thumbnails/2.jpg)
ERPEnterprise Resource Planning
Management / organization of our company
All company:CustomerAccount
Sale…
Custom management
![Page 3: Connecting your Python App to OpenERP through OOOP](https://reader034.vdocument.in/reader034/viewer/2022042813/54b7692d4a795957768b4667/html5/thumbnails/3.jpg)
ERP application clientserverOfficial modules: product, sale, account, stock,..
Extra modules: see addonsextra, addonscommunity or other projects in Launchpad
OpenERP
OpenObjectFramework written by python
![Page 4: Connecting your Python App to OpenERP through OOOP](https://reader034.vdocument.in/reader034/viewer/2022042813/54b7692d4a795957768b4667/html5/thumbnails/4.jpg)
Client / GTK
![Page 5: Connecting your Python App to OpenERP through OOOP](https://reader034.vdocument.in/reader034/viewer/2022042813/54b7692d4a795957768b4667/html5/thumbnails/5.jpg)
LaunchpadTool 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!
![Page 6: Connecting your Python App to OpenERP through OOOP](https://reader034.vdocument.in/reader034/viewer/2022042813/54b7692d4a795957768b4667/html5/thumbnails/6.jpg)
OpenObject
![Page 7: Connecting your Python App to OpenERP through OOOP](https://reader034.vdocument.in/reader034/viewer/2022042813/54b7692d4a795957768b4667/html5/thumbnails/7.jpg)
MODULE STRUCTURE. Basic
![Page 8: Connecting your Python App to OpenERP through OOOP](https://reader034.vdocument.in/reader034/viewer/2022042813/54b7692d4a795957768b4667/html5/thumbnails/8.jpg)
MODULE STRUCTURE. All
![Page 9: Connecting your Python App to OpenERP through OOOP](https://reader034.vdocument.in/reader034/viewer/2022042813/54b7692d4a795957768b4667/html5/thumbnails/9.jpg)
MODEL. Name/Inherit
1. _name = 'model.model'
Create a database table: model_model
Examples:res.partner = res_partnerres.partner.address = res_partner_addressproduct.product = product_product
2. _inherit = 'res,partner'
Add more fields or functions in other model exist. Change functions or fields defined by other modules.
![Page 10: Connecting your Python App to OpenERP through OOOP](https://reader034.vdocument.in/reader034/viewer/2022042813/54b7692d4a795957768b4667/html5/thumbnails/10.jpg)
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.}
![Page 11: Connecting your Python App to OpenERP through OOOP](https://reader034.vdocument.in/reader034/viewer/2022042813/54b7692d4a795957768b4667/html5/thumbnails/11.jpg)
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. }
![Page 12: Connecting your Python App to OpenERP through OOOP](https://reader034.vdocument.in/reader034/viewer/2022042813/54b7692d4a795957768b4667/html5/thumbnails/12.jpg)
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)
ORM Methods
![Page 13: Connecting your Python App to OpenERP through OOOP](https://reader034.vdocument.in/reader034/viewer/2022042813/54b7692d4a795957768b4667/html5/thumbnails/13.jpg)
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.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. }
![Page 14: Connecting your Python App to OpenERP through OOOP](https://reader034.vdocument.in/reader034/viewer/2022042813/54b7692d4a795957768b4667/html5/thumbnails/14.jpg)
OOOP
Connecting your Python App to OpenERP through OOOP
How to?
![Page 15: Connecting your Python App to OpenERP through OOOP](https://reader034.vdocument.in/reader034/viewer/2022042813/54b7692d4a795957768b4667/html5/thumbnails/15.jpg)
Connection
1. $ 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
![Page 16: Connecting your Python App to OpenERP through OOOP](https://reader034.vdocument.in/reader034/viewer/2022042813/54b7692d4a795957768b4667/html5/thumbnails/16.jpg)
All
1. $ 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 instance
7. >>> print partners[0].name8. Zikzakmedia
OpenObject | OOOPres.partner | ResPartner
![Page 17: Connecting your Python App to OpenERP through OOOP](https://reader034.vdocument.in/reader034/viewer/2022042813/54b7692d4a795957768b4667/html5/thumbnails/17.jpg)
Get
1. $ python2. >>> from ooop import OOOP3. >>> o = OOOP(dbname='demo')
4. >>> n = o.ResPartner.get(1)6. >>> print n.name7. Zikzakmedia
8. >>> print n.country.name # country: many2one field9. Spain
10. >>> print n.country.id11. 67
![Page 18: Connecting your Python App to OpenERP through OOOP](https://reader034.vdocument.in/reader034/viewer/2022042813/54b7692d4a795957768b4667/html5/thumbnails/18.jpg)
Delete / Deleting multiple records
1. $ python2. >>> from ooop import OOOP3. >>> o = OOOP(dbname='demo')
4. >>> n = o.ResPartner.get(1)6. >>> n.delete()
1. $ python2. >>> from ooop import OOOP3. >>> o = OOOP(dbname='demo')
4. >>> n = o.ResPartner.all()6. >>> n[1:100].delete()
![Page 19: Connecting your Python App to OpenERP through OOOP](https://reader034.vdocument.in/reader034/viewer/2022042813/54b7692d4a795957768b4667/html5/thumbnails/19.jpg)
Filtering
1. $ python2. >>> from ooop import OOOP3. >>> 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])
![Page 20: Connecting your Python App to OpenERP through OOOP](https://reader034.vdocument.in/reader034/viewer/2022042813/54b7692d4a795957768b4667/html5/thumbnails/20.jpg)
New
1. $ python2. >>> from ooop import OOOP
3. >>> o = OOOP(dbname='demo')4. >>> n = o.ResPartner.new(name='Zikzakmedia', active=True)6. >>> n.save()
New
1. $ python2. >>> from ooop import OOOP3. >>> o = OOOP(dbname='demo')
4. >>> n = o.ResPartner.new()5. >>> n.name = 'Partner created with OOOP'5. >>> n.save()
![Page 21: Connecting your Python App to OpenERP through OOOP](https://reader034.vdocument.in/reader034/viewer/2022042813/54b7692d4a795957768b4667/html5/thumbnails/21.jpg)
New with related objects. Part I
1. $ python2. >>> from ooop import OOOP3. >>> 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()
![Page 22: Connecting your Python App to OpenERP through OOOP](https://reader034.vdocument.in/reader034/viewer/2022042813/54b7692d4a795957768b4667/html5/thumbnails/22.jpg)
New with related objects. Part II
1. $ python2. >>> from ooop import OOOP3. >>> 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()
![Page 23: Connecting your Python App to OpenERP through OOOP](https://reader034.vdocument.in/reader034/viewer/2022042813/54b7692d4a795957768b4667/html5/thumbnails/23.jpg)
www
OpenERPwww.openerp.comwww.openerp.cat
OOOPhttps://github.com/lasarux/ooop
Launchpadhttps://launchpad.net/openobject