ooor 1.9.0 → 1.9.1
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 +27 -16
- data/lib/ooor.rb +2 -1
- data/spec/ooor_spec.rb +1 -1
- metadata +2 -2
@@ -24,10 +24,19 @@ module Ooor
|
|
24
24
|
class << self
|
25
25
|
|
26
26
|
cattr_accessor :logger
|
27
|
-
attr_accessor :openerp_id, :info, :access_ids, :name, :openerp_model, :field_ids, :state, #
|
27
|
+
attr_accessor :openerp_id, :info, :access_ids, :name, :description, :openerp_model, :field_ids, :state, #class attributes associated to the OpenERP ir.model
|
28
28
|
:fields, :fields_defined, :many2one_associations, :one2many_associations, :many2many_associations, :polymorphic_m2o_associations, :associations_keys,
|
29
29
|
:database, :user_id, :scope_prefix, :ooor, :association
|
30
30
|
|
31
|
+
def model_name
|
32
|
+
@_model_name ||= begin
|
33
|
+
namespace = self.parents.detect do |n|
|
34
|
+
n.respond_to?(:use_relative_model_naming?) && n.use_relative_model_naming?
|
35
|
+
end
|
36
|
+
ActiveModel::Name.new(self, namespace, description)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
31
40
|
def print_uml(options={})
|
32
41
|
UML.print_uml([self], options)
|
33
42
|
end
|
@@ -231,9 +240,10 @@ module Ooor
|
|
231
240
|
|
232
241
|
#actually finds many resources specified with scope = ids_array
|
233
242
|
def find_single(scope, options)
|
243
|
+
context = options[:context] || {}
|
244
|
+
reload_fields_definition(false, context)
|
234
245
|
all_fields = @fields.merge(@many2one_associations).merge(@one2many_associations).merge(@many2many_associations).merge(@polymorphic_m2o_associations)
|
235
246
|
fields = options[:fields] || options[:only] || all_fields.keys.select {|k| all_fields[k]["type"] != "binary" && (options[:include_functions] || !all_fields[k]["function"])}
|
236
|
-
context = options[:context] || {}
|
237
247
|
# prefix_options, query_options = split_options(options[:params])
|
238
248
|
is_collection = true
|
239
249
|
scope = [scope] and is_collection = false if !scope.is_a? Array
|
@@ -292,33 +302,34 @@ module Ooor
|
|
292
302
|
self.class.rpc_execute_with_all(object_db, object_uid, object_pass, self.class.openerp_model, method, *args)
|
293
303
|
end
|
294
304
|
|
295
|
-
def reload_from_record!(record) load(record.attributes
|
305
|
+
def reload_from_record!(record) load(record.attributes.merge(record.associations)) end
|
296
306
|
|
297
|
-
def load(attributes,
|
307
|
+
def load(attributes, remove_root=false)#an attribute might actually be a association too, will be determined here
|
298
308
|
self.class.reload_fields_definition(false, object_session)
|
299
309
|
raise ArgumentError, "expected an attributes Hash, got #{attributes.inspect}" unless attributes.is_a?(Hash)
|
300
310
|
@prefix_options, attributes = split_options(attributes)
|
301
|
-
@associations
|
302
|
-
@attributes
|
311
|
+
@associations ||= {}
|
312
|
+
@attributes ||= {}
|
303
313
|
@loaded_associations = {}
|
304
314
|
attributes.each do |key, value|
|
305
315
|
skey = key.to_s
|
306
|
-
if self.class.associations_keys.index(skey) || value.is_a?(Array)
|
307
|
-
associations[skey] = value #the association because we want the method to load the association through method missing
|
316
|
+
if self.class.associations_keys.index(skey) || value.is_a?(Array) #FIXME may miss m2o with inherits!
|
317
|
+
@associations[skey] = value #the association because we want the method to load the association through method missing
|
308
318
|
else
|
309
|
-
@attributes[skey] = value
|
319
|
+
@attributes[skey] = (value == false)? nil : value
|
310
320
|
end
|
311
321
|
end
|
312
322
|
self
|
313
323
|
end
|
314
324
|
|
315
325
|
def available_fields
|
316
|
-
msg = "\n*** AVAILABLE FIELDS ON
|
326
|
+
msg = "\n*** AVAILABLE FIELDS ON #{self.class.name} ARE: ***"
|
317
327
|
msg << "\n\n" << self.class.fields.sort {|a,b| a[1]['type']<=>b[1]['type']}.map {|i| "#{i[1]['type']} --- #{i[0]}"}.join("\n")
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
328
|
+
%w[many2one one2many many2many polymorphic_m2o].each do |kind|
|
329
|
+
msg << "\n\n"
|
330
|
+
msg << (self.class.send "#{kind}_associations").map {|k, v| "{kind} --- #{v['relation']} --- #{k}"}.join("\n")
|
331
|
+
end
|
332
|
+
msg
|
322
333
|
end
|
323
334
|
|
324
335
|
#takes care of reading OpenERP default field values.
|
@@ -381,7 +392,7 @@ module Ooor
|
|
381
392
|
self.class.logger.info result["warning"]["title"]
|
382
393
|
self.class.logger.info result["warning"]["message"]
|
383
394
|
end
|
384
|
-
load(@attributes.merge({field_name => field_value}).merge(result["value"])
|
395
|
+
load(@attributes.merge({field_name => field_value}).merge(result["value"]))
|
385
396
|
end
|
386
397
|
|
387
398
|
#wrapper for OpenERP exec_workflow Business Process Management engine
|
@@ -468,7 +479,7 @@ module Ooor
|
|
468
479
|
end
|
469
480
|
|
470
481
|
def reload_fields(context)
|
471
|
-
records = self.class.find(self.id, :context => context, :fields => @attributes.keys)
|
482
|
+
records = self.class.find(self.id, :context => context, :fields => @attributes.keys + @associations.keys)
|
472
483
|
reload_from_record!(records)
|
473
484
|
end
|
474
485
|
end
|
data/lib/ooor.rb
CHANGED
@@ -98,7 +98,7 @@ module Ooor
|
|
98
98
|
([File.dirname(__FILE__) + '/app/helpers/*'] + (@config[:helper_paths] || [])).each {|dir| Dir[dir].each { |file| require file }}
|
99
99
|
@ir_model_class = define_openerp_model({'model' => 'ir.model'}, @config[:scope_prefix])
|
100
100
|
model_ids = model_names && @ir_model_class.search([['model', 'in', model_names]]) || @ir_model_class.search() - [1]
|
101
|
-
models = @ir_model_class.read(model_ids, ['model'])#['name', 'model', 'id', 'info', 'state', 'field_id', 'access_ids'])
|
101
|
+
models = @ir_model_class.read(model_ids, ['model', 'name'])#['name', 'model', 'id', 'info', 'state', 'field_id', 'access_ids'])
|
102
102
|
@global_context.merge!({}).merge!(@config[:global_context] || {}) #TODO ensure it's required
|
103
103
|
models.each {|openerp_model| define_openerp_model(openerp_model, @config[:scope_prefix], nil, nil, nil, nil, reload)}
|
104
104
|
end
|
@@ -117,6 +117,7 @@ module Ooor
|
|
117
117
|
klass.openerp_id = url || param['id']
|
118
118
|
klass.info = (param['info'] || '').gsub("'",' ')
|
119
119
|
klass.name = model_class_name
|
120
|
+
klass.description = param['name']
|
120
121
|
klass.state = param['state']
|
121
122
|
#klass.field_ids = param['field_id']
|
122
123
|
#klass.access_ids = param['access_ids']
|
data/spec/ooor_spec.rb
CHANGED
@@ -9,7 +9,7 @@ require File.dirname(__FILE__) + '/../lib/ooor'
|
|
9
9
|
#Run the file with the rspec command from the rspec gem
|
10
10
|
describe Ooor do
|
11
11
|
before(:all) do
|
12
|
-
@url = 'http://localhost:
|
12
|
+
@url = 'http://localhost:8169/xmlrpc'
|
13
13
|
@db_password = 'admin'
|
14
14
|
@username = 'admin'
|
15
15
|
@password = 'admin'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ooor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.9.
|
4
|
+
version: 1.9.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-05-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activeresource
|