ooor 1.0.9 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/app/models/open_object_resource.rb +45 -28
- metadata +27 -27
@@ -220,39 +220,52 @@ class OpenObjectResource < ActiveResource::Base
|
|
220
220
|
@attributes.each {|k, v| @attributes[k] = ((v.is_a? BigDecimal) ? Float(v) : v)}
|
221
221
|
end
|
222
222
|
|
223
|
-
def
|
223
|
+
def reload_from_record!(record)
|
224
|
+
load(record.attributes, record.relations)
|
225
|
+
end
|
226
|
+
|
227
|
+
def load(attributes, relations={})
|
224
228
|
self.class.reload_fields_definition unless self.class.field_defined
|
225
229
|
raise ArgumentError, "expected an attributes Hash, got #{attributes.inspect}" unless attributes.is_a?(Hash)
|
226
230
|
@prefix_options, attributes = split_options(attributes)
|
227
|
-
@relations =
|
231
|
+
@relations = relations
|
228
232
|
@loaded_relations = {}
|
229
233
|
attributes.each do |key, value|
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
234
|
+
skey = key.to_s
|
235
|
+
if self.class.many2one_relations.has_key?(skey) || self.class.one2many_relations.has_key?(skey) || self.class.many2many_relations.has_key?(skey)
|
236
|
+
relations[skey] = value #the relation because we want the method to load the association through method missing
|
237
|
+
else
|
238
|
+
case value
|
239
|
+
when self.class.many2one_relations.has_key?(skey) || self.class.one2many_relations.has_key?(skey) || self.class.many2many_relations.has_key?(skey)
|
240
|
+
relations[skey] = value #the relation because we want the method to load the association through method missing
|
241
|
+
when Hash
|
242
|
+
resource = find_or_create_resource_for(key) #TODO check!
|
243
|
+
@attributes[skey] = resource@attributes[skey].new(value)
|
244
|
+
else
|
245
|
+
@attributes[skey] = value.dup rescue value
|
246
|
+
end
|
238
247
|
end
|
239
248
|
end
|
240
249
|
|
241
250
|
self
|
242
251
|
end
|
243
252
|
|
244
|
-
#compatible with the Rails way but also supports OpenERP context
|
253
|
+
#compatible with the Rails way but also supports OpenERP context; TODO: properly pass one2many and many2many object graph like GTK client
|
245
254
|
def create(context={})
|
246
255
|
self.pre_cast_attributes
|
247
|
-
|
248
|
-
|
256
|
+
m2o = @relations.reject{|k, v| !self.class.many2one_relations.has_key?(k)}
|
257
|
+
vals = @attributes.merge(m2o.merge(m2o){|k, v| v.is_a?(Array) ? v[0] : v})
|
258
|
+
self.id = self.class.rpc_execute('create', vals, context)
|
259
|
+
reload_from_record!(self.class.find(self.id, :context => context))
|
249
260
|
end
|
250
261
|
|
251
|
-
#compatible with the Rails way but also supports OpenERP context
|
262
|
+
#compatible with the Rails way but also supports OpenERP context; TODO: properly pass one2many and many2many object graph like GTK client
|
252
263
|
def update(context={})
|
253
264
|
self.pre_cast_attributes
|
254
|
-
|
255
|
-
|
265
|
+
m2o = @relations.reject{|k, v| !self.class.many2one_relations.has_key?(k)}
|
266
|
+
vals = @attributes.reject {|key, value| key == 'id'}.merge(m2o.merge(m2o){|k, v| v.is_a?(Array) ? v[0] : v})
|
267
|
+
self.class.rpc_execute('write', self.id, vals, context)
|
268
|
+
reload_from_record!(self.class.find(self.id, :context => context))
|
256
269
|
end
|
257
270
|
|
258
271
|
#compatible with the Rails way but also supports OpenERP context
|
@@ -281,7 +294,7 @@ class OpenObjectResource < ActiveResource::Base
|
|
281
294
|
#wrapper for OpenERP exec_workflow Business Process Management engine
|
282
295
|
def wkf_action(action, context={})
|
283
296
|
self.class.rpc_exec_workflow(action, self.id) #FIXME looks like OpenERP exec_workflow doesn't accept context but it might be a bug
|
284
|
-
|
297
|
+
reload_from_record!(self.class.find(self.id, :context => context))
|
285
298
|
end
|
286
299
|
|
287
300
|
def old_wizard_step(wizard_name, step='init', wizard_id=nil, form={}, context={})
|
@@ -308,18 +321,22 @@ class OpenObjectResource < ActiveResource::Base
|
|
308
321
|
def method_missing(method_symbol, *arguments)
|
309
322
|
method_name = method_symbol.to_s
|
310
323
|
return @loaded_relations[method_name] if @loaded_relations.has_key?(method_name)
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
324
|
+
if @relations.has_key?(method_name) and !@relations[method_name]
|
325
|
+
return false
|
326
|
+
else
|
327
|
+
result = relationnal_result(method_name, *arguments)
|
328
|
+
if result
|
329
|
+
@loaded_relations[method_name] = result
|
330
|
+
return result
|
331
|
+
elsif @relations and @relations.has_key?(method_name) and !self.class.many2one_relations.empty?
|
332
|
+
#maybe the relation is inherited or could be inferred from a related field
|
333
|
+
self.class.many2one_relations.each do |k, field|
|
334
|
+
model = self.class.load_relation(field.relation, @relations[method_name][0], *arguments)
|
335
|
+
result = model.relationnal_result(method_name, *arguments)
|
336
|
+
return result if result
|
337
|
+
end
|
338
|
+
super
|
321
339
|
end
|
322
|
-
super
|
323
340
|
end
|
324
341
|
super
|
325
342
|
end
|
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.0
|
4
|
+
version: 1.1.0
|
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: 2009-
|
12
|
+
date: 2009-12-16 00:00:00 -02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
|
-
- !ruby/object:Gem::Dependency
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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/controllers/open_objects_controller.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/controllers/open_objects_controller.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
|
-
|
54
|
-
|
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
|
-
|
60
|
-
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: "0"
|
61
61
|
version:
|
62
62
|
requirements: []
|
63
63
|
|