ooor 1.0.8 → 1.0.9

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 CHANGED
@@ -239,6 +239,20 @@ Call aribtrary method:
239
239
 
240
240
  $ use static ObjectClass.rpc_execute_with_all method
241
241
  $ or object.call(method_name, args*) #were args is an aribtrary list of arguments
242
+ $ or use the method missing wrapper that will proxy any OpenERP osv.py/orm.py method, see fo instance:
243
+ $ ResPartner.name_search('ax', [], 'ilike', {})
244
+ $ ProductProduct.fields_view_get(132, 'tree', {})
245
+
246
+
247
+ Call old wizards:
248
+
249
+ $ inv = AccountInvoice.find(4)
250
+ $ wizard = inv.old_wizard_step('account.invoice.pay') #tip: you can inspect the wizard fields, arch and datas
251
+ $ wizard.reconcile({:journal_id => 6, :name =>"from_rails"}) #if you want to pay all; will give you a reloaded invoice
252
+ $ #or if you want a payment with a write off:
253
+ $ wizard.writeoff_check({"amount" => 12, "journal_id" => 6, "name" =>'from_rails'}) #use the button name as the wizard method
254
+ $ wizard.reconcile({required missing write off fields...}) #will give you a reloaded invoice because state is 'end'
255
+ $ TODO test and document new osv_memory wizards API
242
256
 
243
257
 
244
258
  Change logged user:
@@ -1,8 +1,6 @@
1
1
  require 'xmlrpc/client'
2
2
  require 'activeresource'
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
3
+ require 'app/models/open_object_ui'
6
4
 
7
5
  #TODO implement passing session credentials to RPC methods (concurrent access of different user credentials in Rails)
8
6
 
@@ -52,7 +50,7 @@ class OpenObjectResource < ActiveResource::Base
52
50
  logger.info "registering #{model_class_name} as a Rails ActiveResource Model wrapper for OpenObject #{model_key} model"
53
51
  definition = "
54
52
  class #{model_class_name} < OpenObjectResource
55
- self.site = '#{url || Ooor.object_url}'
53
+ self.site = '#{url || Ooor.base_url}'
56
54
  self.user = #{user_id}
57
55
  self.password = #{pass || false}
58
56
  self.openerp_database = '#{database}'
@@ -103,7 +101,7 @@ class OpenObjectResource < ActiveResource::Base
103
101
  args[-1] = Ooor.global_context.merge(args[-1])
104
102
  end
105
103
  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}"
106
- try_with_pretty_error_log { client(@database && @site || Ooor.object_url).call("execute", db, uid, pass, obj, method, *args) }
104
+ try_with_pretty_error_log { client((@database && @site || Ooor.base_url) + "/object").call("execute", db, uid, pass, obj, method, *args) }
107
105
  end
108
106
 
109
107
  #corresponding method for OpenERP osv.exec_workflow(self, db, uid, obj, method, *args)
@@ -120,7 +118,15 @@ class OpenObjectResource < ActiveResource::Base
120
118
  args[-1] = Ooor.global_context.merge(args[-1])
121
119
  end
122
120
  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}"
123
- try_with_pretty_error_log { client(@database && @site || Ooor.object_url).call("exec_workflow", db, uid, pass, obj, action, *args) }
121
+ try_with_pretty_error_log { client((@database && @site || Ooor.base_url) + "/object").call("exec_workflow", db, uid, pass, obj, action, *args) }
122
+ end
123
+
124
+ def old_wizard_step(wizard_name, ids, step='init', wizard_id=nil, form={}, context={}, report_type='pdf')
125
+ context = Ooor.global_context.merge(context)
126
+ unless wizard_id
127
+ wizard_id = try_with_pretty_error_log { 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) }
128
+ end
129
+ [wizard_id, try_with_pretty_error_log { 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, {'model' => @openerp_model, 'form' => form, 'id' => ids[0], 'report_type' => report_type, 'ids' => ids}, step, context) }]
124
130
  end
125
131
 
126
132
  #grab the eventual error log from OpenERP response as OpenERP doesn't enforce carefuly
@@ -140,6 +146,10 @@ class OpenObjectResource < ActiveResource::Base
140
146
  raise
141
147
  end
142
148
 
149
+ def method_missing(method_symbol, *arguments)
150
+ return self.rpc_execute(method_symbol.to_s, *arguments)
151
+ end
152
+
143
153
  def load_relation(model_key, ids, *arguments)
144
154
  options = arguments.extract_options!
145
155
  unless Ooor.all_loaded_models.index(model_key)
@@ -171,7 +181,7 @@ class OpenObjectResource < ActiveResource::Base
171
181
 
172
182
  #TODO, make sense?
173
183
  def find_one
174
- raise "Not implemented yet, go one!"
184
+ raise "Not implemented yet, go on!"
175
185
  end
176
186
 
177
187
  # Find a single resource from the default URL
@@ -274,6 +284,11 @@ class OpenObjectResource < ActiveResource::Base
274
284
  load(self.class.find(self.id, :context => context).attributes)
275
285
  end
276
286
 
287
+ def old_wizard_step(wizard_name, step='init', wizard_id=nil, form={}, context={})
288
+ result = self.class.old_wizard_step(wizard_name, [self.id], step, wizard_id, form, {})
289
+ OpenObjectWizard.new(wizard_name, result[0], result[1], [self])
290
+ end
291
+
277
292
 
278
293
  # ******************** fake associations like much like ActiveRecord according to the cached OpenERP data model ********************
279
294
 
@@ -0,0 +1,44 @@
1
+ class OpenObjectLayoutedFields
2
+ attr_accessor :arch, :fields
3
+
4
+ def initialize(arch, fields)
5
+ @arch = arch
6
+ @fields = fields
7
+ end
8
+ end
9
+
10
+ class OpenObjectWizard < OpenObjectLayoutedFields
11
+ attr_accessor :name, :id, :datas, :arch, :fields, :type, :state, :open_object_resources
12
+
13
+ def initialize(name, id, data, open_object_resources)
14
+ super(data['arch'], data['fields'])
15
+ @name = name
16
+ @id = id
17
+ @open_object_resources = open_object_resources
18
+ @datas = data['datas'].symbolize_keys!
19
+ @type = data['type']
20
+ @state = data['state']
21
+ end
22
+
23
+ def method_missing(method_symbol, *arguments)
24
+ values = @datas.merge((arguments[0] || {}).symbolize_keys!)
25
+ context = Ooor.global_context.merge(arguments[1] || {})
26
+ if @open_object_resources.size == 1
27
+ open_object_resource = @open_object_resources[0]
28
+ data = open_object_resource.class.old_wizard_step(@name, [open_object_resource.id], method_symbol, @id, values, context)
29
+ if data[1]['state'] == 'end'
30
+ return open_object_resource.load(open_object_resource.class.find(open_object_resource.id, :context => context).attributes)
31
+ end
32
+ @arch = data[1]['arch']
33
+ @fields = data[1]['fields']
34
+ @datas = data[1]['datas'].symbolize_keys!
35
+ @type = data[1]['type']
36
+ @state = data[1]['state']
37
+ return self
38
+ else
39
+ ids = @open_object_resources.collect{|open_object_resources| open_object_resources.id}
40
+ return open_object_resource.class.old_wizard_step(@name, ids, method_symbol, @id, values, context)
41
+ end
42
+ end
43
+
44
+ end
@@ -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, :global_context
8
+ attr_accessor :logger, :config, :all_loaded_models, :binding, :base_url, :global_context
9
9
 
10
10
  #load the custom configuration
11
11
  def load_config(config_file=nil, env=nil)
@@ -28,7 +28,7 @@ module Ooor
28
28
  begin
29
29
  Ooor.config[:username] = user
30
30
  Ooor.config[:password] = password
31
- client = OpenObjectResource.client(Ooor.common_url)
31
+ client = OpenObjectResource.client(Ooor.base_url + "/common")
32
32
  OpenObjectResource.try_with_pretty_error_log { client.call("login", Ooor.config[:database], user, password)}
33
33
  rescue SocketError => error
34
34
  Ooor.logger.error """login to OpenERP server failed:
@@ -42,8 +42,7 @@ module Ooor
42
42
  Ooor.config = config.is_a?(Hash) && config or keep_config && Ooor.config or self.load_config(config, env)
43
43
  Ooor.config.symbolize_keys!
44
44
  Ooor.logger.level = Ooor.config[:log_level] if Ooor.config[:log_level]
45
- Ooor.common_url = Ooor.config[:url].gsub(/\/$/,'') + "/common"
46
- Ooor.object_url = Ooor.config[:url].gsub(/\/$/,'') + "/object"
45
+ Ooor.base_url = Ooor.config[:url].gsub(/\/$/,'')
47
46
  Ooor.global_context = Ooor.config[:global_context] || {}
48
47
  Ooor.config[:user_id] = global_login(Ooor.config[:username] || 'admin', Ooor.config[:password] || 'admin')
49
48
 
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.8
4
+ version: 1.0.9
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-11-09 00:00:00 -02:00
12
+ date: 2009-11-23 00:00:00 -02:00
13
13
  default_executable:
14
14
  dependencies:
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:
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,12 +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/controllers/open_objects_controller.rb
39
- - 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
40
41
  has_rdoc: true
41
42
  homepage: http://github.com/rvalyi/ooor
42
43
  licenses: []
@@ -45,18 +46,18 @@ post_install_message:
45
46
  rdoc_options: []
46
47
 
47
48
  require_paths:
48
- - lib
49
+ - lib
49
50
  required_ruby_version: !ruby/object:Gem::Requirement
50
51
  requirements:
51
- - - ">="
52
- - !ruby/object:Gem::Version
53
- version: "0"
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
54
55
  version:
55
56
  required_rubygems_version: !ruby/object:Gem::Requirement
56
57
  requirements:
57
- - - ">="
58
- - !ruby/object:Gem::Version
59
- version: "0"
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: "0"
60
61
  version:
61
62
  requirements: []
62
63