Alastair McGowan-Douglas
and 1 contributors




version 0.46


Provides a base set of methods for OpenERP::OOM classes (search, create, etc).

Searches OpenERP and returns a list of objects matching a given query.

    my @list = $schema->class('Name')->search(
        ['name', 'ilike', 'OpusVL'],
        ['active', '=', 1],

The query is formatted as a list of array references, each specifying a column name, operator, and value. The objects returned will be those where all of these sub-queries match.

Searches can be performed against OpenERP fields, linked objects (e.g. DBIx::Class relationships), or a combination of both.

    my @list = $schema->class('Name')->search(
        ['active', '=', 1],
        ['details', {status => 'value'}, {}],

In this example, 'details' is a linked DBIx::Class object with a column called 'status'.

An optional 'search context' can also be provided at the end of the query list, e.g.

    my @list = $schema->class('Location')->search(
        ['usage' => '=' => 'internal'],
        ['active' => '=' => 1],
            active_id => $self->id,
            active_ids => [$self->id],
            active_model => 'product.product',
            full => 1,
            product_id => $self->id,
            search_default_in_location => 1,
            section_id => undef,
            tz => undef,

Supplying a context further restricts the search, for example to narrow down a 'stock by location' query to 'stock of a specific product by location'.

Following the search context, an arrayref of options can be given to return a paged set of results:

        limit  => 10,    # Return max 10 results
        offset => 20,    # Start at result 20

This is the same as search but it doesn't turn the results into objects. This is useful if your search is likely to have returned fields that aren't part of the object. Queries like those used by the Stock By Location report are likely to return stock levels as well as the location details for example.


This is an alternative version of search that only fills in the required fields of the object.

    # avoid pulling the whole attachement down for a search
    my @a = $attachments->search_limited_fields([
        qw/res_model res_name type url create_uid create_date
            datas_fname description name res_id/
    ], [
        res_model => '=' => 'product.template',
        res_id => '=' => 1,

This allows you to avoid pulling down problem fields. The most obvious example is get a list of attachments for an object, without pulling down all the data for the attachement.


Returns search criteria for a not null search. i.e. equivalend to $field is not null in SQL.

    $self->search($self->is_not_null('x_department'), [ 'other_field', '=', 3 ]);


Returns a 'null' for use in OpenERP calls and objects. (Actually this is a False value).


Returns search criteria for an is null search. i.e. equivalend to $field is null in SQL.

    $self->search($self->is_null('x_department'), [ 'other_field', '=', 3 ]);


Returns the first object matching a given query.

 my $obj = $schema->class('Name')->find(['id', '=', 32]);

Will return undef if no objects matching the query are found.


This returns the options for available for a selection field. It will croak if you try to give it a field that isn't an option.


Returns an object by ID.

 my $obj = $schema->class('Name')->retrieve(32);


Returns an instance of the object filled in with the default values suggested by OpenERP.

Creates a related DBIC object for an object of this class (before the object is created).

It returns a transaction guard alongside the id so that if the corresponding object fails to create it can be aborted.

This can make the link up smoother as you know the id of the object to refer to in OpenERP before creating the OpenERP object. It also allows for failures to be dealt with more reliably.

     my ($id, $guard) = $self->create_related_object_for_DBIC('details', $details);
     # Create the object
     $object->{x_dbic_link_id} = $id;
     $object->{default_code} = sprintf("OBJ%06d", $id);

     my $prod = $self->$orig($object);


Takes a reference to a list of object IDs and returns a list of objects.

 my @list = $schema->class('Name')->retrieve_list([32, 15, 60]);


Creates a new instance of an object in OpenERP.

 my $obj = $schema->class('Name')->create({
     name   => 'OpusVL',
     active => 1,

Takes a hashref of object parameters.

Returns the new object or undef if it could not be created.


Performs an execute in OpenERP on the class level.

    $c->model('OpenERP')->class('Invoice')->execute('build_invoice', $args);

Please look at OpenERP::OOM::Object::Base for more information on execute




 my $obj = $schema->class('Name')->create(\%args);
 foreach my $obj ($schema->class('Name')->search(@query)) {


Jon Allen (JJ), <>


This software is copyright (c) 2011-2016 by OpusVL.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.