Class: Ooor::Base
- Inherits:
-
MiniActiveResource
- Object
- MiniActiveResource
- Ooor::Base
- Includes:
- ActiveModel::Dirty, Associations, Callbacks, FieldMethods, FinderMethods, Naming, Persistence, Reflection, ReflectionOoor, Report, Serialization, TypeCasting
- Defined in:
- lib/ooor/base.rb
Overview
the base class for proxies to OpenERP objects
Constant Summary
Constants included from Callbacks
Constants included from TypeCasting
TypeCasting::BLACKLIST, TypeCasting::OPERATORS
Class Attribute Summary collapse
-
.connection ⇒ Object
template.
-
.name ⇒ Object
template.
-
.scope_prefix ⇒ Object
template.
-
.t ⇒ Object
template.
Instance Attribute Summary collapse
-
#associations ⇒ Object
********************** instance methods **********************************.
-
#ir_model_data_id ⇒ Object
********************** instance methods **********************************.
-
#loaded_associations ⇒ Object
********************** instance methods **********************************.
-
#object_session ⇒ Object
********************** instance methods **********************************.
Attributes inherited from MiniActiveResource
Class Method Summary collapse
- .all(*args) ⇒ Object
-
.create(attributes = {}, context = {}, default_get_list = false, reload = true) ⇒ Object
******************** remote communication *****************************.
- .first(*args) ⇒ Object
- .last(*args) ⇒ Object
- .limit(value) ⇒ Object
- .logger ⇒ Object
- .method_missing(method_symbol, *args) ⇒ Object
- .name_search(name = '', domain = [], operator = 'ilike', context = {}, limit = 100) ⇒ Object
- .object_service(service, obj, method, *args) ⇒ Object
- .offset(value) ⇒ Object
- .order(value) ⇒ Object
-
.relation(context = {}) ⇒ Object
******************** AREL Minimal implementation ***********************.
- .rpc_exec_workflow(action, *args) ⇒ Object
- .rpc_execute(method, *args) ⇒ Object
- .scoped(context = {}) ⇒ Object
-
.search(domain = [], offset = 0, limit = false, order = false, context = {}, count = false) ⇒ Object
OpenERP search method.
- .where(opts, *rest) ⇒ Object
Instance Method Summary collapse
-
#call(method, *args) ⇒ Object
Generic OpenERP rpc method call.
- #get_report_data(report_name, report_type = "pdf", context = {}) ⇒ Object
-
#on_change(on_change_method, field_name, field_value, *args) ⇒ Object
Generic OpenERP on_change method.
- #rpc_execute(method, *args) ⇒ Object
-
#type ⇒ Object
skips deprecated Object#type method.
-
#wkf_action(action, context = {}, reload = true) ⇒ Object
wrapper for OpenERP exec_workflow Business Process Management engine.
Methods included from Persistence
#copy, #create, #create_or_update, #create_record, #destroy, #initialize, #load, #save, #update, #update_attributes, #update_record
Methods included from Associations
#load_x2m_association, #relationnal_result
Methods included from FieldMethods
#get_association, #get_attribute, #method_missing, #set_association, #set_attribute
Methods included from Naming
Methods included from TypeCasting
#cast_association, #cast_associations_to_openerp, #cast_m2o_association, #cast_o2m_assocation, #cast_o2m_nested_attributes, #get_changed_values, #sanitize_associatio_as_string, #sanitize_association, #sanitize_attribute, #sanitize_m2o_association, #to_openerp_hash
Methods included from Serialization
#serializable_hash, #serialize_many2one, #serialize_x_to_many
Methods included from ReflectionOoor
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
.connection ⇒ Object
template
36 37 38 |
# File 'lib/ooor/base.rb', line 36 def connection @connection end |
.name ⇒ Object
template
36 37 38 |
# File 'lib/ooor/base.rb', line 36 def name @name end |
.scope_prefix ⇒ Object
template
36 37 38 |
# File 'lib/ooor/base.rb', line 36 def scope_prefix @scope_prefix end |
.t ⇒ Object
template
36 37 38 |
# File 'lib/ooor/base.rb', line 36 def t @t end |
Instance Attribute Details
#associations ⇒ Object
********************** instance methods **********************************
92 93 94 |
# File 'lib/ooor/base.rb', line 92 def associations @associations end |
#ir_model_data_id ⇒ Object
********************** instance methods **********************************
92 93 94 |
# File 'lib/ooor/base.rb', line 92 def ir_model_data_id @ir_model_data_id end |
#loaded_associations ⇒ Object
********************** instance methods **********************************
92 93 94 |
# File 'lib/ooor/base.rb', line 92 def loaded_associations @loaded_associations end |
#object_session ⇒ Object
********************** instance methods **********************************
92 93 94 |
# File 'lib/ooor/base.rb', line 92 def object_session @object_session end |
Class Method Details
.all(*args) ⇒ Object
77 |
# File 'lib/ooor/base.rb', line 77 def all(*args); relation.all(*args); end |
.create(attributes = {}, context = {}, default_get_list = false, reload = true) ⇒ Object
******************** remote communication *****************************
41 42 43 |
# File 'lib/ooor/base.rb', line 41 def create(attributes = {}, context={}, default_get_list=false, reload=true) self.new(attributes, default_get_list, context).tap { |resource| resource.save(context, reload) } end |
.first(*args) ⇒ Object
81 |
# File 'lib/ooor/base.rb', line 81 def first(*args); relation.first(*args); end |
.last(*args) ⇒ Object
82 |
# File 'lib/ooor/base.rb', line 82 def last(*args); relation.last(*args); end |
.limit(value) ⇒ Object
78 |
# File 'lib/ooor/base.rb', line 78 def limit(value); relation.limit(value); end |
.logger ⇒ Object
84 |
# File 'lib/ooor/base.rb', line 84 def logger; Ooor.logger; end |
.method_missing(method_symbol, *args) ⇒ Object
67 68 69 70 |
# File 'lib/ooor/base.rb', line 67 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', context = {}, limit = 100) ⇒ Object
50 51 52 |
# File 'lib/ooor/base.rb', line 50 def name_search(name='', domain=[], operator='ilike', context={}, limit=100) rpc_execute(:name_search, name, to_openerp_domain(domain), operator, context, limit) end |
.object_service(service, obj, method, *args) ⇒ Object
62 63 64 65 |
# File 'lib/ooor/base.rb', line 62 def object_service(service, obj, method, *args) reload_fields_definition(false, connection.connection_session) cast_answer_to_ruby!(connection.object.object_service(service, obj, method, *cast_request_to_openerp(args))) end |
.offset(value) ⇒ Object
80 |
# File 'lib/ooor/base.rb', line 80 def offset(value); relation.offset(value); end |
.order(value) ⇒ Object
79 |
# File 'lib/ooor/base.rb', line 79 def order(value); relation.order(value); end |
.relation(context = {}) ⇒ Object
******************** AREL Minimal implementation ***********************
74 |
# File 'lib/ooor/base.rb', line 74 def relation(context={}); @relation ||= Relation.new(self, context); end |
.rpc_exec_workflow(action, *args) ⇒ Object
58 59 60 |
# File 'lib/ooor/base.rb', line 58 def rpc_exec_workflow(action, *args) object_service(:exec_workflow, openerp_model, action, *args) end |
.rpc_execute(method, *args) ⇒ Object
54 55 56 |
# File 'lib/ooor/base.rb', line 54 def rpc_execute(method, *args) object_service(:execute, openerp_model, method, *args) end |
.scoped(context = {}) ⇒ Object
75 |
# File 'lib/ooor/base.rb', line 75 def scoped(context={}); relation(context); end |
.search(domain = [], offset = 0, limit = false, order = false, context = {}, count = false) ⇒ Object
OpenERP search method
46 47 48 |
# File 'lib/ooor/base.rb', line 46 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
76 |
# File 'lib/ooor/base.rb', line 76 def where(opts, *rest); relation.where(opts, *rest); end |
Instance Method Details
#call(method, *args) ⇒ Object
Generic OpenERP rpc method call
102 |
# File 'lib/ooor/base.rb', line 102 def call(method, *args) rpc_execute(method, *args) end |
#get_report_data(report_name, report_type = "pdf", context = {}) ⇒ Object
119 120 121 |
# File 'lib/ooor/base.rb', line 119 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
105 106 107 108 109 110 |
# File 'lib/ooor/base.rb', line 105 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
96 97 98 99 |
# File 'lib/ooor/base.rb', line 96 def rpc_execute(method, *args) args += [self.class.connection.connection_session.merge(object_session)] unless args[-1].is_a? Hash self.class.object_service(:execute, self.class.openerp_model, method, *args) end |
#type ⇒ Object
skips deprecated Object#type method
123 |
# File 'lib/ooor/base.rb', line 123 def type() method_missing(:type) end |
#wkf_action(action, context = {}, reload = true) ⇒ Object
wrapper for OpenERP exec_workflow Business Process Management engine
113 114 115 116 |
# File 'lib/ooor/base.rb', line 113 def wkf_action(action, context={}, reload=true) self.class.object_service(:exec_workflow, self.class.openerp_model, action, self.id, object_session) reload_fields(context) if reload end |