ooor 1.5.3 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +9 -0
- data/bin/ooor +1 -1
- data/lib/app/models/common_service.rb +2 -2
- data/lib/app/models/db_service.rb +3 -3
- data/lib/app/models/ooor_client.rb +6 -1
- data/lib/app/models/open_object_resource.rb +4 -10
- data/lib/app/models/type_casting.rb +20 -13
- data/lib/ooor.rb +25 -3
- metadata +42 -54
data/README.md
CHANGED
@@ -159,6 +159,7 @@ Request params or ActiveResource equivalence of OpenERP domain (but degraded as
|
|
159
159
|
OpenERP search method:
|
160
160
|
|
161
161
|
$ ResPartner.search([['name', 'ilike', 'a']], 0, 2)
|
162
|
+
|
162
163
|
Arguments are: domain, offset=0, limit=false, order=false, context={}, count=false
|
163
164
|
|
164
165
|
|
@@ -187,7 +188,9 @@ Load only specific fields support (faster than loading all fields):
|
|
187
188
|
$ ProductProduct.find(:all, :fields=>["state", "id"])
|
188
189
|
$ ProductProduct.find([1,2], :fields=>["state", "id"])
|
189
190
|
$ ProductProduct.find(:all, :fields=>["state", "id"])
|
191
|
+
|
190
192
|
even in relations:
|
193
|
+
|
191
194
|
$ SaleOrder.find(1).order_line(:fields => ["state"])
|
192
195
|
|
193
196
|
|
@@ -243,6 +246,7 @@ On the fly one2many object graph update/creation:
|
|
243
246
|
|
244
247
|
Just like the OpenERP GTK client (and unlike the web client), in OOOR you can pass create/update
|
245
248
|
one2many relation in place directly. For instance:
|
249
|
+
|
246
250
|
$ so = SaleOrder.new
|
247
251
|
$ so.on_change('onchange_partner_id', :partner_id, 1, 1, false) #auto-complete the address and other data based on the partner
|
248
252
|
$ so.order_line = [SaleOrderLine.new(:name => 'sl1', :product_id => 1, :price_unit => 42, :product_uom => 1)] #create one order line
|
@@ -281,9 +285,12 @@ just like Rails fixtures, OpenERP supports absolute ids for its records, especia
|
|
281
285
|
We are here speaking about the string id of the XML or CSV records, eventually prefixed by the module name.
|
282
286
|
Using those ids rather than the SQL ids is a good idea to avoid relying on a particular installation.
|
283
287
|
In OOOR, you can both retrieve one or several records using those ids, like for instance:
|
288
|
+
|
284
289
|
$ ProductCategory.find('product.product_category_3')
|
290
|
+
|
285
291
|
Notice that the 'product.' module prefix is optional here but important if you have similar ids in different module scopes.
|
286
292
|
You can also create a resource and it's ir_model_data record alltogether using the ir_mode_data_id param:
|
293
|
+
|
287
294
|
$ ProductCategory.create(:name => 'rails_categ', :ir_model_data_id =>['product', 'categ_x']) #1st tab element is the module, 2nd the id in the module
|
288
295
|
|
289
296
|
|
@@ -292,6 +299,7 @@ Change logged user:
|
|
292
299
|
$ Ooor.global_login('demo', 'demo')
|
293
300
|
$ s = SaleOrder.find(2)
|
294
301
|
$ => 'Access denied error'
|
302
|
+
|
295
303
|
Notice that this changes the globally logged user and doesn't address the issue of
|
296
304
|
different users using Ooor concurrently with different credentials as you might want
|
297
305
|
for instance in a Rails web application. That second issue will be addressed at
|
@@ -302,6 +310,7 @@ Change log level:
|
|
302
310
|
|
303
311
|
By default the log level is very verbose (debug level) to help newcomers to jumpstart.
|
304
312
|
However you might want to change that. 2 solutions:
|
313
|
+
|
305
314
|
$ Ooor.logger.level = 1 #available levels are those of the standard Ruby Logger class: 0 debug, 1 info, 2 error
|
306
315
|
$ In the config yaml file or hash, set the :log_level parameter
|
307
316
|
|
data/bin/ooor
CHANGED
@@ -21,7 +21,7 @@ module Ooor
|
|
21
21
|
def global_login(user, password)
|
22
22
|
@config[:username] = user
|
23
23
|
@config[:password] = password
|
24
|
-
@config[:user_id] =
|
24
|
+
@config[:user_id] = get_rpc_client(@base_url + "/common").call("login", @config[:database], user, password)
|
25
25
|
rescue Exception => error
|
26
26
|
@logger.error """login to OpenERP server failed:
|
27
27
|
#{error.inspect}
|
@@ -36,7 +36,7 @@ module Ooor
|
|
36
36
|
[:ir_get, :ir_set, :ir_del, :about, :logout, :timezone_get, :get_available_updates, :get_migration_scripts, :get_server_environment, :login_message, :check_connectivity].each do |meth|
|
37
37
|
self.instance_eval do
|
38
38
|
define_method meth do |*args|
|
39
|
-
|
39
|
+
get_rpc_client(@base_url + "/common").call(meth.to_s, *args)
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
@@ -19,7 +19,7 @@
|
|
19
19
|
module Ooor
|
20
20
|
module DbService
|
21
21
|
def create(password=@config[:db_password], db_name='ooor_db', demo=true, lang='en_US', user_password=@config[:password] || 'admin')
|
22
|
-
process_id =
|
22
|
+
process_id = get_rpc_client(@base_url + "/db").call("create", password, db_name, demo, lang, user_password)
|
23
23
|
@config[:database] = db_name
|
24
24
|
@config[:username] = 'admin'
|
25
25
|
@config[:passowrd] = user_password
|
@@ -31,14 +31,14 @@ module Ooor
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def drop(password=@config[:db_password], db_name='ooor_db')
|
34
|
-
|
34
|
+
get_rpc_client(@base_url + "/db").call("drop", password, db_name)
|
35
35
|
end
|
36
36
|
|
37
37
|
#we generate methods handles for use in auto-completion tools such as jirb_swing
|
38
38
|
[:get_progress, :dump, :restore, :rename, :db_exist, :list, :change_admin_password, :list_lang, :server_version, :migrate_databases].each do |meth|
|
39
39
|
self.instance_eval do
|
40
40
|
define_method meth do |*args|
|
41
|
-
|
41
|
+
get_rpc_client(@base_url + "/db").call(meth.to_s, *args)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
@@ -18,7 +18,12 @@
|
|
18
18
|
require 'xmlrpc/client'
|
19
19
|
|
20
20
|
module Ooor
|
21
|
-
class
|
21
|
+
class XMLClient < XMLRPC::Client
|
22
|
+
def self.new2(ooor, url, p, timeout)
|
23
|
+
@ooor = ooor
|
24
|
+
super(url, p, timeout)
|
25
|
+
end
|
26
|
+
|
22
27
|
def call2(method, *args)
|
23
28
|
request = create().methodCall(method, *args)
|
24
29
|
data = (["<?xml version='1.0' encoding='UTF-8'?>\n"] + do_rpc(request, false).lines.to_a[1..-1]).join #encoding is not defined by OpenERP and can lead to bug with Ruby 1.9
|
@@ -19,7 +19,6 @@ require 'rubygems'
|
|
19
19
|
require 'active_resource'
|
20
20
|
require 'app/ui/form_model'
|
21
21
|
require 'app/models/uml'
|
22
|
-
require 'app/models/ooor_client'
|
23
22
|
require 'app/models/type_casting'
|
24
23
|
require 'app/models/relation'
|
25
24
|
|
@@ -113,11 +112,6 @@ module Ooor
|
|
113
112
|
def order(value); relation.order(value); end
|
114
113
|
def offset(value); relation.offset(value); end
|
115
114
|
|
116
|
-
def client(url)
|
117
|
-
@clients ||= {}
|
118
|
-
@clients[url] ||= OOORClient.new2(url, nil, 900)
|
119
|
-
end
|
120
|
-
|
121
115
|
#corresponding method for OpenERP osv.execute(self, db, uid, obj, method, *args, **kw) method
|
122
116
|
def rpc_execute(method, *args)
|
123
117
|
rpc_execute_with_object(@openerp_model, method, *args)
|
@@ -141,7 +135,7 @@ module Ooor
|
|
141
135
|
clean_request_args!(args)
|
142
136
|
reload_fields_definition()
|
143
137
|
logger.debug "OOOR RPC: rpc_method: 'execute', db: #{db}, uid: #{uid}, pass: #, obj: #{obj}, method: #{method}, *args: #{args.inspect}"
|
144
|
-
cast_answer_to_ruby!(
|
138
|
+
cast_answer_to_ruby!(@ooor.get_rpc_client("#{(@database && @site || @ooor.base_url)}/object").call("execute", db, uid, pass, obj, method, *args))
|
145
139
|
end
|
146
140
|
|
147
141
|
#corresponding method for OpenERP osv.exec_workflow(self, db, uid, obj, method, *args)
|
@@ -157,7 +151,7 @@ module Ooor
|
|
157
151
|
clean_request_args!(args)
|
158
152
|
reload_fields_definition()
|
159
153
|
logger.debug "OOOR RPC: 'exec_workflow', db: #{db}, uid: #{uid}, pass: #, obj: #{obj}, action: #{action}, *args: #{args.inspect}"
|
160
|
-
cast_answer_to_ruby!(
|
154
|
+
cast_answer_to_ruby!(@ooor.get_rpc_client("#{(@database && @site || @ooor.base_url)}/object").call("exec_workflow", db, uid, pass, obj, action, *args))
|
161
155
|
end
|
162
156
|
|
163
157
|
def old_wizard_step(wizard_name, ids, step='init', wizard_id=nil, form={}, context={}, report_type='pdf')
|
@@ -165,12 +159,12 @@ module Ooor
|
|
165
159
|
cast_request_to_openerp!(form)
|
166
160
|
unless wizard_id
|
167
161
|
logger.debug "OOOR RPC: 'create old_wizard_step' #{wizard_name}"
|
168
|
-
wizard_id = cast_answer_to_ruby!(
|
162
|
+
wizard_id = cast_answer_to_ruby!(@ooor.get_rpc_client((@database && @site || @ooor.base_url) + "/wizard").call("create", @database || @ooor.config[:database], @user_id || @ooor.config[:user_id], @password || @ooor.config[:password], wizard_name))
|
169
163
|
end
|
170
164
|
params = {'model' => @openerp_model, 'form' => form, 'report_type' => report_type}
|
171
165
|
params.merge!({'id' => ids[0], 'ids' => ids}) if ids
|
172
166
|
logger.debug "OOOR RPC: 'execute old_wizard_step' #{wizard_id}, #{params.inspect}, #{step}, #{context}"
|
173
|
-
[wizard_id, cast_answer_to_ruby!(
|
167
|
+
[wizard_id, cast_answer_to_ruby!(@ooor.get_rpc_client("#{(@database && @site || @ooor.base_url)}/wizard").call("execute", @database || @ooor.config[:database], @user_id || @ooor.config[:user_id], @password || @ooor.config[:password], wizard_id, params, step, context))]
|
174
168
|
end
|
175
169
|
|
176
170
|
def method_missing(method_symbol, *arguments)
|
@@ -25,24 +25,31 @@ module Ooor
|
|
25
25
|
if args[-1].is_a? Hash
|
26
26
|
args[-1] = @ooor.global_context.merge(args[-1])
|
27
27
|
elsif args.is_a?(Array)
|
28
|
+
args.map! {|v| value_to_openerp(v)}
|
28
29
|
args += [@ooor.global_context]
|
29
30
|
end
|
30
|
-
|
31
|
+
cast_map_to_openerp!(args[-2]) if args[-2].is_a? Hash
|
32
|
+
end
|
33
|
+
|
34
|
+
def value_to_openerp(v)
|
35
|
+
if v == nil
|
36
|
+
return false
|
37
|
+
elsif !v.is_a?(Integer) && !v.is_a?(Float) && v.is_a?(Numeric) && v.respond_to?(:to_f)
|
38
|
+
return v.to_f
|
39
|
+
elsif !v.is_a?(Numeric) && !v.is_a?(Integer) && v.respond_to?(:sec) && v.respond_to?(:year)#really ensure that's a datetime type
|
40
|
+
return "#{v.year}-#{v.month}-#{v.day} #{v.hour}:#{v.min}:#{v.sec}"
|
41
|
+
elsif !v.is_a?(Numeric) && !v.is_a?(Integer) && v.respond_to?(:day) && v.respond_to?(:year)#really ensure that's a date type
|
42
|
+
return "#{v.year}-#{v.month}-#{v.day}"
|
43
|
+
elsif v == "false" #may happen with OOORBIT
|
44
|
+
return false
|
45
|
+
else
|
46
|
+
v
|
47
|
+
end
|
31
48
|
end
|
32
49
|
|
33
|
-
def
|
50
|
+
def cast_map_to_openerp!(map)
|
34
51
|
map.each do |k, v|
|
35
|
-
|
36
|
-
map[k] = false
|
37
|
-
elsif !v.is_a?(Integer) && !v.is_a?(Float) && v.is_a?(Numeric) && v.respond_to?(:to_f)
|
38
|
-
map[k] = v.to_f
|
39
|
-
elsif !v.is_a?(Numeric) && !v.is_a?(Integer) && v.respond_to?(:sec) && v.respond_to?(:year)#really ensure that's a datetime type
|
40
|
-
map[k] = "#{v.year}-#{v.month}-#{v.day} #{v.hour}:#{v.min}:#{v.sec}"
|
41
|
-
elsif !v.is_a?(Numeric) && !v.is_a?(Integer) && v.respond_to?(:day) && v.respond_to?(:year)#really ensure that's a date type
|
42
|
-
map[k] = "#{v.year}-#{v.month}-#{v.day}"
|
43
|
-
elsif v == "false" #may happen with OOORBIT
|
44
|
-
map[k] = false
|
45
|
-
end
|
52
|
+
map[k] = value_to_openerp(v)
|
46
53
|
end
|
47
54
|
end
|
48
55
|
|
data/lib/ooor.rb
CHANGED
@@ -49,6 +49,29 @@ module Ooor
|
|
49
49
|
{}
|
50
50
|
end
|
51
51
|
|
52
|
+
def get_rpc_client(url)
|
53
|
+
@rpc_clients ||= {}
|
54
|
+
unless @rpc_clients[url]
|
55
|
+
if defined?(Java) && @config[:rpc_client] != 'ruby'
|
56
|
+
begin
|
57
|
+
require 'jooor'
|
58
|
+
@rpc_clients[url] = get_java_rpc_client(url)
|
59
|
+
rescue LoadError
|
60
|
+
puts "WARNING falling back on Ruby xmlrpc/client client (much slower). Install the 'jooor' gem if you want Java speed for the RPC!"
|
61
|
+
@rpc_clients[url] = get_ruby_rpc_client(url)
|
62
|
+
end
|
63
|
+
else
|
64
|
+
@rpc_clients[url] = get_ruby_rpc_client(url)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
@rpc_clients[url]
|
68
|
+
end
|
69
|
+
|
70
|
+
def get_ruby_rpc_client(url)
|
71
|
+
require 'app/models/ooor_client'
|
72
|
+
XMLClient.new2(self, url, nil, @config[:rpc_timeout] || 900)
|
73
|
+
end
|
74
|
+
|
52
75
|
def initialize(config, env=false)
|
53
76
|
@config = config.is_a?(String) ? Ooor.load_config(config, env) : config
|
54
77
|
@config.symbolize_keys!
|
@@ -72,9 +95,9 @@ module Ooor
|
|
72
95
|
if to_load_models #we load only a customized subset of the OpenERP models
|
73
96
|
model_ids = @ir_model_class.search([['model', 'in', to_load_models]])
|
74
97
|
else #we load all the models
|
75
|
-
model_ids = @ir_model_class.search() - [1]
|
98
|
+
model_ids = @config[:search_models] && @ir_model_class.search() - [1] || @config[:nb_models] || (501.times.map{|i| i}[2..500])
|
76
99
|
end
|
77
|
-
models = @ir_model_class.read(model_ids, ['name', 'model', 'id', 'info', 'state'])#, 'field_id', 'access_ids'])
|
100
|
+
models = @ir_model_class.read(model_ids, ['model'])#['name', 'model', 'id', 'info', 'state'])#, 'field_id', 'access_ids'])
|
78
101
|
@global_context.merge!({}).merge!(@config[:global_context] || {})
|
79
102
|
models.each {|openerp_model| define_openerp_model(openerp_model, @config[:scope_prefix])}
|
80
103
|
end
|
@@ -106,7 +129,6 @@ module Ooor
|
|
106
129
|
@loaded_models.push(klass)
|
107
130
|
klass
|
108
131
|
end
|
109
|
-
|
110
132
|
end
|
111
133
|
|
112
134
|
if defined?(Rails) #Optional autoload in Rails:
|
metadata
CHANGED
@@ -1,64 +1,56 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ooor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 1
|
7
|
-
- 5
|
8
|
-
- 3
|
9
|
-
version: 1.5.3
|
4
|
+
prerelease:
|
5
|
+
version: 1.6.0
|
10
6
|
platform: ruby
|
11
7
|
authors:
|
12
|
-
- Raphael Valyi - www.akretion.com
|
8
|
+
- Raphael Valyi - www.akretion.com
|
13
9
|
autorequire:
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
12
|
|
17
|
-
date: 2011-
|
13
|
+
date: 2011-08-25 00:00:00 -03:00
|
18
14
|
default_executable:
|
19
15
|
dependencies:
|
20
|
-
- !ruby/object:Gem::Dependency
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
- 5
|
32
|
-
version: 2.3.5
|
33
|
-
type: :runtime
|
34
|
-
version_requirements: *id001
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: activeresource
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 2.3.5
|
25
|
+
type: :runtime
|
26
|
+
version_requirements: *id001
|
35
27
|
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
|
36
28
|
email: rvalyi@akretion.com
|
37
29
|
executables:
|
38
|
-
- ooor
|
30
|
+
- ooor
|
39
31
|
extensions: []
|
40
32
|
|
41
33
|
extra_rdoc_files: []
|
42
34
|
|
43
35
|
files:
|
44
|
-
- README.md
|
45
|
-
- agpl-3.0-licence.txt
|
46
|
-
- lib/ooor.rb
|
47
|
-
- ooor.yml
|
48
|
-
- lib/app/models/open_object_resource.rb
|
49
|
-
- lib/app/models/type_casting.rb
|
50
|
-
- lib/app/models/uml.rb
|
51
|
-
- lib/app/models/base64.rb
|
52
|
-
- lib/app/models/ooor_client.rb
|
53
|
-
- lib/app/models/relation.rb
|
54
|
-
- lib/app/models/db_service.rb
|
55
|
-
- lib/app/models/common_service.rb
|
56
|
-
- lib/app/ui/action_window.rb
|
57
|
-
- lib/app/ui/client_base.rb
|
58
|
-
- lib/app/ui/form_model.rb
|
59
|
-
- lib/app/ui/menu.rb
|
60
|
-
- spec/ooor_spec.rb
|
61
|
-
- bin/ooor
|
36
|
+
- README.md
|
37
|
+
- agpl-3.0-licence.txt
|
38
|
+
- lib/ooor.rb
|
39
|
+
- ooor.yml
|
40
|
+
- lib/app/models/open_object_resource.rb
|
41
|
+
- lib/app/models/type_casting.rb
|
42
|
+
- lib/app/models/uml.rb
|
43
|
+
- lib/app/models/base64.rb
|
44
|
+
- lib/app/models/ooor_client.rb
|
45
|
+
- lib/app/models/relation.rb
|
46
|
+
- lib/app/models/db_service.rb
|
47
|
+
- lib/app/models/common_service.rb
|
48
|
+
- lib/app/ui/action_window.rb
|
49
|
+
- lib/app/ui/client_base.rb
|
50
|
+
- lib/app/ui/form_model.rb
|
51
|
+
- lib/app/ui/menu.rb
|
52
|
+
- spec/ooor_spec.rb
|
53
|
+
- bin/ooor
|
62
54
|
has_rdoc: true
|
63
55
|
homepage: http://github.com/rvalyi/ooor
|
64
56
|
licenses: []
|
@@ -67,27 +59,23 @@ post_install_message:
|
|
67
59
|
rdoc_options: []
|
68
60
|
|
69
61
|
require_paths:
|
70
|
-
- lib
|
62
|
+
- lib
|
71
63
|
required_ruby_version: !ruby/object:Gem::Requirement
|
72
64
|
none: false
|
73
65
|
requirements:
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
- 0
|
78
|
-
version: "0"
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: "0"
|
79
69
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
70
|
none: false
|
81
71
|
requirements:
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
- 0
|
86
|
-
version: "0"
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: "0"
|
87
75
|
requirements: []
|
88
76
|
|
89
77
|
rubyforge_project:
|
90
|
-
rubygems_version: 1.
|
78
|
+
rubygems_version: 1.5.1
|
91
79
|
signing_key:
|
92
80
|
specification_version: 3
|
93
81
|
summary: OOOR - OpenObject On Ruby
|