OpenERP::OOM::Tutorial::Schema - Setting up an OpenERP::OOM Schema
OpenERP::OOM uses an object model consisting of a Schema, Classes, and Objects. These are organised as shown below, with methods to traverse up and down the tree.
+-------------------------------+ | Schema | | e.g. MyApp | +-------------------------------+ /|\ | | class schema | | \|/ +-------------------------------+ | Class | | e.g. MyApp::Class::Partner | +-------------------------------+ /|\ | | search class retrieve | create | | | \|/ +-------------------------------+ | Object | | e.g. MyApp::Object::Partner | +-------------------------------+ | update delete | \|/ +-------------------------------+ | OpenERP model | | e.g res.partner | +-------------------------------+
The schema class extends the OpenERP::OOM::Schema module, i.e.:
package MyApp; use Moose; extends 'OpenERP::OOM::Schema'; 1;
To create a new instance of your schema, pass the OpenERP connection details in the call to new().
new()
use MyApp; my $schema = MyApp->new( openerp_connect => { host => 'localhost', dbname => 'openerp_db', username => 'admin', password => 'admin', } );
A typical class definition is as follows:
package MyApp::Class::Partner; use OpenERP::OOM::Class; object_type 'MyApp::Object::Company'; 1;
From your schema, you can then access classes.
my $class = $schema->class('Partner');
The class provides methods to search, retrieve, and create objects.
package MyApp::Object::Partner; use OpenERP::OOM::Object; openerp_model 'res.partner'; has 'name' => (isa=>'Str', is=>'rw'); 1;
Objects are created and retrieved from the class:
my $partner = $schema->class('Partner')->create({ name => 'My Partner', }); foreach my $partner ($schema->class->('Partner')->search) { say $partner->name; }
__END__
To install OpenERP::OOM, copy and paste the appropriate command in to your terminal.
cpanm
cpanm OpenERP::OOM
CPAN shell
perl -MCPAN -e shell install OpenERP::OOM
For more information on module installation, please visit the detailed CPAN module installation guide.