Skip to content
1 change: 1 addition & 0 deletions app/models/asset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ class Asset < ApplicationRecord
validates :status, presence: true
belongs_to :space
has_many :asset_suppliers
has_many :suppliers, through: :asset_suppliers
has_many :maintenances
end
7 changes: 6 additions & 1 deletion app/models/contract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
class Contract < ApplicationRecord
validates :start_date, presence: true
validates :finish_date, presence: true
belongs_to :space
has_many :payments
has_many :contract_spaces
has_many :spaces, through: :contract_spaces
belongs_to :user
def name
"#{start_date} | #{finish_date}"
end
end
5 changes: 5 additions & 0 deletions app/models/contract_space.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# ContractSpace
class ContractSpace < ApplicationRecord
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Esta clase no es necesaria.

belongs_to :contract
belongs_to :space
end
8 changes: 8 additions & 0 deletions app/models/payment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Payment
class Payment < ApplicationRecord
validates :due_date, presence: true
validates :payment_date, presence: true
validates :amount, presence: true
validates :status, presence: true
belongs_to :contract
end
17 changes: 16 additions & 1 deletion app/models/space.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,22 @@ class Space < ApplicationRecord
validates :name, presence: true
belongs_to :parent, inverse_of: :children, foreign_key: :space_id, class_name: 'Space', optional: true
has_many :children, inverse_of: :parent, foreign_key: :space_id, class_name: 'Space'
has_many :contracts
has_many :assets
has_one :warehouse
has_many :contract_spaces
has_many :contracts, through: :contract_spaces

before_save :generate_full_name

protected

def generate_full_name
self.full_name = array_parents.reverse.map(&:name).join(' | ')
end

def array_parents
objects = [self]
objects.push(objects.last.parent) while objects.last.parent
objects
end
end
3 changes: 2 additions & 1 deletion app/models/supplier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class Supplier < ApplicationRecord
validates :supplier_identity, presence: true, uniqueness: true
validates :services, presence: true
validates :category, presence: true
has_many :asset_suppliers
has_many :maintenances
has_many :asset_suppliers
has_many :assets, through: :asset_suppliers
end
4 changes: 3 additions & 1 deletion config/initializers/rails_admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@
config.model (User) { list { configure :id { hide } } }
config.model (Organization) { list { configure :id { hide } } }
config.model (Asset) { list { configure :id { hide } } }
config.model (AssetSupplier) { list { configure :id { hide } } }
config.model (Contract) { list { configure :id { hide } } }
config.model (Maintenance) { list { configure :id { hide } } }
config.model (Space) { list { configure :id { hide } } }
config.model (Supplier) { list { configure :id { hide } } }
config.model (Supply) { list { configure :id { hide } } }
config.model (Warehouse) { list { configure :id { hide } } }
config.model (Payment) { list { configure :id { hide } } }
config.model (ContractSpace) { list { configure :id { hide } } }
config.model (AssetSupplier) { list { configure :id { hide } } }
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class ChangeTypeCategoryAssetDescription < ActiveRecord::Migration[5.1]
def up
change_table :assets do |t|
t.change :description, :text
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class ChangeTypeCategoryOrganizationDescription < ActiveRecord::Migration[5.1]
def up
change_table :organizations do |t|
t.change :description, :text
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class ChangeTypeCategorySupplierAddress < ActiveRecord::Migration[5.1]
def up
change_table :suppliers do |t|
t.change :address, :text
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class ChangeTypeCategorySupplyDescription < ActiveRecord::Migration[5.1]
def up
change_table :supplies do |t|
t.change :description, :text
end
end
end
7 changes: 7 additions & 0 deletions db/migrate/20180209172241_change_type_category_supply_note.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class ChangeTypeCategorySupplyNote < ActiveRecord::Migration[5.1]
def up
change_table :supplies do |t|
t.change :note, :text
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class ChangeTypeCategoryUserAddress < ActiveRecord::Migration[5.1]
def up
change_table :users do |t|
t.change :address, :text
end
end
end
5 changes: 5 additions & 0 deletions db/migrate/20180209174923_add_full_name_to_space.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddFullNameToSpace < ActiveRecord::Migration[5.1]
def change
add_column :spaces, :full_name, :string
end
end
5 changes: 5 additions & 0 deletions db/migrate/20180212043454_remove_references_on_contract.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RemoveReferencesOnContract < ActiveRecord::Migration[5.1]
def change
remove_reference(:contracts, :space, index: true)
end
end
15 changes: 15 additions & 0 deletions db/migrate/20180212161659_create_payments.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class CreatePayments < ActiveRecord::Migration[5.1]
def change
create_table :payments do |t|
t.integer :payment
t.date :payment_date
t.date :warning_date
t.integer :quantity
t.string :status
t.text :note
t.references :contract, foreign_key: true

t.timestamps
end
end
end
8 changes: 8 additions & 0 deletions db/migrate/20180214175011_changes_on_payment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class ChangesOnPayment < ActiveRecord::Migration[5.1]
def change
rename_column :payments, :warning_date, :due_date
rename_column :payments, :quantity, :amount
remove_column :payments, :payment, :integer
change_column :payments, :amount, :float
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class RemoveReferencesOnContractSpaces < ActiveRecord::Migration[5.1]
def change
remove_reference(:contract_spaces, :space, index: true)
remove_reference(:contract_spaces, :contract, index: true)
end
end
5 changes: 5 additions & 0 deletions db/migrate/20180214194838_drop_contract_space.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class DropContractSpace < ActiveRecord::Migration[5.1]
def change
drop_table :contract_spaces
end
end
6 changes: 6 additions & 0 deletions db/migrate/20180214201411_contracts_spaces.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class ContractsSpaces < ActiveRecord::Migration[5.1]
create_table :contracts_spaces, id: false do |t|
t.belongs_to :contract, index: true
t.belongs_to :space, index: true
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class RemoveReferencesOnAssetSupplier < ActiveRecord::Migration[5.1]
def change
remove_reference(:asset_suppliers, :asset, index: true)
remove_reference(:asset_suppliers, :supplier, index: true)
end
end
5 changes: 5 additions & 0 deletions db/migrate/20180214212102_drop_asset_supplier.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class DropAssetSupplier < ActiveRecord::Migration[5.1]
def change
drop_table :asset_suppliers
end
end
6 changes: 6 additions & 0 deletions db/migrate/20180214212252_assets_suppliers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AssetsSuppliers < ActiveRecord::Migration[5.1]
create_table :assets_suppliers, id: false do |t|
t.belongs_to :asset, index: true
t.belongs_to :supplier, index: true
end
end
5 changes: 5 additions & 0 deletions db/migrate/20180215171145_remove_relation_contracts_space.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RemoveRelationContractsSpace < ActiveRecord::Migration[5.1]
def change
drop_table :contracts_spaces
end
end
5 changes: 5 additions & 0 deletions db/migrate/20180215171311_remove_relation_assets_suppliers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RemoveRelationAssetsSuppliers < ActiveRecord::Migration[5.1]
def change
drop_table :assets_suppliers
end
end
11 changes: 11 additions & 0 deletions db/migrate/20180215173742_create_contract_spaces.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class CreateContractSpaces < ActiveRecord::Migration[5.1]
def change
create_table :contract_spaces do |t|
t.belongs_to :contract, index: true
t.belongs_to :space, index: true
t.datetime :appointment_date

t.timestamps
end
end
end
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
class CreateAssetSuppliers < ActiveRecord::Migration[5.1]
def change
create_table :asset_suppliers do |t|
t.references :asset, foreign_key: true
t.references :supplier, foreign_key: true

t.belongs_to :asset, index: true
t.belongs_to :supplier, index: true
t.timestamps
end
end
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20180215181142_remove_column_on_contract_space.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RemoveColumnOnContractSpace < ActiveRecord::Migration[5.1]
def change
remove_column :contract_spaces, :appointment_date, :datetime
end
end
42 changes: 30 additions & 12 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20180208203810) do
ActiveRecord::Schema.define(version: 20180215181142) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand All @@ -32,22 +32,29 @@
t.string "category"
t.string "sub_category"
t.integer "status"
t.string "description"
t.text "description"
t.integer "interval"
t.bigint "space_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["space_id"], name: "index_assets_on_space_id"
end

create_table "contract_spaces", force: :cascade do |t|
t.bigint "contract_id"
t.bigint "space_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["contract_id"], name: "index_contract_spaces_on_contract_id"
t.index ["space_id"], name: "index_contract_spaces_on_space_id"
end

create_table "contracts", force: :cascade do |t|
t.date "start_date"
t.date "finish_date"
t.bigint "space_id"
t.bigint "user_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["space_id"], name: "index_contracts_on_space_id"
t.index ["user_id"], name: "index_contracts_on_user_id"
end

Expand All @@ -64,13 +71,25 @@

create_table "organizations", force: :cascade do |t|
t.string "name"
t.string "description"
t.text "description"
t.string "organization_identifier"
t.string "website"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "payments", force: :cascade do |t|
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+  create_table "payments", force: :cascade do |t|
 -    t.integer "payment"
 +    t.date "due_date"
 +    t.date "payment_date"
 -    t.date "warning_date"
 +    t.decimal "amount"
 +    t.string "status"
 +    t.text "note"

t.date "payment_date"
t.date "due_date"
t.float "amount"
t.string "status"
t.text "note"
t.bigint "contract_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["contract_id"], name: "index_payments_on_contract_id"
end

create_table "spaces", force: :cascade do |t|
t.string "space_identifier"
t.string "name"
Expand All @@ -80,6 +99,7 @@
t.bigint "space_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "full_name"
t.index ["space_id"], name: "index_spaces_on_space_id"
end

Expand All @@ -90,7 +110,7 @@
t.integer "ranking"
t.string "services"
t.string "category"
t.string "address"
t.text "address"
t.string "bank"
t.string "current_account"
t.string "email"
Expand All @@ -102,7 +122,7 @@

create_table "supplies", force: :cascade do |t|
t.string "name"
t.string "description"
t.text "description"
t.string "brand"
t.string "color"
t.string "presentation"
Expand All @@ -112,7 +132,7 @@
t.integer "stock"
t.integer "stock_minimun"
t.integer "stock_reposition"
t.string "note"
t.text "note"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
Expand All @@ -127,7 +147,7 @@
t.date "birthday"
t.string "role"
t.integer "user_identifier"
t.string "address"
t.text "address"
t.text "bio"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
Expand All @@ -144,13 +164,11 @@
t.index ["supply_id"], name: "index_warehouses_on_supply_id"
end

add_foreign_key "asset_suppliers", "assets"
add_foreign_key "asset_suppliers", "suppliers"
add_foreign_key "assets", "spaces"
add_foreign_key "contracts", "spaces"
add_foreign_key "contracts", "users"
add_foreign_key "maintenances", "assets"
add_foreign_key "maintenances", "suppliers"
add_foreign_key "payments", "contracts"
add_foreign_key "spaces", "spaces"
add_foreign_key "users", "organizations"
add_foreign_key "warehouses", "spaces"
Expand Down
4 changes: 4 additions & 0 deletions spec/factories/contract_spaces.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FactoryBot.define do
factory :contract_space do
end
end
9 changes: 9 additions & 0 deletions spec/factories/payments.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FactoryBot.define do
factory :payment do
payment_date FFaker::IdentificationESCO.expedition_date
due_date FFaker::IdentificationESCO.expedition_date
amount FFaker::PhoneNumberAU.home_work_phone_prefix
status 'Completo'
note FFaker::Book.description
end
end
Loading