Jon Allen > OpenERP-OOM > OpenERP::OOM::Class::Base

Download:
OpenERP-OOM-0.12.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Source  

NAME ^

OpenERP::OOM::Class::Base

SYNOPSYS ^

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

DESCRIPTION ^

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

search

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
    }

raw_search

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.

is_not_null

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 ]);

null

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

is_null

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 ]);

find

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.

get_options

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.

retrieve

Returns an object by ID.

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

default_values

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

retrieve_list

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]);

create

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.

AUTHOR ^

Jon Allen (JJ) - jj@opusvl.com

COPYRIGHT and LICENSE ^

Copyright (C) 2010 Opus Vision Limited

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

syntax highlighting: