Files
vault171/app/models/category.rb
David Böhm b4c57b6f14
Some checks failed
CI / scan_ruby (push) Has been cancelled
CI / scan_js (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / test (push) Has been cancelled
CI / system-test (push) Has been cancelled
Added more infos in category#index cards
2026-05-28 19:24:37 +02:00

21 lines
564 B
Ruby

class Category < ApplicationRecord
has_many :items, dependent: :restrict_with_error
validates :name, presence: true, uniqueness: true
# 1. Zählt Artikel im Hauptlager (weder User noch Raum zugewiesen)
def items_in_storage_count
items.where(user_id: nil, room_id: nil).count
end
# 2. Zählt Artikel, die bei Mitarbeitern im Umlauf sind
def items_with_users_count
items.where.not(user_id: nil).count
end
# 3. Zählt Artikel, die fest in Räumen verbaut sind
def items_in_rooms_count
items.where.not(room_id: nil).count
end
end