ooor 1.6.0 → 1.6.1
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/lib/app/models/open_object_resource.rb +27 -23
- data/lib/ooor.rb +1 -1
- metadata +41 -43
@@ -42,10 +42,10 @@ module Ooor
|
|
42
42
|
end
|
43
43
|
|
44
44
|
#similar to Object#const_get but for OpenERP model key
|
45
|
-
def const_get(model_key)
|
45
|
+
def const_get(model_key, context={})
|
46
46
|
klass_name = class_name_from_model_key(model_key)
|
47
47
|
klass = (self.scope_prefix ? Object.const_get(self.scope_prefix) : Object).const_defined?(klass_name) ? (self.scope_prefix ? Object.const_get(self.scope_prefix) : Object).const_get(klass_name) : @ooor.define_openerp_model({'model' => model_key}, self.scope_prefix)
|
48
|
-
klass.reload_fields_definition()
|
48
|
+
klass.reload_fields_definition(false, context)
|
49
49
|
klass
|
50
50
|
end
|
51
51
|
|
@@ -53,7 +53,7 @@ module Ooor
|
|
53
53
|
self.new(attributes, default_get_list, context).tap { |resource| resource.save(context, reload) }
|
54
54
|
end
|
55
55
|
|
56
|
-
def reload_fields_definition(force =
|
56
|
+
def reload_fields_definition(force=false, context={})
|
57
57
|
if force or not @fields_defined
|
58
58
|
@fields_defined = true
|
59
59
|
@fields = {}
|
@@ -122,6 +122,7 @@ module Ooor
|
|
122
122
|
user_id = args[-1].delete(:user_id) || args[-1].delete('user_id') || @user_id || @ooor.config[:user_id]
|
123
123
|
password = args[-1].delete(:password) || args[-1].delete('password') || @password || @ooor.config[:password]
|
124
124
|
database = args[-1].delete(:database) || args[-1].delete('database') || @database || @ooor.config[:database]
|
125
|
+
args[-1].delete(:context)
|
125
126
|
else
|
126
127
|
user_id = @user_id || @ooor.config[:user_id] #TODO @user_id useless?
|
127
128
|
password = @password || @ooor.config[:password]
|
@@ -133,7 +134,7 @@ module Ooor
|
|
133
134
|
#corresponding method for OpenERP osv.execute(self, db, uid, obj, method, *args, **kw) method
|
134
135
|
def rpc_execute_with_all(db, uid, pass, obj, method, *args)
|
135
136
|
clean_request_args!(args)
|
136
|
-
reload_fields_definition()
|
137
|
+
reload_fields_definition(false, {:user_id => uid, :password => pass})
|
137
138
|
logger.debug "OOOR RPC: rpc_method: 'execute', db: #{db}, uid: #{uid}, pass: #, obj: #{obj}, method: #{method}, *args: #{args.inspect}"
|
138
139
|
cast_answer_to_ruby!(@ooor.get_rpc_client("#{(@database && @site || @ooor.base_url)}/object").call("execute", db, uid, pass, obj, method, *args))
|
139
140
|
end
|
@@ -177,10 +178,10 @@ module Ooor
|
|
177
178
|
private
|
178
179
|
|
179
180
|
def find_every(options)
|
180
|
-
domain = options[:domain]
|
181
|
+
domain = options[:domain] || []
|
181
182
|
context = options[:context] || {}
|
182
|
-
prefix_options, domain = split_options(options[:params]) unless domain
|
183
|
-
ids = rpc_execute('search', to_openerp_domain(domain), options[:offset] || 0, options[:limit] || false, options[:order] || false, context)
|
183
|
+
#prefix_options, domain = split_options(options[:params]) unless domain
|
184
|
+
ids = rpc_execute('search', to_openerp_domain(domain), options[:offset] || 0, options[:limit] || false, options[:order] || false, context.dup)
|
184
185
|
!ids.empty? && ids[0].is_a?(Integer) && find_single(ids, options) || []
|
185
186
|
end
|
186
187
|
|
@@ -188,7 +189,7 @@ module Ooor
|
|
188
189
|
def find_single(scope, options)
|
189
190
|
fields = options[:fields] || options[:only] || []
|
190
191
|
context = options[:context] || {}
|
191
|
-
prefix_options, query_options = split_options(options[:params])
|
192
|
+
# prefix_options, query_options = split_options(options[:params])
|
192
193
|
is_collection = true
|
193
194
|
scope = [scope] and is_collection = false if !scope.is_a? Array
|
194
195
|
scope.map! do |item|
|
@@ -196,13 +197,13 @@ module Ooor
|
|
196
197
|
tab = item.split(".")
|
197
198
|
domain = [['name', '=', tab[-1]]]
|
198
199
|
domain += [['module', '=', tab[-2]]] if tab[-2]
|
199
|
-
ir_model_data = const_get('ir.model.data').find(:first, :domain => domain)
|
200
|
+
ir_model_data = const_get('ir.model.data', context).find(:first, :domain => domain)
|
200
201
|
ir_model_data && ir_model_data.res_id && search([['id', '=', ir_model_data.res_id]])[0]
|
201
202
|
else
|
202
203
|
item
|
203
204
|
end
|
204
205
|
end.reject! {|item| !item}
|
205
|
-
records = rpc_execute('read', scope, fields, context)
|
206
|
+
records = rpc_execute('read', scope, fields, context.dup)
|
206
207
|
records = records.sort_by {|r| scope.index(r["id"])} #TODO use sort_by! in Ruby 1.9
|
207
208
|
active_resources = []
|
208
209
|
records.each do |record|
|
@@ -210,7 +211,7 @@ module Ooor
|
|
210
211
|
record.each_pair do |k,v|
|
211
212
|
r[k.to_sym] = v
|
212
213
|
end
|
213
|
-
active_resources << instantiate_record(r,
|
214
|
+
active_resources << instantiate_record(r, {}, context)
|
214
215
|
end
|
215
216
|
unless is_collection
|
216
217
|
return active_resources[0]
|
@@ -220,7 +221,7 @@ module Ooor
|
|
220
221
|
|
221
222
|
#overriden because loading default fields is all the rage but we don't want them when reading a record
|
222
223
|
def instantiate_record(record, prefix_options = {}, context = {})
|
223
|
-
new(record, [], context).tap do |resource|
|
224
|
+
new(record, [], context, true).tap do |resource|
|
224
225
|
resource.prefix_options = prefix_options
|
225
226
|
end
|
226
227
|
end
|
@@ -251,7 +252,7 @@ module Ooor
|
|
251
252
|
def reload_from_record!(record) load(record.attributes, record.associations) end
|
252
253
|
|
253
254
|
def load(attributes, associations={})#an attribute might actually be a association too, will be determined here
|
254
|
-
self.class.reload_fields_definition()
|
255
|
+
self.class.reload_fields_definition(false, object_session)
|
255
256
|
raise ArgumentError, "expected an attributes Hash, got #{attributes.inspect}" unless attributes.is_a?(Hash)
|
256
257
|
@prefix_options, attributes = split_options(attributes)
|
257
258
|
@associations = associations
|
@@ -276,8 +277,8 @@ module Ooor
|
|
276
277
|
|
277
278
|
def load_association(model_key, ids, *arguments)
|
278
279
|
options = arguments.extract_options!
|
279
|
-
related_class = self.class.const_get(model_key)
|
280
|
-
related_class.send :find, ids, :fields => options[:fields] || options[:only] || [], :context => options[:context] ||
|
280
|
+
related_class = self.class.const_get(model_key, object_session)
|
281
|
+
related_class.send :find, ids, :fields => options[:fields] || options[:only] || [], :context => options[:context] || object_session
|
281
282
|
end
|
282
283
|
|
283
284
|
def available_fields
|
@@ -290,7 +291,7 @@ module Ooor
|
|
290
291
|
end
|
291
292
|
|
292
293
|
#takes care of reading OpenERP default field values.
|
293
|
-
def initialize(attributes = {}, default_get_list=false, context={})
|
294
|
+
def initialize(attributes = {}, default_get_list=false, context={}, persisted=false)
|
294
295
|
@attributes = {}
|
295
296
|
@prefix_options = {}
|
296
297
|
@ir_model_data_id = attributes.delete(:ir_model_data_id)
|
@@ -299,11 +300,12 @@ module Ooor
|
|
299
300
|
@object_session[:database] = context.delete :database
|
300
301
|
@object_session[:password] = context.delete :password
|
301
302
|
@object_session[:context] = context
|
303
|
+
@persisted = persisted #TODO match 3.1 ActiveResource API
|
302
304
|
if default_get_list == []
|
303
305
|
load(attributes)
|
304
306
|
else
|
305
|
-
self.class.reload_fields_definition()
|
306
|
-
attributes = rpc_execute("default_get", default_get_list || self.class.fields.keys + self.class.associations_keys,
|
307
|
+
self.class.reload_fields_definition(false, object_session)
|
308
|
+
attributes = rpc_execute("default_get", default_get_list || self.class.fields.keys + self.class.associations_keys, object_session[:context]).symbolize_keys!.merge(attributes.symbolize_keys!)
|
307
309
|
load(attributes)
|
308
310
|
end
|
309
311
|
end
|
@@ -317,12 +319,14 @@ module Ooor
|
|
317
319
|
self.id = rpc_execute('create', to_openerp_hash!, context)
|
318
320
|
IrModelData.create(:model => self.class.openerp_model, :module => @ir_model_data_id[0], :name=> @ir_model_data_id[1], :res_id => self.id) if @ir_model_data_id
|
319
321
|
reload_from_record!(self.class.find(self.id, :context => context)) if reload
|
322
|
+
@persisted = true
|
320
323
|
end
|
321
324
|
|
322
325
|
#compatible with the Rails way but also supports OpenERP context
|
323
326
|
def update(context={}, reload=true)
|
324
327
|
rpc_execute('write', [self.id], to_openerp_hash!, context)
|
325
328
|
reload_from_record!(self.class.find(self.id, :context => context)) if reload
|
329
|
+
@persisted = true
|
326
330
|
end
|
327
331
|
|
328
332
|
#compatible with the Rails way but also supports OpenERP context
|
@@ -365,7 +369,7 @@ module Ooor
|
|
365
369
|
|
366
370
|
# fakes associations like much like ActiveRecord according to the cached OpenERP data model
|
367
371
|
def relationnal_result(method_name, *arguments)
|
368
|
-
self.class.reload_fields_definition()
|
372
|
+
self.class.reload_fields_definition(false, object_session)
|
369
373
|
if self.class.many2one_associations.has_key?(method_name)
|
370
374
|
return false unless @associations[method_name]
|
371
375
|
load_association(self.class.many2one_associations[method_name]['relation'], @associations[method_name].is_a?(Integer) && @associations[method_name] || @associations[method_name][0], *arguments)
|
@@ -385,7 +389,7 @@ module Ooor
|
|
385
389
|
method_name = method_symbol.to_s
|
386
390
|
is_assign = method_name.end_with?('=')
|
387
391
|
method_key = method_name.sub('=', '')
|
388
|
-
self.class.reload_fields_definition()
|
392
|
+
self.class.reload_fields_definition(false, object_session)
|
389
393
|
|
390
394
|
if attributes.has_key?(method_key)
|
391
395
|
return super
|
@@ -395,16 +399,16 @@ module Ooor
|
|
395
399
|
result = relationnal_result(method_name, *arguments)
|
396
400
|
@loaded_associations[method_name] = result and return result if result
|
397
401
|
elsif is_assign
|
398
|
-
known_associations = self.class.associations_keys + self.class.many2one_associations.collect {|k, field| self.class.const_get(field['relation']).associations_keys}.flatten
|
402
|
+
known_associations = self.class.associations_keys + self.class.many2one_associations.collect {|k, field| self.class.const_get(field['relation'], object_session).associations_keys}.flatten
|
399
403
|
if known_associations.index(method_key)
|
400
404
|
@associations[method_key] = arguments[0]
|
401
405
|
@loaded_associations[method_key] = arguments[0]
|
402
406
|
return
|
403
407
|
end
|
404
|
-
know_fields = self.class.fields.keys + self.class.many2one_associations.collect {|k, field| self.class.const_get(field['relation']).fields.keys}.flatten
|
408
|
+
know_fields = self.class.fields.keys + self.class.many2one_associations.collect {|k, field| self.class.const_get(field['relation'], object_session).fields.keys}.flatten
|
405
409
|
@attributes[method_key] = arguments[0] and return if know_fields.index(method_key)
|
406
410
|
elsif self.class.fields.has_key?(method_key) || self.class.associations_keys.index(method_name) #unloaded field/association
|
407
|
-
load(rpc_execute('read', [id], [method_key], *arguments)[0] || {})
|
411
|
+
load(rpc_execute('read', [id], [method_key], *arguments || object_session)[0] || {})
|
408
412
|
return method_missing(method_key, *arguments)
|
409
413
|
elsif id #it's an action
|
410
414
|
arguments += [{}] unless arguments.last.is_a?(Hash)
|
data/lib/ooor.rb
CHANGED
@@ -135,7 +135,7 @@ module Ooor
|
|
135
135
|
if Rails.version[0] == "3"[0] #Rails 3 bootstrap
|
136
136
|
class Railtie < Rails::Railtie
|
137
137
|
initializer "ooor.middleware" do |app|
|
138
|
-
Ooor.default_config = Ooor.load_config(false,
|
138
|
+
Ooor.default_config = Ooor.load_config(false, Rails.env)
|
139
139
|
Ooor.default_ooor = Ooor.new(Ooor.default_config) if Ooor.default_config['bootstrap']
|
140
140
|
end
|
141
141
|
end
|
metadata
CHANGED
@@ -2,56 +2,54 @@
|
|
2
2
|
name: ooor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.6.
|
5
|
+
version: 1.6.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
|
-
|
8
|
+
- Raphael Valyi - www.akretion.com
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
14
|
-
default_executable:
|
13
|
+
date: 2011-09-14 00:00:00 Z
|
15
14
|
dependencies:
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: activeresource
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 2.3.5
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: *id001
|
27
26
|
description: OOOR exposes business object proxies to your Ruby (Rails or not) application, that maps seamlessly to your remote OpenObject/OpenERP server using webservices. It extends the standard ActiveResource API. Running on JRuby, OOOR also offers a convenient bridge between OpenERP and the Java eco-system
|
28
27
|
email: rvalyi@akretion.com
|
29
28
|
executables:
|
30
|
-
|
29
|
+
- ooor
|
31
30
|
extensions: []
|
32
31
|
|
33
32
|
extra_rdoc_files: []
|
34
33
|
|
35
34
|
files:
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
has_rdoc: true
|
35
|
+
- README.md
|
36
|
+
- agpl-3.0-licence.txt
|
37
|
+
- lib/ooor.rb
|
38
|
+
- ooor.yml
|
39
|
+
- lib/app/models/open_object_resource.rb
|
40
|
+
- lib/app/models/type_casting.rb
|
41
|
+
- lib/app/models/uml.rb
|
42
|
+
- lib/app/models/base64.rb
|
43
|
+
- lib/app/models/ooor_client.rb
|
44
|
+
- lib/app/models/relation.rb
|
45
|
+
- lib/app/models/db_service.rb
|
46
|
+
- lib/app/models/common_service.rb
|
47
|
+
- lib/app/ui/action_window.rb
|
48
|
+
- lib/app/ui/client_base.rb
|
49
|
+
- lib/app/ui/form_model.rb
|
50
|
+
- lib/app/ui/menu.rb
|
51
|
+
- spec/ooor_spec.rb
|
52
|
+
- bin/ooor
|
55
53
|
homepage: http://github.com/rvalyi/ooor
|
56
54
|
licenses: []
|
57
55
|
|
@@ -59,23 +57,23 @@ post_install_message:
|
|
59
57
|
rdoc_options: []
|
60
58
|
|
61
59
|
require_paths:
|
62
|
-
|
60
|
+
- lib
|
63
61
|
required_ruby_version: !ruby/object:Gem::Requirement
|
64
62
|
none: false
|
65
63
|
requirements:
|
66
|
-
|
67
|
-
|
68
|
-
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: "0"
|
69
67
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
68
|
none: false
|
71
69
|
requirements:
|
72
|
-
|
73
|
-
|
74
|
-
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: "0"
|
75
73
|
requirements: []
|
76
74
|
|
77
75
|
rubyforge_project:
|
78
|
-
rubygems_version: 1.5
|
76
|
+
rubygems_version: 1.8.5
|
79
77
|
signing_key:
|
80
78
|
specification_version: 3
|
81
79
|
summary: OOOR - OpenObject On Ruby
|