NAME
OpenERP::OOM::Tutorial::Schema - Setting up an OpenERP::OOM Schema
DESCRIPTION
Object model
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       |
+-------------------------------+
Schema
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().
use MyApp;
my $schema = MyApp->new(
    openerp_connect => {
        host     => 'localhost',
        dbname   => 'openerp_db',
        username => 'admin',
        password => 'admin',
    }
);
Classes
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.
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__