ooor 1.2.7 → 1.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -46,6 +46,13 @@ class OpenObjectResource < ActiveResource::Base
46
46
  end
47
47
  end
48
48
  @relations_keys = @many2one_relations.merge(@one2many_relations).merge(@many2many_relations).keys
49
+ (@fields.keys + @relations_keys).each do |meth| #generates method handlers for autompletion tools such as jirb_swing
50
+ self.instance_eval do
51
+ define_method meth do |*args|
52
+ self.send :method_missing, *[meth, *args]
53
+ end
54
+ end
55
+ end
49
56
  logger.info "#{fields.size} fields loaded in model #{self.class}"
50
57
  end
51
58
  @fields_defined = true
@@ -131,7 +138,9 @@ class OpenObjectResource < ActiveResource::Base
131
138
 
132
139
  def cast_request_to_openerp!(map)
133
140
  map.each do |k, v|
134
- if !v.is_a?(Integer) && !v.is_a?(Float) && v.is_a?(Numeric) && v.respond_to?(:to_f)
141
+ if v == nil
142
+ map[k] = false
143
+ elsif !v.is_a?(Integer) && !v.is_a?(Float) && v.is_a?(Numeric) && v.respond_to?(:to_f)
135
144
  map[k] = v.to_f
136
145
  elsif !v.is_a?(Numeric) && !v.is_a?(Integer) && v.respond_to?(:sec) && v.respond_to?(:year)#really ensure that's a datetime type
137
146
  map[k] = "#{v.year}-#{v.month}-#{v.day} #{v.hour}:#{v.min}:#{v.sec}"
@@ -190,9 +199,6 @@ class OpenObjectResource < ActiveResource::Base
190
199
  !ids.empty? && ids[0].is_a?(Integer) && find_single(ids, options) || []
191
200
  end
192
201
 
193
- #TODO, makes sense?
194
- def find_one; raise"Not implemented yet, go on!"; end
195
-
196
202
  # Find a single resource from the default URL
197
203
  def find_single(scope, options)
198
204
  fields = options[:fields] || []
@@ -205,7 +211,7 @@ class OpenObjectResource < ActiveResource::Base
205
211
  tab = item.split(".")
206
212
  domain = [['name', '=', tab[-1]]]
207
213
  domain += [['module', '=', tab[-2]]] if tab[-2]
208
- ir_model_data = IrModelData.find(:first, :domain => domain)
214
+ ir_model_data = const_get('ir.model.data').find(:first, :domain => domain)
209
215
  ir_model_data && ir_model_data.res_id && search([['id', '=', ir_model_data.res_id]])[0]
210
216
  else
211
217
  item
@@ -296,7 +302,7 @@ class OpenObjectResource < ActiveResource::Base
296
302
  resource = find_or_create_resource_for(key) #TODO check!
297
303
  @attributes[skey] = resource@attributes[skey].new(value)
298
304
  else
299
- @attributes[skey] = value.dup rescue value
305
+ @attributes[skey] = value
300
306
  end
301
307
  end
302
308
  end
@@ -310,18 +316,13 @@ class OpenObjectResource < ActiveResource::Base
310
316
  end
311
317
 
312
318
  def display_available_fields
313
- self.class.logger.debug ""
314
- self.class.logger.debug "*** DIRECTLY AVAILABLE FIELDS ON OBJECT #{self} ARE: ***\n"
315
- self.class.fields.sort {|a,b| a[1].ttype<=>b[1].ttype}.each {|i| self.class.logger.debug "#{i[1].ttype} --- #{i[0]}"}
316
- self.class.logger.debug ""
317
- self.class.many2one_relations.each {|k, v| self.class.logger.debug "many2one --- #{v.relation} --- #{k}"}
318
- self.class.logger.debug ""
319
- self.class.one2many_relations.each {|k, v| self.class.logger.debug "one2many --- #{v.relation} --- #{k}"}
320
- self.class.logger.debug ""
321
- self.class.many2many_relations.each {|k, v| self.class.logger.debug "many2many --- #{v.relation} --- #{k}"}
322
- self.class.logger.debug ""
323
- self.class.logger.debug "YOU CAN ALSO USE THE INHERITED FIELDS FROM THE INHERITANCE MANY2ONE RELATIONS OR THE OBJECT METHODS..."
324
- self.class.logger.debug ""
319
+ msg = "\n*** DIRECTLY AVAILABLE FIELDS ON OBJECT #{self} ARE: ***"
320
+ msg << "\n\n" << self.class.fields.sort {|a,b| a[1].ttype<=>b[1].ttype}.map {|i| "#{i[1].ttype} --- #{i[0]}"}.join("\n")
321
+ msg << "\n\n" << self.class.many2one_relations.map {|k, v| "many2one --- #{v.relation} --- #{k}"}.join("\n")
322
+ msg << "\n\n" << self.class.one2many_relations.map {|k, v| "one2many --- #{v.relation} --- #{k}"}.join("\n")
323
+ msg << "\n\n" << self.class.many2many_relations.map {|k, v| "many2many --- #{v.relation} --- #{k}"}.join("\n")
324
+ msg << "\n\nYOU CAN ALSO USE THE INHERITED FIELDS FROM THE INHERITANCE MANY2ONE RELATIONS OR THE OBJECT METHODS...\n\n"
325
+ self.class.logger.debug msg
325
326
  end
326
327
 
327
328
  def to_openerp_hash!
@@ -340,7 +341,7 @@ class OpenObjectResource < ActiveResource::Base
340
341
  else
341
342
  self.class.reload_fields_definition() unless self.class.fields_defined
342
343
  default_get_list ||= Set.new(self.class.many2one_relations.collect {|k, field| self.class.const_get(field.relation).fields.keys}.flatten + self.class.fields.keys).to_a
343
- load(self.class.rpc_execute("default_get", default_get_list, context).merge(attributes))
344
+ load(self.class.rpc_execute("default_get", default_get_list, context).symbolize_keys!.merge(attributes.symbolize_keys!))
344
345
  end
345
346
  end
346
347
 
@@ -36,7 +36,7 @@ class Ooor
36
36
  def initialize(config, env=false)
37
37
  @config = config.is_a?(String) ? Ooor.load_config(config, env) : config
38
38
  @config.symbolize_keys!
39
- @logger = ((defined?(RAILS_ENV) and RAILS_ENV != "development") ? Rails.logger : Logger.new(STDOUT))
39
+ @logger = ((defined?(RAILS_ENV) && $0 != 'irb') ? Rails.logger : Logger.new(STDOUT))
40
40
  @logger.level = config[:log_level] if config[:log_level]
41
41
  @base_url = config[:url].gsub(/\/$/,'')
42
42
  @global_context = config[:global_context] || {}
@@ -54,7 +54,7 @@ class Ooor
54
54
  if config[:models] #we load only a customized subset of the OpenERP models
55
55
  models = @ir_model_class.find(:all, :domain => [['model', 'in', config[:models]]])
56
56
  else #we load all the models
57
- models = @ir_model_class.find(:all).reject {|model| model.model == "ir.model" || model.model == "ir.model.fields"}
57
+ models = @ir_model_class.find(:all).reject {|model| ["ir.model", "ir.model.fields", "ir.model.data"].index model.model}
58
58
  end
59
59
  models.each {|openerp_model| define_openerp_model(openerp_model, nil, nil, nil, nil, config[:scope_prefix])}
60
60
  end
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ooor
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.7
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 2
8
+ - 8
9
+ version: 1.2.8
5
10
  platform: ruby
6
11
  authors:
7
12
  - Raphael Valyi - www.akretion.com
@@ -9,19 +14,23 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-02-24 00:00:00 -03:00
17
+ date: 2010-03-02 00:00:00 -03:00
13
18
  default_executable:
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: activeresource
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
20
24
  requirements:
21
25
  - - ">="
22
26
  - !ruby/object:Gem::Version
27
+ segments:
28
+ - 2
29
+ - 3
30
+ - 1
23
31
  version: 2.3.1
24
- version:
32
+ type: :runtime
33
+ version_requirements: *id001
25
34
  description: OOOR exposes business object proxies to your Ruby (Rails or not) application, that map seamlessly to your remote OpenObject/OpenERP server using webservices. It extends the standard ActiveResource API.
26
35
  email: rvalyi@akretion.com
27
36
  executables: []
@@ -51,18 +60,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
51
60
  requirements:
52
61
  - - ">="
53
62
  - !ruby/object:Gem::Version
63
+ segments:
64
+ - 0
54
65
  version: "0"
55
- version:
56
66
  required_rubygems_version: !ruby/object:Gem::Requirement
57
67
  requirements:
58
68
  - - ">="
59
69
  - !ruby/object:Gem::Version
70
+ segments:
71
+ - 0
60
72
  version: "0"
61
- version:
62
73
  requirements: []
63
74
 
64
75
  rubyforge_project:
65
- rubygems_version: 1.3.5
76
+ rubygems_version: 1.3.6
66
77
  signing_key:
67
78
  specification_version: 3
68
79
  summary: OOOR - OpenObject On Rails