Class: Ooor::Base

Overview

the base class for proxies to OpenERP objects

Constant Summary

Constants included from Callbacks

Callbacks::CALLBACKS

Constants included from TypeCasting

TypeCasting::BLACKLIST, TypeCasting::OPERATORS

Class Attribute Summary collapse

Instance Attribute Summary collapse

Attributes included from FieldMethods

#_display_name

Attributes inherited from MiniActiveResource

#attributes, #id

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Persistence

#copy, #delete, #destroy, #destroy!, #destroyed?, #initialize, #load, #save, #save!, #update, #update!, #update_attribute, #valid?

Methods included from Associations

#relationnal_result

Methods included from FieldMethods

#_destroy, #_destroy=, #get_association, #get_attribute, #lazy_load, #method_missing, #set_association, #set_attribute

Methods included from AutosaveAssociation

#changed_for_autosave?, #destroyed_by_association, #destroyed_by_association=, #mark_for_destruction, #marked_for_destruction?, #reload

Methods included from Naming

#to_param

Methods included from TypeCasting

#cast_association, #cast_m2o_association, #cast_o2m_association, #cast_o2m_nested_attributes, #get_changed_values, #sanitize_association, #sanitize_association_as_string, #sanitize_attribute, #sanitize_m2o_association, #to_openerp_hash

Methods included from Serialization

#serializable_hash, #serialize_many2one, #serialize_x_to_many

Methods included from ReflectionOoor

#column_for_attribute, #has_attribute?

Methods inherited from MiniActiveResource

element_name, #errors, #new?, #persisted?, #reload, #to_json, #to_xml

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Ooor::FieldMethods

Class Attribute Details

.nameObject

Returns the value of attribute name.



23
24
25
# File 'lib/ooor/base.rb', line 23

def name
  @name
end

.scope_prefixObject

Returns the value of attribute scope_prefix.



23
24
25
# File 'lib/ooor/base.rb', line 23

def scope_prefix
  @scope_prefix
end

.sessionObject

Returns the value of attribute session.



23
24
25
# File 'lib/ooor/base.rb', line 23

def session
  @session
end

.tObject

Returns the value of attribute t.



23
24
25
# File 'lib/ooor/base.rb', line 23

def t
  @t
end

Instance Attribute Details

#associationsObject

********************** instance methods **********************************



87
88
89
# File 'lib/ooor/base.rb', line 87

def associations
  @associations
end

#ir_model_data_idObject

********************** instance methods **********************************



87
88
89
# File 'lib/ooor/base.rb', line 87

def ir_model_data_id
  @ir_model_data_id
end

#loaded_associationsObject

********************** instance methods **********************************



87
88
89
# File 'lib/ooor/base.rb', line 87

def loaded_associations
  @loaded_associations
end

Class Method Details

.all(*args) ⇒ Object



66
# File 'lib/ooor/base.rb', line 66

def all(*args); relation.all(*args); end

.contextObject



54
55
56
# File 'lib/ooor/base.rb', line 54

def context
  session.session_context
end

.first(*args) ⇒ Object



70
# File 'lib/ooor/base.rb', line 70

def first(*args); relation.first(*args); end

.includes(*args) ⇒ Object



72
# File 'lib/ooor/base.rb', line 72

def includes(*args); relation.includes(*args); end

.last(*args) ⇒ Object



71
# File 'lib/ooor/base.rb', line 71

def last(*args); relation.last(*args); end

.limit(value) ⇒ Object



67
# File 'lib/ooor/base.rb', line 67

def limit(value); relation.limit(value); end

.loggerObject



75
# File 'lib/ooor/base.rb', line 75

def logger; Ooor.logger; end

.method_missing(method_symbol, *args) ⇒ Object

Raises:

  • (RuntimeError)


58
59
60
61
# File 'lib/ooor/base.rb', line 58

def method_missing(method_symbol, *args)
  raise RuntimeError.new("Invalid RPC method:  #{method_symbol}") if [:type!, :allowed!].index(method_symbol)
  self.rpc_execute(method_symbol.to_s, *args)
end

.name_search(name = '', domain = [], operator = 'ilike', limit = 100, context = {}) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/ooor/base.rb', line 33

def name_search(name='', domain=[], operator='ilike', limit=100, context={})
  if session.odoo_serie < 10
    rpc_execute(:name_search, name, to_openerp_domain(domain), operator, context, limit)
  else
    rpc_execute(:name_search, name, to_openerp_domain(domain), operator, limit)
  end
end

.object_service(service, obj, method, *args) ⇒ Object



49
50
51
52
# File 'lib/ooor/base.rb', line 49

def object_service(service, obj, method, *args)
  reload_fields_definition(false)
  cast_answer_to_ruby!(session.object.object_service(service, obj, method, *cast_request_to_openerp(args)))
end

.offset(value) ⇒ Object



69
# File 'lib/ooor/base.rb', line 69

def offset(value); relation.offset(value); end

.order(value) ⇒ Object



68
# File 'lib/ooor/base.rb', line 68

def order(value); relation.order(value); end

.rpc_exec_workflow(action, *args) ⇒ Object



45
46
47
# File 'lib/ooor/base.rb', line 45

def rpc_exec_workflow(action, *args)
  object_service(:exec_workflow, openerp_model, action, *args)
end

.rpc_execute(method, *args) ⇒ Object



41
42
43
# File 'lib/ooor/base.rb', line 41

def rpc_execute(method, *args)
  object_service(:execute, openerp_model, method, *args)
end

.search(domain = [], offset = 0, limit = false, order = false, context = {}, count = false) ⇒ Object

OpenERP search method



29
30
31
# File 'lib/ooor/base.rb', line 29

def search(domain=[], offset=0, limit=false, order=false, context={}, count=false)
  rpc_execute(:search, to_openerp_domain(domain), offset, limit, order, context, count)
end

.where(opts, *rest) ⇒ Object

******************** AREL Minimal implementation ***********************



65
# File 'lib/ooor/base.rb', line 65

def where(opts, *rest); relation.where(opts, *rest); end

Instance Method Details

#call(method, *args) ⇒ Object

Generic OpenERP rpc method call



97
# File 'lib/ooor/base.rb', line 97

def call(method, *args) rpc_execute(method, *args) end

#get_report_data(report_name, report_type = "pdf", context = {}) ⇒ Object

Add get_report_data to obtain [report,report] of a concrete openERP Object



114
115
116
# File 'lib/ooor/base.rb', line 114

def get_report_data(report_name, report_type="pdf", context={})
  self.class.get_report_data(report_name, [self.id], report_type, context)
end

#on_change(on_change_method, field_name, field_value, *args) ⇒ Object

Generic OpenERP on_change method



100
101
102
103
104
105
# File 'lib/ooor/base.rb', line 100

def on_change(on_change_method, field_name, field_value, *args)
  # NOTE: OpenERP doesn't accept context systematically in on_change events unfortunately
  ids = self.id ? [id] : []
  result = self.class.object_service(:execute, self.class.openerp_model, on_change_method, ids, *args)
  load_on_change_result(result, field_name, field_value)
end

#rpc_execute(method, *args) ⇒ Object



91
92
93
94
# File 'lib/ooor/base.rb', line 91

def rpc_execute(method, *args)
  args += [self.class.context] unless args[-1].is_a? Hash
  self.class.object_service(:execute, self.class.openerp_model, method, *args)
end

#typeObject

skips deprecated Object#type method



118
# File 'lib/ooor/base.rb', line 118

def type() method_missing(:type) end

#wkf_action(action, context = {}, reload = true) ⇒ Object

wrapper for OpenERP exec_workflow Business Process Management engine



108
109
110
111
# File 'lib/ooor/base.rb', line 108

def wkf_action(action, context={}, reload=true)
  self.class.object_service(:exec_workflow, self.class.openerp_model, action, self.id, context)
  reload_fields if reload
end