ooor 1.0.6 → 1.0.7
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 +4 -2
- data/lib/app/models/open_object_resource.rb +31 -23
- data/lib/ooor.rb +2 -1
- data/ooor.yml +3 -0
- metadata +2 -2
data/README.md
CHANGED
@@ -113,6 +113,8 @@ That the easiest option to get started while you might not want that in producti
|
|
113
113
|
|
114
114
|
Then just start your Rails application, your OpenERP models will be loaded as you'll see in the Rails log.
|
115
115
|
You can then use all the OOOR API upon all loaded OpenERP models in your regular Rails code (see API usage section).
|
116
|
+
A good way to start playing with OOOR is inside the console, using:
|
117
|
+
$ ruby script/console #or jruby script/console on JRuby of course
|
116
118
|
|
117
119
|
Enabling REST HTTP routes to your OpenERP models:
|
118
120
|
in your config/route.rb, you can alternatively enable routes to all your OpenERP models by addding:
|
@@ -177,7 +179,7 @@ Inherited relations support:
|
|
177
179
|
$ ProductProduct.find(1).categ_id #where categ_id is inherited from the ProductTemplate
|
178
180
|
|
179
181
|
Please notice that loaded relations are cached (to avoid hitting OpenERP over and over)
|
180
|
-
until the root object is reloaded (after save/update for instance)
|
182
|
+
until the root object is reloaded (after save/update for instance).
|
181
183
|
Currently, save/update doesn't save the whole object graph but only the current object.
|
182
184
|
We might change this in the future to match the way OpenERP clients are working which
|
183
185
|
is supported by the OpenERP ORM, see issue: http://github.com/rvalyi/ooor/issues/#issue/3
|
@@ -252,7 +254,7 @@ the API level but it's not easy as ActiveResource has not been designed for it.
|
|
252
254
|
|
253
255
|
Change log level:
|
254
256
|
|
255
|
-
By default the log level is very verbose (debug level) to help newcomers to jumpstart
|
257
|
+
By default the log level is very verbose (debug level) to help newcomers to jumpstart.
|
256
258
|
However you might want to change that. 2 solutions:
|
257
259
|
$ Ooor.logger.level = 1 #available levels are those of the standard Ruby Logger class: 0 debug, 1 info, 2 error
|
258
260
|
$ In the config yaml file or hash, set the :log_level parameter
|
@@ -1,6 +1,11 @@
|
|
1
1
|
require 'xmlrpc/client'
|
2
2
|
require 'activeresource'
|
3
3
|
|
4
|
+
#TODO implement method missing on the OpenObjectResource level and proxy the method upon the RPC client, as done in openerp/tools/rpc.py
|
5
|
+
#in the official web client
|
6
|
+
|
7
|
+
#TODO implement passing session credentials to RPC methods (concurrent access of different user credentials in Rails)
|
8
|
+
|
4
9
|
class OpenObjectResource < ActiveResource::Base
|
5
10
|
|
6
11
|
# ******************** class methods ********************
|
@@ -94,6 +99,9 @@ class OpenObjectResource < ActiveResource::Base
|
|
94
99
|
|
95
100
|
#corresponding method for OpenERP osv.execute(self, db, uid, obj, method, *args, **kw) method
|
96
101
|
def rpc_execute_with_all(db, uid, pass, obj, method, *args)
|
102
|
+
if args[-1].is_a? Hash
|
103
|
+
args[-1] = Ooor.global_context.merge(args[-1])
|
104
|
+
end
|
97
105
|
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}"
|
98
106
|
try_with_pretty_error_log { client(@database && @site || Ooor.object_url).call("execute", db, uid, pass, obj, method, *args) }
|
99
107
|
end
|
@@ -108,6 +116,9 @@ class OpenObjectResource < ActiveResource::Base
|
|
108
116
|
end
|
109
117
|
|
110
118
|
def rpc_exec_workflow_with_all(db, uid, pass, obj, action, *args)
|
119
|
+
if args[-1].is_a? Hash
|
120
|
+
args[-1] = Ooor.global_context.merge(args[-1])
|
121
|
+
end
|
111
122
|
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}"
|
112
123
|
try_with_pretty_error_log { client(@database && @site || Ooor.object_url).call("exec_workflow", db, uid, pass, obj, action, *args) }
|
113
124
|
end
|
@@ -115,7 +126,7 @@ class OpenObjectResource < ActiveResource::Base
|
|
115
126
|
#grab the eventual error log from OpenERP response as OpenERP doesn't enforce carefuly
|
116
127
|
#the XML/RPC spec, see https://bugs.launchpad.net/openerp/+bug/257581
|
117
128
|
def try_with_pretty_error_log
|
118
|
-
|
129
|
+
yield
|
119
130
|
rescue RuntimeError => e
|
120
131
|
begin
|
121
132
|
openerp_error_hash = eval("#{ e }".gsub("wrong fault-structure: ", ""))
|
@@ -173,7 +184,7 @@ class OpenObjectResource < ActiveResource::Base
|
|
173
184
|
scope = [scope]
|
174
185
|
is_collection = false
|
175
186
|
end
|
176
|
-
records = rpc_execute('read', scope,
|
187
|
+
records = rpc_execute('read', scope, fields, context)
|
177
188
|
active_resources = []
|
178
189
|
records.each do |record|
|
179
190
|
r = {}
|
@@ -193,7 +204,7 @@ class OpenObjectResource < ActiveResource::Base
|
|
193
204
|
|
194
205
|
# ******************** instance methods ********************
|
195
206
|
|
196
|
-
attr_accessor :
|
207
|
+
attr_accessor :relations, :loaded_relations
|
197
208
|
|
198
209
|
def pre_cast_attributes
|
199
210
|
@attributes.each {|k, v| @attributes[k] = ((v.is_a? BigDecimal) ? Float(v) : v)}
|
@@ -203,6 +214,8 @@ class OpenObjectResource < ActiveResource::Base
|
|
203
214
|
self.class.reload_fields_definition unless self.class.field_defined
|
204
215
|
raise ArgumentError, "expected an attributes Hash, got #{attributes.inspect}" unless attributes.is_a?(Hash)
|
205
216
|
@prefix_options, attributes = split_options(attributes)
|
217
|
+
@relations = {}
|
218
|
+
@loaded_relations = {}
|
206
219
|
attributes.each do |key, value|
|
207
220
|
case value
|
208
221
|
when Array
|
@@ -264,36 +277,31 @@ class OpenObjectResource < ActiveResource::Base
|
|
264
277
|
|
265
278
|
# ******************** fake associations like much like ActiveRecord according to the cached OpenERP data model ********************
|
266
279
|
|
267
|
-
def
|
268
|
-
@relations ||= {} and @relations
|
269
|
-
end
|
270
|
-
|
271
|
-
def relationnal_result(method_id, *arguments)
|
280
|
+
def relationnal_result(method_name, *arguments)
|
272
281
|
self.class.reload_fields_definition unless self.class.field_defined
|
273
|
-
if self.class.many2one_relations
|
274
|
-
self.class.load_relation(self.class.many2one_relations[
|
275
|
-
elsif self.class.one2many_relations
|
276
|
-
self.class.load_relation(self.class.one2many_relations[
|
277
|
-
elsif self.class.many2many_relations
|
278
|
-
self.class.load_relation(self.class.many2many_relations[
|
282
|
+
if self.class.many2one_relations.has_key?(method_name)
|
283
|
+
self.class.load_relation(self.class.many2one_relations[method_name].relation, @relations[method_name][0], *arguments)
|
284
|
+
elsif self.class.one2many_relations.has_key?(method_name)
|
285
|
+
self.class.load_relation(self.class.one2many_relations[method_name].relation, @relations[method_name], *arguments)
|
286
|
+
elsif self.class.many2many_relations.has_key?(method_name)
|
287
|
+
self.class.load_relation(self.class.many2many_relations[method_name].relation, @relations[method_name], *arguments)
|
279
288
|
else
|
280
289
|
false
|
281
290
|
end
|
282
291
|
end
|
283
292
|
|
284
|
-
def method_missing(
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
result = relationnal_result(method_id, *arguments)
|
293
|
+
def method_missing(method_symbol, *arguments)
|
294
|
+
method_name = method_symbol.to_s
|
295
|
+
return @loaded_relations[method_name] if @loaded_relations.has_key?(method_name)
|
296
|
+
result = relationnal_result(method_name, *arguments)
|
289
297
|
if result
|
290
|
-
@loaded_relations[
|
298
|
+
@loaded_relations[method_name] = result
|
291
299
|
return result
|
292
|
-
elsif @relations and @relations
|
300
|
+
elsif @relations and @relations.has_key?(method_name) and !self.class.many2one_relations.empty?
|
293
301
|
#maybe the relation is inherited or could be inferred from a related field
|
294
302
|
self.class.many2one_relations.each do |k, field|
|
295
|
-
model = self.class.load_relation(field.relation, @relations[
|
296
|
-
result = model.relationnal_result(
|
303
|
+
model = self.class.load_relation(field.relation, @relations[method_name][0], *arguments)
|
304
|
+
result = model.relationnal_result(method_name, *arguments)
|
297
305
|
return result if result
|
298
306
|
end
|
299
307
|
super
|
data/lib/ooor.rb
CHANGED
@@ -5,7 +5,7 @@ module Ooor
|
|
5
5
|
|
6
6
|
class << self
|
7
7
|
|
8
|
-
attr_accessor :logger, :config, :all_loaded_models, :binding, :common_url, :object_url
|
8
|
+
attr_accessor :logger, :config, :all_loaded_models, :binding, :common_url, :object_url, :global_context
|
9
9
|
|
10
10
|
#load the custom configuration
|
11
11
|
def load_config(config_file=nil, env=nil)
|
@@ -44,6 +44,7 @@ module Ooor
|
|
44
44
|
Ooor.logger.level = Ooor.config[:log_level] if Ooor.config[:log_level]
|
45
45
|
Ooor.common_url = Ooor.config[:url].gsub(/\/$/,'') + "/common"
|
46
46
|
Ooor.object_url = Ooor.config[:url].gsub(/\/$/,'') + "/object"
|
47
|
+
Ooor.global_context = Ooor.config[:global_context] || {}
|
47
48
|
Ooor.config[:user_id] = global_login(Ooor.config[:username] || 'admin', Ooor.config[:password] || 'admin')
|
48
49
|
|
49
50
|
#*************** load the models
|
data/ooor.yml
CHANGED
@@ -9,6 +9,9 @@ development:
|
|
9
9
|
#comment the following line if you want to load ALL the available models (slower startup), or complete it with all the OpenERP models you want to be loaded
|
10
10
|
models: [res.partner, product.template, product.product, product.category, sale.order, sale.order.line, account.invoice]
|
11
11
|
bootstrap: true #true if you want to load OpenObject models (will hit OpenERP server) at startup; else use Ooor.reload!(lambda {}) to reload the Ooor models at any time
|
12
|
+
#log_level: 0
|
13
|
+
#global_context:
|
14
|
+
#'lang': en_US
|
12
15
|
|
13
16
|
test:
|
14
17
|
url: http://localhost:8069/xmlrpc
|
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.0.
|
4
|
+
version: 1.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Raphael Valyi - www.akretion.com
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
12
|
+
date: 2009-11-09 00:00:00 -02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|