Module: Ooor::Naming::ClassMethods

Defined in:
lib/ooor/naming.rb

Instance Method Summary collapse

Instance Method Details

#alias(context = {}) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/ooor/naming.rb', line 52

def alias(context={})
  # NOTE in v8, see if we can use ModelConvert here https://github.com/akretion/openerp-addons/blob/trunk-website-al/website/models/ir_http.py#L126
  if connection.config[:aliases]
    lang = context['lang'] || connection.config['lang'] || 'en_US'
    if alias_data = connection.config[:aliases][lang]
      alias_data.select{|key, value| value == openerp_model }.keys[0] || openerp_model
    else
      openerp_model
    end
  else
    openerp_model
  end
end

#const_get(model_key) ⇒ Object

similar to Object#const_get but for OpenERP model key



26
27
28
29
30
31
32
33
34
# File 'lib/ooor/naming.rb', line 26

def const_get(model_key)
  scope = self.scope_prefix ? Object.const_get(self.scope_prefix) : Object
  klass_name = connection.class_name_from_model_key(model_key)
  if scope.const_defined?(klass_name) && Ooor.session_handler.connection_spec(scope.const_get(klass_name).connection.config) == Ooor.session_handler.connection_spec(connection.config)
    scope.const_get(klass_name)
  else
    connection.define_openerp_model(model: model_key, scope_prefix: self.scope_prefix)
  end
end


45
46
47
48
49
50
# File 'lib/ooor/naming.rb', line 45

def find_by_permalink(param, options={})
  # NOTE in v8, see if we can use PageConverter here https://github.com/akretion/openerp-addons/blob/trunk-website-al/website/models/ir_http.py#L138
  param = param.to_i unless param.to_i == 0
  options.merge!(domain: {param_field => param})
  find(:first, options)
end

#human_attribute_name(field_name, options = {}) ⇒ Object

required by form validators; TODO implement better?



37
38
39
# File 'lib/ooor/naming.rb', line 37

def human_attribute_name(field_name, options={})
  ""
end

#model_nameObject



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/ooor/naming.rb', line 8

def model_name
  @_model_name ||= begin
    namespace = self.parents.detect do |n|
      n.respond_to?(:use_relative_model_naming?) && n.use_relative_model_naming?
    end
    ActiveModel::Name.new(self, namespace, self.description || self.openerp_model).tap do |r|
      def r.param_key
        @klass.openerp_model.gsub('.', '_')
      end
    end
  end
end

#param_fieldObject



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

def param_field
  connection.config[:param_keys] && connection.config[:param_keys][openerp_model] || :id
end

#param_key(context = {}) ⇒ Object



21
22
23
# File 'lib/ooor/naming.rb', line 21

def param_key(context={})
  self.alias(context).gsub('.', '-') # we don't use model_name because model_name isn't bijective
end