Class: Property
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Property
- Includes:
- PgSearch::Model
- Defined in:
- app/models/property.rb
Class Method Summary collapse
- .archived_completed ⇒ Object
- .inspectable_units(property_id) ⇒ Object
- .search(system_id, property_name, inspection_completed, is_archived) ⇒ Object
Instance Method Summary collapse
Class Method Details
.archived_completed ⇒ Object
26 27 28 29 30 31 |
# File 'app/models/property.rb', line 26 def self.archived_completed where("(properties->>'is_archived' = 'Yes') is not null") .where("(properties->>'inspection_finished' = '1') is not null") .where(status: 'active') .order(property_name: :asc) end |
.inspectable_units(property_id) ⇒ Object
46 47 48 |
# File 'app/models/property.rb', line 46 def self.inspectable_units(property_id) Unit.where(property_id: property_id).count end |
.search(system_id, property_name, inspection_completed, is_archived) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/models/property.rb', line 33 def self.search(system_id, property_name, inspection_completed,is_archived) is_archived = is_archived.nil? ? '0' : is_archived result = Property.where(system_id: system_id ? system_id : 2) result = result.where('property_name ILIKE ?', "%#{property_name}%") if property_name.present? result = result.where("properties->>'is_archived' = '#{is_archived}'") if is_archived.present? result = result.where("properties->>'inspection_finished' = '#{inspection_completed}'") if inspection_completed.present? result.class == Class ? all : result end |
Instance Method Details
#duplicate_with_buildings_and_units ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'app/models/property.rb', line 50 def duplicate_with_buildings_and_units new_property = self.dup new_property.property_name = "#{self.property_name} (Duplicated)" new_property.created_by_id = 1 new_property.updated_by_id = 1 new_property.save self.buildings.each do |building| new_building = building.dup new_building.old_id = '' new_building.property_id = new_property.id new_building.save building.units.each do |unit| new_unit = unit.dup new_unit.old_id = '' new_unit.property_id = new_property.id new_unit.building_id = new_building.id new_unit.save end end new_property end |