ooor 1.6.1 → 1.6.2
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 +20 -4
- data/lib/app/models/open_object_resource.rb +53 -4
- metadata +3 -3
data/README.md
CHANGED
@@ -294,17 +294,33 @@ You can also create a resource and it's ir_model_data record alltogether using t
|
|
294
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
|
295
295
|
|
296
296
|
|
297
|
+
Obtain report binary data:
|
298
|
+
|
299
|
+
To obtain the binary data of an object report simply use the function get_report_data(report_name). This function returns a list that contains the binary data encoded in base64 and a string with the file format.
|
300
|
+
Example:
|
301
|
+
|
302
|
+
$ inv = AccountInvoice.find(3)
|
303
|
+
$ report = inv.get_report_data('account.invoice') #account.invoice is the service name defined in Invoices report
|
304
|
+
$ #Save the report to a file
|
305
|
+
$ #report[1] contains the file extension and report[0] contains the binary data of the report encoded in base64
|
306
|
+
$ File.open("invoice_report.#{report[1]}", "w") {|f| f.write(Base64.decode64(report[0]))}
|
307
|
+
|
297
308
|
Change logged user:
|
298
309
|
|
310
|
+
An Ooor client can have a global user logged in, to change it:
|
311
|
+
|
299
312
|
$ Ooor.global_login('demo', 'demo')
|
300
313
|
$ s = SaleOrder.find(2)
|
301
314
|
$ => 'Access denied error'
|
302
315
|
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
316
|
+
Instead, every Ooor business objects can also belong to some specific user. To achieve that, generate your object passing
|
317
|
+
proper :user_id and :password parameters inside the context of the method creating the object (typically a find).
|
318
|
+
Notice that methods invoked on an objet use the same credentials as the business objects.
|
319
|
+
Objects generated by this object (by a call to an association for instance) will also have the same credentials.
|
320
|
+
|
321
|
+
$ p = ProductProduct.find(1, :context => {:user_id=>3, :password=>'test'})
|
307
322
|
|
323
|
+
This is tipycally the system you will use in a Ruby (Rails or not) web application.
|
308
324
|
|
309
325
|
Change log level:
|
310
326
|
|
@@ -21,6 +21,7 @@ require 'app/ui/form_model'
|
|
21
21
|
require 'app/models/uml'
|
22
22
|
require 'app/models/type_casting'
|
23
23
|
require 'app/models/relation'
|
24
|
+
require 'app/models/serialization'
|
24
25
|
|
25
26
|
module Ooor
|
26
27
|
class OpenObjectResource < ActiveResource::Base
|
@@ -28,6 +29,7 @@ module Ooor
|
|
28
29
|
#include ActiveModel::Validations
|
29
30
|
include UML
|
30
31
|
include TypeCasting
|
32
|
+
include Serialization
|
31
33
|
|
32
34
|
# ******************** class methods ********************
|
33
35
|
class << self
|
@@ -172,7 +174,44 @@ module Ooor
|
|
172
174
|
raise RuntimeError.new("Invalid RPC method: #{method_symbol}") if [:type!, :allowed!].index(method_symbol)
|
173
175
|
self.rpc_execute(method_symbol.to_s, *arguments)
|
174
176
|
end
|
175
|
-
|
177
|
+
|
178
|
+
#Added methods to obtain report data for a model
|
179
|
+
def report(report_name, ids, report_type='pdf', context={})
|
180
|
+
context = @ooor.global_context.merge(context)
|
181
|
+
params = {'model' => @openerp_model, 'id' => ids[0], 'report_type' => report_type}
|
182
|
+
@ooor.get_rpc_client("#{(@database && @site || @ooor.base_url)}/report").call("report", @database || @ooor.config[:database], @user_id || @ooor.config[:user_id], @password || @ooor.config[:password], report_name, ids, params, context)
|
183
|
+
end
|
184
|
+
|
185
|
+
def report_get(report_id, context={})
|
186
|
+
context = @ooor.global_context.merge(context)
|
187
|
+
@ooor.get_rpc_client("#{(@database && @site || @ooor.base_url)}/report").call("report_get", @database || @ooor.config[:database], @user_id || @ooor.config[:user_id], @password || @ooor.config[:password], report_id)
|
188
|
+
end
|
189
|
+
|
190
|
+
def get_report_data(report_name, ids, report_type='pdf', context={})
|
191
|
+
report_id = self.report(report_name, ids, report_type, context)
|
192
|
+
if report_id
|
193
|
+
state = false
|
194
|
+
attempt = 0
|
195
|
+
while not state
|
196
|
+
report = self.report_get(report_id, context)
|
197
|
+
state = report["state"]
|
198
|
+
attempt = 1
|
199
|
+
if not state
|
200
|
+
sleep(0.1)
|
201
|
+
attempt += 1
|
202
|
+
else
|
203
|
+
return [report["result"],report["format"]]
|
204
|
+
end
|
205
|
+
if attempt > 100
|
206
|
+
logger.debug "OOOR RPC: 'Printing Aborted!'"
|
207
|
+
break
|
208
|
+
end
|
209
|
+
end
|
210
|
+
else
|
211
|
+
logger.debug "OOOR RPC: 'report not found'"
|
212
|
+
end
|
213
|
+
return nil
|
214
|
+
end
|
176
215
|
|
177
216
|
# ******************** finders low level implementation ********************
|
178
217
|
private
|
@@ -239,6 +278,11 @@ module Ooor
|
|
239
278
|
def object_uid; object_session[:user_id] || self.class.user_id || self.class.ooor.config[:user_id]; end
|
240
279
|
def object_pass; object_session[:password] || self.class.password || self.class.ooor.config[:password]; end
|
241
280
|
|
281
|
+
# Ruby 1.9.compat, See also http://tenderlovemaking.com/2011/06/28/til-its-ok-to-return-nil-from-to_ary/
|
282
|
+
def to_ary # :nodoc:
|
283
|
+
nil
|
284
|
+
end
|
285
|
+
|
242
286
|
#try to wrap the object context inside the query.
|
243
287
|
def rpc_execute(method, *args)
|
244
288
|
if args[-1].is_a? Hash
|
@@ -361,8 +405,8 @@ module Ooor
|
|
361
405
|
def old_wizard_step(wizard_name, step='init', wizard_id=nil, form={}, context={})
|
362
406
|
result = self.class.old_wizard_step(wizard_name, [self.id], step, wizard_id, form, {})
|
363
407
|
FormModel.new(wizard_name, result[0], nil, nil, result[1], [self], self.class.ooor.global_context)
|
364
|
-
end
|
365
|
-
|
408
|
+
end
|
409
|
+
|
366
410
|
def log(message, context={}) rpc_execute('log', id, message, context) end
|
367
411
|
|
368
412
|
def type() method_missing(:type) end #skips deprecated Object#type method
|
@@ -415,12 +459,17 @@ module Ooor
|
|
415
459
|
rpc_execute(method_key, [id], *arguments) #we assume that's an action
|
416
460
|
else
|
417
461
|
super
|
418
|
-
end
|
462
|
+
end
|
419
463
|
|
420
464
|
rescue RuntimeError => e
|
421
465
|
e.message << "\n" + available_fields if e.message.index("AttributeError")
|
422
466
|
raise e
|
423
467
|
end
|
468
|
+
|
469
|
+
#Add get_report_data to obtain [report["result"],report["format]] of a concrete openERP Object
|
470
|
+
def get_report_data(report_name, report_type="pdf", context={})
|
471
|
+
self.class.get_report_data(report_name, [self.id], report_type, context)
|
472
|
+
end
|
424
473
|
|
425
474
|
end
|
426
475
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: ooor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.6.
|
5
|
+
version: 1.6.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Raphael Valyi - www.akretion.com
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-09-
|
13
|
+
date: 2011-09-26 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activeresource
|
@@ -73,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
73
|
requirements: []
|
74
74
|
|
75
75
|
rubyforge_project:
|
76
|
-
rubygems_version: 1.8.
|
76
|
+
rubygems_version: 1.8.10
|
77
77
|
signing_key:
|
78
78
|
specification_version: 3
|
79
79
|
summary: OOOR - OpenObject On Ruby
|