Class: EntityAddress

Inherits:
Ekylibre::Record::Base show all
Defined in:
app/models/entity_address.rb

Overview

Informations

License

Ekylibre - Simple agricultural ERP Copyright (C) 2008-2009 Brice Texier, Thibaud Merigon Copyright (C) 2010-2012 Brice Texier Copyright (C) 2012-2016 Brice Texier, David Joulin

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see www.gnu.org/licenses.

Table: entity_addresses

by_default          :boolean          default(FALSE), not null
canal               :string           not null
coordinate          :string           not null
created_at          :datetime         not null
creator_id          :integer
deleted_at          :datetime
entity_id           :integer          not null
id                  :integer          not null, primary key
lock_version        :integer          default(0), not null
mail_auto_update    :boolean          default(FALSE), not null
mail_country        :string
mail_geolocation    :geometry({:srid=>4326, :type=>"point"})
mail_line_1         :string
mail_line_2         :string
mail_line_3         :string
mail_line_4         :string
mail_line_5         :string
mail_line_6         :string
mail_postal_zone_id :integer
name                :string
thread              :string
updated_at          :datetime         not null
updater_id          :integer

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Ekylibre::Record::Base

#already_updated?, attr_readonly_with_conditions, #check_if_destroyable?, #check_if_updateable?, columns_definition, complex_scopes, customizable?, #customizable?, #customized?, #destroyable?, #editable?, has_picture, #human_attribute_name, human_attribute_name_with_id, nomenclature_reflections, #old_record, #others, refers_to, scope_with_registration, simple_scopes, #updateable?

Class Method Details

.exportable_columnsObject


144
145
146
# File 'app/models/entity_address.rb', line 144

def self.exportable_columns
  content_columns.delete_if { |c| [:deleted_at, :closed_at, :lock_version, :thread, :created_at, :updated_at].include?(c.name.to_sym) }
end

Instance Method Details

#destroyObject

without.allbacks


140
141
142
# File 'app/models/entity_address.rb', line 140

def destroy # _without_.allbacks
  self.class.where(id: id).update_all(deleted_at: Time.zone.now) unless new_record?
end

#labelObject


148
149
150
# File 'app/models/entity_address.rb', line 148

def label
  entity.number + '. ' + coordinate
end

#mail_coordinateObject


179
180
181
# File 'app/models/entity_address.rb', line 179

def mail_coordinate
  mail_lines(separator: "\r\n")
end

#mail_line_6_city=(value) ⇒ Object


165
166
167
# File 'app/models/entity_address.rb', line 165

def mail_line_6_city=(value)
  self.mail_line_6 = (mail_line_6.to_s + ' ' + value.to_s).strip
end

#mail_line_6_codeObject Also known as: mail_postal_code


152
153
154
# File 'app/models/entity_address.rb', line 152

def mail_line_6_code
  mail_postal_zone.postal_code if mail_postal_zone
end

#mail_line_6_code=(value) ⇒ Object


157
158
159
# File 'app/models/entity_address.rb', line 157

def mail_line_6_code=(value)
  self.mail_line_6 = (value.to_s + ' ' + mail_line_6.to_s).strip
end

#mail_lines(options = {}) ⇒ Object


169
170
171
172
173
174
175
176
177
# File 'app/models/entity_address.rb', line 169

def mail_lines(options = {})
  options = { separator: ', ', with_city: true, with_country: true }.merge(options)
  lines = [mail_line_1, mail_line_2, mail_line_3, mail_line_4, mail_line_5]
  lines << mail_line_6.to_s if options[:with_city]
  lines << (Nomen::Country[mail_country] ? Nomen::Country[mail_country].human_name : '') if options[:with_country]
  lines = lines.compact.collect { |x| x.gsub(options[:separator], ' ').gsub(/\ +/, ' ') }
  lines.delete ''
  lines.join(options[:separator])
end

#mail_mail_line_6_cityObject


161
162
163
# File 'app/models/entity_address.rb', line 161

def mail_mail_line_6_city
  mail_postal_zone.city if mail_postal_zone
end

#updateObject

without.allbacks


121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'app/models/entity_address.rb', line 121

def update # _without_.allbacks
  # raise StandardError.new "UPDAAAAAAAAAAAATE"
  current_time = Time.zone.now
  stamper = begin
              self.class.stamper_class.stamper
            rescue
              nil
            end
  # raise stamper.inspect unless stamper.nil?
  stamper_id = stamper.id if stamper.is_a? Entity
  nc = self.class.new
  for attr, val in attributes.merge(created_at: current_time, updated_at: current_time, creator_id: stamper_id, updater_id: stamper_id).delete_if { |k, _v| k.to_s == 'id' }
    nc.send("#{attr}=", val)
  end
  nc.save!
  self.class.where(id: id).update_all(deleted_at: current_time)
  nc
end