Module: Kangaroo::Model::OpenObjectOrm

Includes:
ConditionNormalizer
Included in:
Base
Defined in:
lib/kangaroo/model/open_object_orm.rb

Constant Summary

Constants included from ConditionNormalizer

ConditionNormalizer::CONDITION_OPERATORS, ConditionNormalizer::CONDITION_PATTERN

Instance Method Summary collapse

Instance Method Details

#create_record(attributes, options = {}) ⇒ Number

Create a OpenObject record.

Parameters:

  • attributes (Hash)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • context (Hash)

Returns:

  • (Number)

    id



76
77
78
# File 'lib/kangaroo/model/open_object_orm.rb', line 76

def create_record attributes, options = {}
  remote.create attributes, options[:context]
end

#default_get(options = {}) ⇒ Hash

Fetch default attribute values from OpenERP database

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • fields (Array)
  • context (Hash)

Returns:

  • (Hash)

    default values



87
88
89
90
91
92
93
# File 'lib/kangaroo/model/open_object_orm.rb', line 87

def default_get options = {}
  options = {
    :fields => attribute_names
  }.merge(options)

  remote.default_get options[:fields], options[:context]
end

#fields_get(options = {}) ⇒ Hash

Retrieve field informations

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • fields (Array)
  • context (Hash)

Returns:

  • (Hash)


59
60
61
62
63
64
65
66
67
68
# File 'lib/kangaroo/model/open_object_orm.rb', line 59

def fields_get options = {}
  options = {
    :fields => attribute_names,
    :context => {}
  }.merge(options)

  remote.fields_get(options[:fields], options[:context]).map do |key, val|
    Field.new key, val
  end
end

#read(ids, options = {}) ⇒ Array

Read records and instantiate them

Parameters:

  • ids (Array)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • fields (Array)
  • context (Hash)

Returns:

  • (Array)

    list of Kangaroo::Model::Base instances



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/kangaroo/model/open_object_orm.rb', line 40

def read ids, options = {}
  fields = options[:fields]
  fields = attribute_names if options[:fields].blank?
  context = options[:context]

  [].tap do |result|
    remote.read(ids, fields, context).each do |attributes|
      position = ids.index(attributes[:id].to_i)
      result[position] = instantiate attributes, context
    end
  end
end

#search(conditions, options = {}) ⇒ Object

Search for records in the OpenERP database

Parameters:

  • conditions (Hash, Array, String)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • limit (Number)
  • offset (Number)
  • order (String)
  • context (Hash)
  • count (boolean)

Returns:

  • list of ids



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/kangaroo/model/open_object_orm.rb', line 19

def search conditions, options = {}
  options = {
    :limit  => false,
    :offset => 0
  }.merge(options)

  remote.search normalize_conditions(conditions),
                options[:offset],
                options[:limit],
                options[:order],
                options[:context],
                options[:count]
end

Remove records

Parameters:

  • ids (Array)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • context (Hash)

Returns:

  • (boolean)

    true/false



112
113
114
# File 'lib/kangaroo/model/open_object_orm.rb', line 112

def unlink ids, options = {}
  remote.unlink ids, options[:context]
end

#write_record(ids, attributes, options = {}) ⇒ boolean

Write values to records

Parameters:

  • ids (Array)
  • attributes (Hash)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • context (Hash)

Returns:

  • (boolean)

    true/false



102
103
104
# File 'lib/kangaroo/model/open_object_orm.rb', line 102

def write_record ids, attributes, options = {}
  remote.write ids, attributes, options[:context]
end