OpenERP and Perl

66
OpenERP and Perl Jon Allen (JJ) – [email protected]

description

OpenERP is a very flexible open-source ERP system, which handles accounting, CRM, sales, purchasing, manufacturing, and many other business functions. It is written in Python but has an XML-RPC API so we can control all of its functions from Perl. However, despite OpenERP having an object-oriented architecture the API is quite 'low-level', and using it is a very different experience compared to having an ORM like DBIx::Class. OpenERP::OOM (Object to Object Mapper) bridges this gap, letting us use Moose classes to represent the OpenERP schema. As with an ORM, the schema and object classes can be extended with our own methods and functions. With this approach the underlying interface to OpenERP becomes transparent - everything is done with Perl - which means we can write Catalyst models, extend OpenERP with CPAN modules, and use all of OpenERP's functions from our Perl code. Presented at the YAPC Europe 2012 conference in Frankfurt, Germany.

Transcript of OpenERP and Perl

Page 1: OpenERP and Perl

OpenERP and Perl Jon  Allen  (JJ)  –  [email protected]  

Page 2: OpenERP and Perl

www.opusvl.com!

OpenERP

Page 3: OpenERP and Perl

www.opusvl.com!

enterprise"resource"planning

Page 4: OpenERP and Perl

www.opusvl.com!

?

Page 5: OpenERP and Perl

www.opusvl.com!

core business"applications

Page 6: OpenERP and Perl

www.opusvl.com!

sales crm"manufacturing"

purchasing

Page 7: OpenERP and Perl

www.opusvl.com!

accounting

Page 8: OpenERP and Perl

www.opusvl.com!

integrated accounting

Page 9: OpenERP and Perl

www.opusvl.com!

Page 10: OpenERP and Perl

www.opusvl.com!

Perl?

Page 11: OpenERP and Perl

www.opusvl.com!

OpenERP

website

intranet

Page 12: OpenERP and Perl

www.opusvl.com!

api

Page 13: OpenERP and Perl

www.opusvl.com!

XML-RPC

Page 14: OpenERP and Perl

www.opusvl.com!

single"requests

Page 15: OpenERP and Perl

www.opusvl.com!

stateless

Page 16: OpenERP and Perl

www.opusvl.com!

object"model

Page 17: OpenERP and Perl

www.opusvl.com!

relationships

Page 18: OpenERP and Perl

www.opusvl.com!

one2manyres.partner

res.partner.address

res.companymany2one

Page 19: OpenERP and Perl

www.opusvl.com!

database

Page 20: OpenERP and Perl

www.opusvl.com!

ORM

Page 21: OpenERP and Perl

www.opusvl.com!

object"relational"mapper

Page 22: OpenERP and Perl

www.opusvl.com!

OOM

Page 23: OpenERP and Perl

www.opusvl.com!

object to"object"

mapper

Page 24: OpenERP and Perl

www.opusvl.com!

OpenERP::OOM

Page 25: OpenERP and Perl

www.opusvl.com!

Moose

Page 26: OpenERP and Perl

www.opusvl.com!

object model

Page 27: OpenERP and Perl

www.opusvl.com!

OpenERP

Schema

Class Class Class

Object Object

Page 28: OpenERP and Perl

www.opusvl.com!

# Code layout for module using OpenERP::OOM

lib/ MyApp.pm # Schema definition MyApp/ Class/ # Class definitions Company.pm Partner.pm Object/ # Object definitions Company.pm Partner.pm

Page 29: OpenERP and Perl

www.opusvl.com!

schema

Page 30: OpenERP and Perl

www.opusvl.com!

# MyApp.pm

package MyApp;

use Moose;extends 'OpenERP::OOM::Schema';

1;

Page 31: OpenERP and Perl

www.opusvl.com!

connection

Page 32: OpenERP and Perl

www.opusvl.com!

use MyApp;

my $schema = MyApp->new( openerp_connect => { host => 'localhost', dbname => 'jj_test_1', username => 'admin', password => 'admin', },);

Page 33: OpenERP and Perl

www.opusvl.com!

classes

Page 34: OpenERP and Perl

www.opusvl.com!

# MyApp/Class/Company.pm

package MyApp::Class::Company;use OpenERP::OOM::Class;

object_type 'MyApp::Object::Company';

# Class methods go here

1;

Page 35: OpenERP and Perl

www.opusvl.com!

objects

Page 36: OpenERP and Perl

www.opusvl.com!

fields

Page 37: OpenERP and Perl

www.opusvl.com!

relationships

Page 38: OpenERP and Perl

www.opusvl.com!

partner"has many"addresses

Page 39: OpenERP and Perl

www.opusvl.com!

package MyApp::Object::Partner;use OpenERP::OOM::Object;

openerp_model 'res.partner';has 'name' => (isa=>'Str', is=>'rw');

relationship 'addresses' => ( key => 'address', # OpenERP field type => 'one2many', # OpenERP type class => 'PartnerAddress',);

Page 40: OpenERP and Perl

www.opusvl.com!

object "creation

Page 41: OpenERP and Perl

www.opusvl.com!

# Schema -> Class -> Class Method

my $partner = $schema->class('Partner')-> create({ name => 'JJ' });

# Updates

$partner->update({name => 'Jon Allen'});say $partner->name;

Page 42: OpenERP and Perl

www.opusvl.com!

search

Page 43: OpenERP and Perl

www.opusvl.com!

# Single result

my $jj = $schema->class('Partner')-> find(['name' => '=' => 'JJ']);

# Multiple results

my @partners = $schema->class('Partner')-> search(['name' => 'like' => 'J']);

Page 44: OpenERP and Perl

www.opusvl.com!

related"objects

Page 45: OpenERP and Perl

www.opusvl.com!

$partner->create_related( 'addresses', { name => '...', street => '...', city => '...', });

Page 46: OpenERP and Perl

www.opusvl.com!

add"methods

Page 47: OpenERP and Perl

www.opusvl.com!

extend OpenERP

objects

Page 48: OpenERP and Perl

www.opusvl.com!

external"data sources

Page 49: OpenERP and Perl

www.opusvl.com!

DBIx::Class

Page 50: OpenERP and Perl

www.opusvl.com!

not just"data

Page 51: OpenERP and Perl

www.opusvl.com!

OpenERP"methods

Page 52: OpenERP and Perl

www.opusvl.com!

workflows

Page 53: OpenERP and Perl

www.opusvl.com!

integrated"accounting

Page 54: OpenERP and Perl

www.opusvl.com!

my $po = $schema->class('PurchaseOrder')-> search([ ... ]);

$po->update({ ... });

# Approve purchase order$po->execute_workflow('purchase_confirm');

# Print (returns PDF)$po->get_report('purchase.order');

Page 55: OpenERP and Perl

www.opusvl.com!

application logic = Perl

Page 56: OpenERP and Perl

www.opusvl.com!

application"data = DBIC

Page 57: OpenERP and Perl

www.opusvl.com!

generic logic "= OpenERP

Page 58: OpenERP and Perl

www.opusvl.com!

generic data "= OpenERP

Page 59: OpenERP and Perl

www.opusvl.com!

many uses

Page 60: OpenERP and Perl

www.opusvl.com!

Catalyst model

Page 61: OpenERP and Perl

www.opusvl.com!

18 months"development

Page 62: OpenERP and Perl

www.opusvl.com!

3 commercial"deployments

Page 63: OpenERP and Perl

www.opusvl.com!

open sourced"today

Page 64: OpenERP and Perl

www.opusvl.com!

http://search.cpan.org/dist/OpenERP-OOM

Page 65: OpenERP and Perl

www.opusvl.com!

questions?

Page 66: OpenERP and Perl

www.opusvl.com!