ooor 1.4.1 → 1.4.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -44,11 +44,17 @@ But OOOR makes it straightforward to use a standard OpenERP models as your persi
44
44
 
45
45
  An other reason why you might want to use OOOR is because you would like to code essentially a Rails or say web application
46
46
  (because you know it better, because the framework is cleaner or because you will reuse something, possibly Java libraries though JRuby)
47
- but you still want to benefit from OpenERP features.
47
+ but you still want to benefit from OpenERP features. Notice that despite its name OOOR doens't hold a dependency upon Rails anymore.
48
48
 
49
49
  Yet an other typicall use case would be to test your OpenERP application/module using Rails best of bread BDD Ruby frameworks such as RSpec or Cucumber.
50
+ We use RSpec to test OOOR againt OpenERP [here](http://github.com/rvalyi/ooor/blob/master/spec/ooor_spec.rb) and thanks to the initiative of CampToCamp, the OpenERP community tests OpenERP business features extensively
51
+ using Cucumber in [OEPScenario](http://launchpad.net/oerpscenario).
50
52
 
51
- Finally you might also want to use OOOR simply to expose your OpenERP through REST to other consumer applications. Since OOOR just does that too out of the box.
53
+ An other usage of OOOR, is it ability to bridge the OpenERP Python world and and the Java world thanks to its JRuby compatibility. This is especially useful in to do extensive "Data Integration" with OpenERP and benefit from the
54
+ most powerful Java based ETL's. The main project here is [TerminatOOOR](http://github.com/rvalyi/terminatooor), a Pentaho ETL Kettle 4 plugin allowing to push/pull data into/from OpenERP with an incomparable flexibility and yet benefit
55
+ all standard ETL features, including the AgileBI OLAP business intelligence plugin.
56
+
57
+ Finally you might also want to use OOOR simply to expose your OpenERP through REST to other consumer applications using [the OOOREST project](http://github.com/rvalyi/ooorest).
52
58
 
53
59
 
54
60
 
@@ -56,9 +62,9 @@ How?
56
62
  ------------
57
63
 
58
64
  OpenERP is a Python based open source ERP. Every action in OpenERP is actually invokable as a webservice (SOA orientation, close to being RESTful).
59
- OOOR just takes advantage of brings this power your favorite web development tool - Rails - with OpenERP domain objects and business methods.
65
+ OOOR just takes advantage of it.
60
66
 
61
- OOOR aims at being a very simple piece of code (< 500 lines of code; e.g no bug, easy to evolve) adhering to Rails standards.
67
+ OOOR aims at being a very simple piece of code (< 500 lines of code; e.g no bug, [heavility tested](http://github.com/rvalyi/ooor/blob/master/spec/ooor_spec.rb), easy to evolve) adhering to Rails standards.
62
68
  So instead of re-inventing the wheel, OOOR basically just sits on the top of Rails [ActiveResource::Base](http://api.rubyonrails.org/classes/ActiveResource/Base.html), the standard way of remoting you ActiveRecord Rails models with REST.
63
69
 
64
70
  Remember, ActiveResource is actually simpler than [ActiveRecord](http://api.rubyonrails.org/classes/ActiveRecord/Base.html). It's aimed at remoting ANY object model, not necessarily ActiveRecord models.
@@ -66,13 +72,21 @@ So ActiveResource is only a subset of ActiveRecord, sharing the common denominat
66
72
 
67
73
  OOOR implements ActiveResource public API almost fully. It means that you can remotely work on any OpenERP model using [the standard ActiveResource API](http://api.rubyonrails.org/classes/ActiveResource/Base.html).
68
74
 
69
- But, OOOR goes actually a bit further: it does implements model associations (one2many, many2many, many2one, single table inheritance).
75
+ But, OOOR goes actually a bit further: it does implements model associations (one2many, many2many, many2one, single table inheritance, polymorphic associations...).
70
76
  Indeed, when loading the OpenERP models, we load the relational meta-model using OpenERP standard datamodel introspection services.
71
77
  Then we cache that relational model and use it in OpenObjectResource.method_missing to load associations as requested.
72
78
 
73
79
  OOOR also extends ActiveResource a bit with special request parameters (like :domain or :context) that will just map smoothly to the OpenERP native API, see API.
74
80
 
75
81
 
82
+ Trying it simply
83
+ ------------
84
+
85
+ If you have Java 1.6+ installed, then the easiest way to tryout OOOR might be to download the [TerminatOOOR zip](http://github.com/rvalyi/terminatooor/downloads)
86
+ and double-click on jruby-ooor.jar or launch it by command line with java -jar jruby-ooor.jar: it will launch an OOOR console with helpful auto-completion (hit 'tab') on OpenERP business objects.
87
+
88
+
89
+
76
90
  Installation
77
91
  ------------
78
92
 
@@ -95,6 +109,8 @@ Let's test OOOR in an irb console (irb command):
95
109
  This should load all your OpenERP models into Ruby proxy Activeresource objects. Of course there are option to load only some models.
96
110
  Let's try to retrieve the user with id 1:
97
111
  $ ResUsers.find(1)
112
+
113
+ (in case you have an error like "no such file to load -- net/https", then on Debian/Ubuntu, you might need to do before: apt-get install libopenssl-ruby)
98
114
 
99
115
 
100
116
  ### (J)Ruby on Rails application:
@@ -115,8 +131,8 @@ You can then use all the OOOR API upon all loaded OpenERP models in your regular
115
131
  A good way to start playing with OOOR is inside the console, using:
116
132
  $ ruby script/console #or jruby script/console on JRuby of course
117
133
 
118
- Note: when boostraping Ooor in a Rails application, the default Ooor instance is stored in the OOOR constant.
119
- So for instance you can know all loaded models doing OOOR.all_loaded_models; this is used by [OooREST](http://github.com/rvalyi/ooorest) to register all the REST controllers.
134
+ Note: when boostraping Ooor in a Rails application, the default Ooor instance is stored in the Ooor.default_ooor variable.
135
+ So for instance you can know all loaded models doing Ooor.default_ooor variable.loaded_models; this is used by [OooREST](http://github.com/rvalyi/ooorest) to register all the REST controllers.
120
136
 
121
137
  Enabling REST HTTP routes to your OpenERP models:
122
138
  The REST Controller layer of OOOR has been moved as a thin separate gem called [OooREST](http://github.com/rvalyi/ooorest).
@@ -273,7 +289,7 @@ Call old style wizards:
273
289
  $ TODO test and document new osv_memory wizards API
274
290
 
275
291
 
276
- Absolute OpeNERP ids aka ir_model_data:
292
+ Absolute OpenERP ids aka ir_model_data:
277
293
 
278
294
  just like Rails fixtures, OpenERP supports absolute ids for its records, especially those imported from XML or CSV.
279
295
  We are here speaking about the string id of the XML or CSV records, eventually prefixed by the module name.
@@ -40,7 +40,7 @@ class OpenObjectResource < ActiveResource::Base
40
40
  def const_get(model_key)
41
41
  klass_name = class_name_from_model_key(model_key)
42
42
  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)
43
- klass.reload_fields_definition unless klass.fields_defined
43
+ klass.reload_fields_definition()
44
44
  klass
45
45
  end
46
46
 
@@ -175,7 +175,7 @@ class OpenObjectResource < ActiveResource::Base
175
175
  end
176
176
 
177
177
  def cast_answer_to_ruby!(answer)
178
- reload_fields_definition() unless self.fields_defined
178
+ reload_fields_definition()
179
179
 
180
180
  def cast_map_to_ruby!(map)
181
181
  map.each do |k, v|
@@ -219,7 +219,7 @@ class OpenObjectResource < ActiveResource::Base
219
219
  domain.push [k.to_s, '=', v]
220
220
  end
221
221
  end
222
- ids = rpc_execute('search', domain, context)
222
+ ids = rpc_execute('search', domain, options[:offset] || 0, options[:limit] || false, options[:order] || false, context)
223
223
  !ids.empty? && ids[0].is_a?(Integer) && find_single(ids, options) || []
224
224
  end
225
225
 
@@ -324,7 +324,7 @@ class OpenObjectResource < ActiveResource::Base
324
324
  def reload_from_record!(record) load(record.attributes, record.relations) end
325
325
 
326
326
  def load(attributes, relations={})#an attribute might actually be a relation too, will be determined here
327
- self.class.reload_fields_definition() unless self.class.fields_defined
327
+ self.class.reload_fields_definition()
328
328
  raise ArgumentError, "expected an attributes Hash, got #{attributes.inspect}" unless attributes.is_a?(Hash)
329
329
  @prefix_options, attributes = split_options(attributes)
330
330
  @relations = relations
@@ -381,7 +381,8 @@ class OpenObjectResource < ActiveResource::Base
381
381
  if default_get_list == []
382
382
  load(attributes)
383
383
  else
384
- load(rpc_execute("default_get", default_get_list || self.class.fields && self.class.fields.keys || rpc_execute("fields_get").keys, @object_session[:context]).symbolize_keys!.merge(attributes.symbolize_keys!))
384
+ self.class.reload_fields_definition()
385
+ load(rpc_execute("default_get", default_get_list || self.class.fields.keys + self.class.relations_keys, @object_session[:context]).symbolize_keys!.merge(attributes.symbolize_keys!))
385
386
  end
386
387
  end
387
388
 
@@ -398,7 +399,7 @@ class OpenObjectResource < ActiveResource::Base
398
399
 
399
400
  #compatible with the Rails way but also supports OpenERP context
400
401
  def update(context={}, reload=true)
401
- rpc_execute('write', self.id, to_openerp_hash!, context)
402
+ rpc_execute('write', [self.id], to_openerp_hash!, context)
402
403
  reload_from_record!(self.class.find(self.id, :context => context)) if reload
403
404
  end
404
405
 
@@ -442,9 +443,9 @@ class OpenObjectResource < ActiveResource::Base
442
443
  # ******************** fake associations like much like ActiveRecord according to the cached OpenERP data model ********************
443
444
 
444
445
  def relationnal_result(method_name, *arguments)
445
- self.class.reload_fields_definition unless self.class.fields_defined
446
+ self.class.reload_fields_definition()
446
447
  if self.class.many2one_relations.has_key?(method_name)
447
- load_relation(self.class.many2one_relations[method_name]['relation'], @relations[method_name][0], *arguments)
448
+ load_relation(self.class.many2one_relations[method_name]['relation'], @relations[method_name].is_a?(Integer) && @relations[method_name] || @relations[method_name][0], *arguments)
448
449
  elsif self.class.one2many_relations.has_key?(method_name)
449
450
  load_relation(self.class.one2many_relations[method_name]['relation'], @relations[method_name], *arguments)
450
451
  elsif self.class.many2many_relations.has_key?(method_name)
@@ -464,7 +465,7 @@ class OpenObjectResource < ActiveResource::Base
464
465
  return super if attributes.has_key?(method_key)
465
466
  return rpc_execute(method_name, *arguments) unless arguments.empty? || is_assign
466
467
 
467
- self.class.reload_fields_definition() unless self.class.fields_defined
468
+ self.class.reload_fields_definition()
468
469
 
469
470
  if is_assign
470
471
  known_relations = self.class.relations_keys + self.class.many2one_relations.collect {|k, field| self.class.const_get(field['relation']).relations_keys}.flatten
data/spec/ooor_spec.rb CHANGED
@@ -110,6 +110,8 @@ describe Ooor do
110
110
  it "should support OpenERP context in finders" do
111
111
  p = ProductProduct.find(1, :context => {:my_key => 'value'})
112
112
  p.should_not be_nil
113
+ products = ProductProduct.find(:all, :context => {:lang => 'es_ES'})
114
+ products.should be_kind_of(Array)
113
115
  end
114
116
 
115
117
  it "should support OpenERP search method" do
@@ -180,7 +182,7 @@ describe Ooor do
180
182
  it "should support context when instanciating collections" do
181
183
  products = ProductProduct.find([1, 2, 3], :context => {:lang => 'en_US', :user_id=>1, :password => 'admin'})
182
184
  p = products[0]
183
- p.object_session[:context][:lang] .should == 'en_US'
185
+ p.object_session[:context][:lang].should == 'en_US'
184
186
  p.object_session[:user_id].should == 1
185
187
  p.object_session[:password].should == "admin"
186
188
  p.save
@@ -239,6 +241,11 @@ describe Ooor do
239
241
  end
240
242
 
241
243
  describe "Relations assignations" do
244
+ it "should be able to assign many2one relations on new" do
245
+ s = SaleOrder.new(:partner_id => 2)
246
+ s.partner_id.id.should == 2
247
+ end
248
+
242
249
  it "should be able to do product.taxes_id = [1,2]" do
243
250
  p = ProductProduct.find(1)
244
251
  p.taxes_id = [1, 2]
metadata CHANGED
@@ -3,34 +3,35 @@ name: ooor
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
- - 1
7
- - 4
8
- - 1
9
- version: 1.4.1
6
+ - 1
7
+ - 4
8
+ - 2
9
+ version: 1.4.2
10
10
  platform: ruby
11
11
  authors:
12
- - Raphael Valyi - www.akretion.com
12
+ - Raphael Valyi - www.akretion.com
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-07-06 00:00:00 -03:00
17
+ date: 2010-09-15 00:00:00 -03:00
18
18
  default_executable:
19
19
  dependencies:
20
- - !ruby/object:Gem::Dependency
21
- name: activeresource
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- segments:
28
- - 2
29
- - 3
30
- - 1
31
- version: 2.3.1
32
- type: :runtime
33
- version_requirements: *id001
20
+ - !ruby/object:Gem::Dependency
21
+ name: activeresource
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 2
30
+ - 3
31
+ - 1
32
+ version: 2.3.1
33
+ type: :runtime
34
+ version_requirements: *id001
34
35
  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.
35
36
  email: rvalyi@akretion.com
36
37
  executables: []
@@ -40,20 +41,20 @@ extensions: []
40
41
  extra_rdoc_files: []
41
42
 
42
43
  files:
43
- - README.md
44
- - agpl-3.0-licence.txt
45
- - lib/ooor.rb
46
- - ooor.yml
47
- - lib/app/models/open_object_resource.rb
48
- - lib/app/models/uml.rb
49
- - lib/app/models/base64.rb
50
- - lib/app/models/db_service.rb
51
- - lib/app/models/common_service.rb
52
- - lib/app/ui/action_window.rb
53
- - lib/app/ui/client_base.rb
54
- - lib/app/ui/form_model.rb
55
- - lib/app/ui/menu.rb
56
- - spec/ooor_spec.rb
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/uml.rb
50
+ - lib/app/models/base64.rb
51
+ - lib/app/models/db_service.rb
52
+ - lib/app/models/common_service.rb
53
+ - lib/app/ui/action_window.rb
54
+ - lib/app/ui/client_base.rb
55
+ - lib/app/ui/form_model.rb
56
+ - lib/app/ui/menu.rb
57
+ - spec/ooor_spec.rb
57
58
  has_rdoc: true
58
59
  homepage: http://github.com/rvalyi/ooor
59
60
  licenses: []
@@ -62,25 +63,27 @@ post_install_message:
62
63
  rdoc_options: []
63
64
 
64
65
  require_paths:
65
- - lib
66
+ - lib
66
67
  required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
67
69
  requirements:
68
- - - ">="
69
- - !ruby/object:Gem::Version
70
- segments:
71
- - 0
72
- version: "0"
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ segments:
73
+ - 0
74
+ version: "0"
73
75
  required_rubygems_version: !ruby/object:Gem::Requirement
76
+ none: false
74
77
  requirements:
75
- - - ">="
76
- - !ruby/object:Gem::Version
77
- segments:
78
- - 0
79
- version: "0"
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ segments:
81
+ - 0
82
+ version: "0"
80
83
  requirements: []
81
84
 
82
85
  rubyforge_project:
83
- rubygems_version: 1.3.6
86
+ rubygems_version: 1.3.7
84
87
  signing_key:
85
88
  specification_version: 3
86
89
  summary: OOOR - OpenObject On Rails