odoo connector (formerly openerp connector)

42
OpenERP / odoo Connector OpenDays 2014 Guewen Baconnier / Alexandre Fayolle

Upload: camptocamp

Post on 10-May-2015

981 views

Category:

Business


9 download

DESCRIPTION

30 seconds to say... ■ Documentation: http://www.openerp-connector.com ■ Mailing list: https://launchpad.net/~openerp-connector-community

TRANSCRIPT

Page 1: Odoo Connector (formerly OpenERP Connector)

OpenERP / odoo Connector

OpenDays 2014Guewen Baconnier / Alexandre Fayolle

Page 2: Odoo Connector (formerly OpenERP Connector)

2/42www.camptocamp.com /

30 seconds to say...

■ Documentation: http://www.openerp-connector.com

■ Mailing list: https://launchpad.net/~openerp-connector-community

Page 3: Odoo Connector (formerly OpenERP Connector)

3/42www.camptocamp.com /

What is a connector?

■ Connect odoo with external systems

■ Exchange any data between them

Page 4: Odoo Connector (formerly OpenERP Connector)

4/42www.camptocamp.com /

What is not the connector?

■ A middleware, it is a module inside odoo

■ It does not listen external systems, it speaks to them

Page 5: Odoo Connector (formerly OpenERP Connector)

5/42www.camptocamp.com /

A framework

Does not do anything “out of the box”, rather:

■ Suggests an implementation style

■ Proposes bare “interface” classes

■ Defines bricks○ Jobs

○ Events

○ Backend / version mechanisms

Page 6: Odoo Connector (formerly OpenERP Connector)

6/42www.camptocamp.com /

Glossary

■ Backend

■ Event

■ Job / jobs queue

■ Worker

■ Binding

Page 7: Odoo Connector (formerly OpenERP Connector)

7/42www.camptocamp.com /

Existing implementations

■ Magento

■ Prestashop

■ Multicompany (odoo to odoo)

■ Solr

■ CMIS

■ Connector E-Commerce (not a full implementation)

See http://openerp-connector.com/ for links!

Page 8: Odoo Connector (formerly OpenERP Connector)

8/42www.camptocamp.com /

Find the doc

■ http://www.openerp-connector.com

■ Have a look at http://www.openerp-magento-connector.com(reference implementation, lots of great examples)

■ Source code itself.

Page 9: Odoo Connector (formerly OpenERP Connector)

9/42www.camptocamp.com /

Mailing List

■ Join the team on https://launchpad.net/~openerp-connector-community

■ Shared for discussions about the connector and all the different implementations

Page 10: Odoo Connector (formerly OpenERP Connector)

10/42www.camptocamp.com /

How to install

■ Just like any other add-on!

■ Grab the source code

bzr branch lp:openerp-connector/7.0

■ Add to --addons-path

■ Install in odoo like any other add-on

Page 11: Odoo Connector (formerly OpenERP Connector)

11/42www.camptocamp.com /

Multiprocessing and Workers

■ One odoo process: all is fine

■ Several processes: at least one independent process must be launched for the processing of the jobs queue○ Tip: use the provided openerp-connector-worker

script

http://openerp-connector.com/guides/multiprocessing.html

Page 12: Odoo Connector (formerly OpenERP Connector)

12/42www.camptocamp.com /

Multiple databases and Workers

■ Supported!

Gotcha:

■ Only runs on databases that are ○ in the option database in the command line

○ or db_name in the configuration file

○ if nothing is provided, will run on all databases

Page 13: Odoo Connector (formerly OpenERP Connector)

13/42www.camptocamp.com /

Design goals – Overview

■ Do not impose a way of using the framework to the developer, only strong advices

■ Propose bits of implementation, which can be used or not, and the developer can cherry pick

■ The developer is in charge of choosing her path through the code, the code does not choose it for her

■ Do not mix everything in Model objects

Page 14: Odoo Connector (formerly OpenERP Connector)

14/42www.camptocamp.com /

Design goals - Events

■ Declare an event only once

■ Consume it several times○ → several actions can be triggered

■ Different connectors can share events

Page 15: Odoo Connector (formerly OpenERP Connector)

15/42www.camptocamp.com /

Code example: Events

Page 16: Odoo Connector (formerly OpenERP Connector)

16/42www.camptocamp.com /

Design goals - Jobs

■ Reliable

■ No batches!

■ Run in the background in a separate process

■ Overview of what is running, failing, waiting.

Page 17: Odoo Connector (formerly OpenERP Connector)

17/42www.camptocamp.com /

Overview - Jobs

Page 18: Odoo Connector (formerly OpenERP Connector)

18/42www.camptocamp.com /

Code example: Jobs

Page 19: Odoo Connector (formerly OpenERP Connector)

19/42www.camptocamp.com /

Design goals - Backends

■ Different behaviors across versions of a backend (Magento 1.7 or 2.0, or a customized Magento version...)

■ Extensible

Page 20: Odoo Connector (formerly OpenERP Connector)

20/42www.camptocamp.com /

Overview - Backends

Page 21: Odoo Connector (formerly OpenERP Connector)

21/42www.camptocamp.com /

Code example: Backends

Page 22: Odoo Connector (formerly OpenERP Connector)

22/42www.camptocamp.com /

Code example: Backends

Page 23: Odoo Connector (formerly OpenERP Connector)

23/42www.camptocamp.com /

The glue: Environment and ConnectorSession■ Environment is the current working context:

○ Model

○ Backend (with version)

○ ConnectorSession

■ ConnectorSession is a container for:○ Cursor

○ User

○ Context

Page 24: Odoo Connector (formerly OpenERP Connector)

24/42www.camptocamp.com /

Design goals – Binding records

■ Store the external / odoo couples of IDs○ Plus synchronization date

○ And possibly extra data related only to this record and this backend

■ If several backends are possible (e.g. Magento):

→ _inherits on the model

■ If only one backend possible (e.g. Trello):

→ data may be added directly in the model

Page 25: Odoo Connector (formerly OpenERP Connector)

25/42www.camptocamp.com /

Example of binding record

Page 26: Odoo Connector (formerly OpenERP Connector)

26/42www.camptocamp.com /

Design goals - ConnectorUnit

■ Bare, decoupled, classes

■ Registered with a backend

■ 1 class: 1 responsibility

■ Combined to do the synchronizations

Page 27: Odoo Connector (formerly OpenERP Connector)

27/42www.camptocamp.com /

ConnectorUnit – Synchronizer

■ 2 kinds of synchronizers: ○ Importer

○ Exporter

■ Manage the flow of the synchronization○ Use all or part of the other ConnectorUnit classes to

perform each synchronization step

Page 28: Odoo Connector (formerly OpenERP Connector)

28/42www.camptocamp.com /

Overview – ConnectorUnit (importer)

Page 29: Odoo Connector (formerly OpenERP Connector)

29/42www.camptocamp.com /

ConnectorUnit - Mapper

■ Transform data

■ Take data in, give data out

Page 30: Odoo Connector (formerly OpenERP Connector)

30/42www.camptocamp.com /

Code example: Mapper

Page 31: Odoo Connector (formerly OpenERP Connector)

31/42www.camptocamp.com /

Code example: using a Mapperin a Synchronizer

Page 32: Odoo Connector (formerly OpenERP Connector)

32/42www.camptocamp.com /

ConnectorUnit - Binder

■ Know the external ID for an odoo ID (and conversely)

■ Store the couple “external / odoo” IDs in binding records

Page 33: Odoo Connector (formerly OpenERP Connector)

33/42www.camptocamp.com /

Code example: Binder

Page 34: Odoo Connector (formerly OpenERP Connector)

34/42www.camptocamp.com /

Code example: Binder bind method

Page 35: Odoo Connector (formerly OpenERP Connector)

35/42www.camptocamp.com /

Code example: using a Binder in a Synchonizer

Page 36: Odoo Connector (formerly OpenERP Connector)

36/42www.camptocamp.com /

ConnectorUnit - BackendAdapter

■ Communicate with the external system

■ Speak the external language (REST, XML/RPC, …)

■ But 1 interface within odoo○ Typically CRUD

○ Often uses helper library (trollop, requests, magento, gdata...)

Page 37: Odoo Connector (formerly OpenERP Connector)

37/42www.camptocamp.com /

Code example: BackendAdapter

Page 38: Odoo Connector (formerly OpenERP Connector)

38/42www.camptocamp.com /

Code example: using a BackendAdapter in a Synchronizer

Page 39: Odoo Connector (formerly OpenERP Connector)

39/42www.camptocamp.com /

Tests

■ Tests!

■ External system should not be required to run the tests

→ Mock the external API

○ Examples in the Magento connector

Page 40: Odoo Connector (formerly OpenERP Connector)

40/42www.camptocamp.com /

Tips

■ When developing, deactivate the cron tasks / worker process in charge of assigning and queueing the jobs

■ Use erppeek to run jobs one by one:

model('queue.worker').assign_then_enqueue(1)

■ Set a high priority on the job(s) you want to process first○ high priority == low value

Page 41: Odoo Connector (formerly OpenERP Connector)

41/42www.camptocamp.com /

Demo: Trello connector

https://launchpad.net/openerp-trello-connector

Page 42: Odoo Connector (formerly OpenERP Connector)