ooor 1.2.6 → 1.2.7

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -273,6 +273,18 @@ Call old style wizards:
273
273
  $ TODO test and document new osv_memory wizards API
274
274
 
275
275
 
276
+ Absolute OpeNERP ids aka ir_model_data:
277
+
278
+ just like Rails fixtures, OpenERP supports absolute ids for its records, especially those imported from XML or CSV.
279
+ We are here speaking about the string id of the XML or CSV records, eventually prefixed by the module name.
280
+ Using those ids rather than the SQL ids is a good idea to avoid relying on a particular installation.
281
+ In OOOR, you can both retrieve one or several records using those ids, like for instance:
282
+ $ ProductCategory.find('product.product_category_3')
283
+ Notice that the 'product.' module prefix is optional here but important if you have similar ids in different module scopes.
284
+ You can also create a resource and it's ir_model_data record alltogether using the ir_mode_data_id param:
285
+ $ ProductCategory.create(:name => 'rails_categ', :ir_model_data_id =>['product', 'categ_x']) #1st tab element is the module, 2nd the id in the module
286
+
287
+
276
288
  Change logged user:
277
289
 
278
290
  $ Ooor.global_login('demo', 'demo')
@@ -112,16 +112,12 @@ class OpenObjectResource < ActiveResource::Base
112
112
  rescue RuntimeError => e
113
113
  begin
114
114
  openerp_error_hash = eval("#{ e }".gsub("wrong fault-structure: ", ""))
115
- if openerp_error_hash.is_a? Hash
116
- logger.error "*********** OpenERP Server ERROR:
117
- #{openerp_error_hash["faultString"]}***********"
118
- e.backtrace.each {|line| logger.error line unless line.index("lib/ruby")} and return nil
119
- else
120
- raise
121
- end
122
- rescue
123
- raise
115
+ rescue SyntaxError
116
+ raise e
124
117
  end
118
+ raise e unless openerp_error_hash.is_a? Hash
119
+ logger.error "*********** OpenERP Server ERROR:\n#{openerp_error_hash["faultString"]}***********"
120
+ raise RuntimeError.new('OpenERP server error')
125
121
  end
126
122
 
127
123
  def clean_request_args!(args)
@@ -170,7 +166,10 @@ class OpenObjectResource < ActiveResource::Base
170
166
  end
171
167
  end
172
168
 
173
- def method_missing(method_symbol, *arguments) self.rpc_execute(method_symbol.to_s, *arguments) end
169
+ def method_missing(method_symbol, *arguments)
170
+ raise RuntimeError.new("Invalid RPC method: #{method_symbol}") if [:type!, :allowed!].index(method_symbol)
171
+ self.rpc_execute(method_symbol.to_s, *arguments)
172
+ end
174
173
 
175
174
 
176
175
  # ******************** finders low level implementation ********************
@@ -200,10 +199,18 @@ class OpenObjectResource < ActiveResource::Base
200
199
  context = options[:context] || {}
201
200
  prefix_options, query_options = split_options(options[:params])
202
201
  is_collection = true
203
- if !scope.is_a? Array
204
- scope = [scope]
205
- is_collection = false
206
- end
202
+ scope = [scope] and is_collection = false if !scope.is_a? Array
203
+ scope.map! do |item|
204
+ if item.is_a? String #triggers ir_model_data absolute reference lookup
205
+ tab = item.split(".")
206
+ domain = [['name', '=', tab[-1]]]
207
+ domain += [['module', '=', tab[-2]]] if tab[-2]
208
+ ir_model_data = IrModelData.find(:first, :domain => domain)
209
+ ir_model_data && ir_model_data.res_id && search([['id', '=', ir_model_data.res_id]])[0]
210
+ else
211
+ item
212
+ end
213
+ end.reject! {|item| !item}
207
214
  records = rpc_execute('read', scope, fields, context)
208
215
  active_resources = []
209
216
  records.each do |record|
@@ -231,7 +238,7 @@ class OpenObjectResource < ActiveResource::Base
231
238
 
232
239
  # ******************** instance methods ********************
233
240
 
234
- attr_accessor :relations, :loaded_relations
241
+ attr_accessor :relations, :loaded_relations, :ir_model_data_id
235
242
 
236
243
  def cast_relations_to_openerp!
237
244
  @relations.reject! do |k, v| #reject non asigned many2one or empty list
@@ -327,6 +334,7 @@ class OpenObjectResource < ActiveResource::Base
327
334
  def initialize(attributes = {}, default_get_list=false, context={})
328
335
  @attributes = {}
329
336
  @prefix_options = {}
337
+ @ir_model_data_id = attributes.delete(:ir_model_data_id)
330
338
  if ['ir.model', 'ir.model.fields'].index(self.class.openerp_model) || default_get_list == []
331
339
  load(attributes)
332
340
  else
@@ -337,20 +345,21 @@ class OpenObjectResource < ActiveResource::Base
337
345
  end
338
346
 
339
347
  #compatible with the Rails way but also supports OpenERP context
340
- def create(context={})
348
+ def create(context={}, reload=true)
341
349
  self.id = self.class.rpc_execute('create', to_openerp_hash!, context)
342
- reload_from_record!(self.class.find(self.id, :context => context))
350
+ IrModelData.create(:model => self.class.openerp_model, :module => @ir_model_data_id[0], :name=> @ir_model_data_id[1], :res_id => self.id) if @ir_model_data_id
351
+ reload_from_record!(self.class.find(self.id, :context => context)) if reload
343
352
  end
344
353
 
345
354
  #compatible with the Rails way but also supports OpenERP context
346
- def update(context={})
355
+ def update(context={}, reload=true)
347
356
  self.class.rpc_execute('write', self.id, to_openerp_hash!, context)
348
- reload_from_record!(self.class.find(self.id, :context => context))
357
+ reload_from_record!(self.class.find(self.id, :context => context)) if reload
349
358
  end
350
359
 
351
360
  #compatible with the Rails way but also supports OpenERP context
352
361
  def destroy(context={})
353
- self.class.rpc_execute('unlink', self.id, context)
362
+ self.class.rpc_execute('unlink', [self.id], context)
354
363
  end
355
364
 
356
365
  #OpenERP copy method, load persisted copied Object
@@ -423,7 +432,9 @@ class OpenObjectResource < ActiveResource::Base
423
432
  return @loaded_relations[method_name] if @loaded_relations.has_key?(method_name)
424
433
  return false if @relations.has_key?(method_name) and (!@relations[method_name] || @relations[method_name].is_a?(Array) && !@relations[method_name][0])
425
434
 
426
- return false if self.class.relations_keys.index(method_name) && !@relations[method_name]
435
+ if self.class.relations_keys.index(method_name) && !@relations[method_name]
436
+ return self.class.many2one_relations.index(method_name) ? nil : []
437
+ end
427
438
  result = relationnal_result(method_name, *arguments)
428
439
  @loaded_relations[method_name] = result and return result if result
429
440
 
@@ -49,6 +49,7 @@ class Ooor
49
49
  OpenObjectResource.logger = @logger
50
50
  @ir_model_class = define_openerp_model("ir.model", nil, nil, nil, nil, config[:scope_prefix])
51
51
  define_openerp_model("ir.model.fields", nil, nil, nil, nil, config[:scope_prefix])
52
+ define_openerp_model("ir.model.data", nil, nil, nil, nil, config[:scope_prefix])
52
53
 
53
54
  if config[:models] #we load only a customized subset of the OpenERP models
54
55
  models = @ir_model_class.find(:all, :domain => [['model', 'in', config[:models]]])
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.2.6
4
+ version: 1.2.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: 2010-02-18 00:00:00 -02:00
12
+ date: 2010-02-24 00:00:00 -03:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency