ooor 1.2.3 → 1.2.4

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.
data/README.md CHANGED
@@ -152,7 +152,7 @@ OpenERP context support (same as OpenERP):
152
152
 
153
153
  Request params or ActiveResource equivalence of OpenERP domain (but degraded as only the = operator is supported, else use domain):
154
154
 
155
- $ Partners.find(:all, :params => {:supplier => true})
155
+ $ ResPartner.find(:all, :params => {:supplier => true})
156
156
 
157
157
 
158
158
  OpenERP search method:
@@ -2,6 +2,7 @@ require 'xmlrpc/client'
2
2
  require 'active_resource'
3
3
  require 'app/models/open_object_ui'
4
4
  require 'app/models/uml'
5
+ require 'set'
5
6
 
6
7
  #TODO implement passing session credentials to RPC methods (concurrent access of different user credentials in Rails)
7
8
 
@@ -73,10 +74,8 @@ class OpenObjectResource < ActiveResource::Base
73
74
 
74
75
  #corresponding method for OpenERP osv.execute(self, db, uid, obj, method, *args, **kw) method
75
76
  def rpc_execute_with_all(db, uid, pass, obj, method, *args)
76
- if args[-1].is_a? Hash
77
- args[-1] = @ooor.global_context.merge(args[-1])
78
- end
79
- logger.debug "rpc_execute_with_all: rpc_methods: 'execute', db: #{db.inspect}, uid: #{uid.inspect}, pass: #{pass.inspect}, obj: #{obj.inspect}, method: #{method}, *args: #{args.inspect}"
77
+ args[-1] = @ooor.global_context.merge(args[-1]) if args[-1].is_a? Hash
78
+ logger.debug "rpc_execute_with_all: rpc_method: 'execute', db: #{db.inspect}, uid: #{uid.inspect}, pass: #{pass.inspect}, obj: #{obj.inspect}, method: #{method}, *args: #{args.inspect}"
80
79
  try_with_pretty_error_log { client((@database && @site || @ooor.base_url) + "/object").call("execute", db, uid, pass, obj, method, *args) }
81
80
  end
82
81
 
@@ -90,10 +89,8 @@ class OpenObjectResource < ActiveResource::Base
90
89
  end
91
90
 
92
91
  def rpc_exec_workflow_with_all(db, uid, pass, obj, action, *args)
93
- if args[-1].is_a? Hash
94
- args[-1] = @ooor.global_context.merge(args[-1])
95
- end
96
- logger.debug "rpc_execute_with_all: rpc_methods: 'exec_workflow', db: #{db.inspect}, uid: #{uid.inspect}, pass: #{pass.inspect}, obj: #{obj.inspect}, action #{action}, *args: #{args.inspect}"
92
+ args[-1] = @ooor.global_context.merge(args[-1]) if args[-1].is_a? Hash
93
+ logger.debug "rpc_execute_with_all: rpc_method: 'exec_workflow', db: #{db.inspect}, uid: #{uid.inspect}, pass: #{pass.inspect}, obj: #{obj.inspect}, action: #{action}, *args: #{args.inspect}"
97
94
  try_with_pretty_error_log { client((@database && @site || @ooor.base_url) + "/object").call("exec_workflow", db, uid, pass, obj, action, *args) }
98
95
  end
99
96
 
@@ -114,12 +111,14 @@ class OpenObjectResource < ActiveResource::Base
114
111
  openerp_error_hash = eval("#{ e }".gsub("wrong fault-structure: ", ""))
115
112
  if openerp_error_hash.is_a? Hash
116
113
  logger.error "*********** OpenERP Server ERROR:
117
- #{openerp_error_hash["faultString"]}
118
- ***********"
114
+ #{openerp_error_hash["faultString"]}***********"
115
+ e.backtrace.each {|line| logger.error line if line.index("ooor")} and return nil
116
+ else
117
+ raise
119
118
  end
120
119
  rescue
120
+ raise
121
121
  end
122
- raise
123
122
  end
124
123
 
125
124
  def method_missing(method_symbol, *arguments) self.rpc_execute(method_symbol.to_s, *arguments) end
@@ -171,6 +170,13 @@ class OpenObjectResource < ActiveResource::Base
171
170
  return active_resources
172
171
  end
173
172
 
173
+ #overriden because loading default fields is all the rage but we don't want them when reading a record
174
+ def instantiate_record(record, prefix_options = {})
175
+ new(record, [], {}).tap do |resource|
176
+ resource.prefix_options = prefix_options
177
+ end
178
+ end
179
+
174
180
  end
175
181
 
176
182
 
@@ -295,6 +301,20 @@ class OpenObjectResource < ActiveResource::Base
295
301
  @attributes.reject {|key, value| key == 'id'}.merge(@relations)
296
302
  end
297
303
 
304
+ #takes care of reading OpenERP default field values.
305
+ #FIXME: until OpenObject explicits inheritances, we load all default values of all related fields, unless specified in default_get_list
306
+ def initialize(attributes = {}, default_get_list=false, context={})
307
+ @attributes = {}
308
+ @prefix_options = {}
309
+ if ['ir.model', 'ir.model.fields'].index(self.class.openerp_model) || default_get_list == []
310
+ load(attributes)
311
+ else
312
+ self.class.reload_fields_definition() unless self.class.fields_defined
313
+ 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
314
+ load(self.class.rpc_execute("default_get", default_get_list, context).merge(attributes))
315
+ end
316
+ end
317
+
298
318
  #compatible with the Rails way but also supports OpenERP context
299
319
  def create(context={})
300
320
  self.id = self.class.rpc_execute('create', to_openerp_hash!, context)
@@ -364,9 +384,16 @@ class OpenObjectResource < ActiveResource::Base
364
384
  is_assign = method_name.end_with?('=')
365
385
  method_key = method_name.sub('=', '')
366
386
  return super if attributes.has_key?(method_key)
367
-
368
- @relations[method_key] = arguments[0] and return if is_assign && self.class.relations_keys.index(method_key)
369
- @attributes[method_key] = arguments[0] and return if is_assign && self.class.fields.keys.index(method_key)
387
+ return self.class.rpc_execute(method_name, *arguments) unless arguments.empty? || is_assign
388
+
389
+ self.class.reload_fields_definition() unless self.class.fields_defined
390
+
391
+ if is_assign
392
+ know_relations = self.class.relations_keys + self.class.many2one_relations.collect {|k, field| self.class.const_get(field.relation).relations_keys}.flatten
393
+ @relations[method_key] = arguments[0] and return if know_relations.index(method_key)
394
+ know_fields = self.class.fields.keys + self.class.many2one_relations.collect {|k, field| self.class.const_get(field.relation).fields.keys}.flatten
395
+ @attributes[method_key] = arguments[0] and return if know_fields.index(method_key)
396
+ end
370
397
 
371
398
  return @loaded_relations[method_name] if @loaded_relations.has_key?(method_name)
372
399
  return false if @relations.has_key?(method_name) and !@relations[method_name]
@@ -387,11 +414,13 @@ class OpenObjectResource < ActiveResource::Base
387
414
  @attributes[method_key] = arguments[0] and return if klazz.fields.keys.index(method_key)
388
415
  end
389
416
  end
417
+ super
390
418
 
391
- rescue
419
+ rescue RuntimeError
420
+ raise
421
+ rescue NoMethodError
392
422
  display_available_fields
393
-
394
- super
423
+ raise
395
424
  end
396
425
 
397
426
  end
@@ -1,17 +1,16 @@
1
- require 'set'
2
-
3
1
  module UML
4
2
  #usage: UML.print_uml or with options: UML.print_uml(:all, : detailed) or MyOpenObjectResource.print_uml or UML.print_uml([list_of_classes], :all, :detailed)
5
3
 
6
4
  def self.included(base) base.extend(ClassMethods) end
7
5
 
8
6
  def print_uml(*options)
9
- UML.print_uml(@config[:models] && @all_loaded_models.select {|model| @config[:models].index(model.openerp_model)} || @all_loaded_models, options)
7
+ ooor = self.class.ooor
8
+ UML.print_uml(ooor.config[:models] && ooor.all_loaded_models.select {|model| ooor.config[:models].index(model.openerp_model)} || ooor.all_loaded_models, options)
10
9
  end
11
10
 
12
11
  module ClassMethods
13
12
  def print_uml(*options)
14
- UML.print_uml([self], options) if self.is_a?(OpenObjectResource)
13
+ UML.print_uml([self], options)
15
14
  end
16
15
  end
17
16
 
@@ -21,17 +21,16 @@ class Ooor
21
21
  end
22
22
 
23
23
  def global_login(user, password)
24
- begin
25
24
  @config[:username] = user
26
25
  @config[:password] = password
27
26
  client = OpenObjectResource.client(@base_url + "/common")
28
27
  OpenObjectResource.try_with_pretty_error_log { client.call("login", @config[:database], user, password)}
29
- rescue SocketError => error
28
+ rescue Exception => error
30
29
  @logger.error """login to OpenERP server failed:
31
30
  #{error.inspect}
32
31
  Are your sure the server is started? Are your login parameters correct? Can this server ping the OpenERP server?
33
32
  login XML/RPC url was #{@config[:url].gsub(/\/$/,'') + "/common"}"""
34
- end
33
+ raise
35
34
  end
36
35
 
37
36
  def initialize(config, env=false)
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ooor
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3
4
+ version: 1.2.4
5
5
  platform: ruby
6
6
  authors:
7
- - Raphael Valyi - www.akretion.com
7
+ - Raphael Valyi - www.akretion.com
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-19 00:00:00 -02:00
12
+ date: 2010-02-04 00:00:00 -02:00
13
13
  default_executable:
14
14
  dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: activeresource
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: 2.3.1
24
- version:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activeresource
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.3.1
24
+ version:
25
25
  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
26
  email: rvalyi@akretion.com
27
27
  executables: []
@@ -31,13 +31,13 @@ extensions: []
31
31
  extra_rdoc_files: []
32
32
 
33
33
  files:
34
- - README.md
35
- - MIT-LICENSE
36
- - lib/ooor.rb
37
- - lib/app/models/open_object_resource.rb
38
- - lib/app/models/open_object_ui.rb
39
- - lib/app/models/uml.rb
40
- - ooor.yml
34
+ - README.md
35
+ - MIT-LICENSE
36
+ - lib/ooor.rb
37
+ - lib/app/models/open_object_resource.rb
38
+ - lib/app/models/open_object_ui.rb
39
+ - lib/app/models/uml.rb
40
+ - ooor.yml
41
41
  has_rdoc: true
42
42
  homepage: http://github.com/rvalyi/ooor
43
43
  licenses: []
@@ -46,18 +46,18 @@ post_install_message:
46
46
  rdoc_options: []
47
47
 
48
48
  require_paths:
49
- - lib
49
+ - lib
50
50
  required_ruby_version: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: "0"
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
55
  version:
56
56
  required_rubygems_version: !ruby/object:Gem::Requirement
57
57
  requirements:
58
- - - ">="
59
- - !ruby/object:Gem::Version
60
- version: "0"
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: "0"
61
61
  version:
62
62
  requirements: []
63
63