app/models/item.rb in enju_biblio-0.0.3 vs app/models/item.rb in enju_biblio-0.0.4
- old
+ new
@@ -18,10 +18,11 @@
belongs_to :required_role, :class_name => 'Role', :foreign_key => 'required_role_id', :validate => true
has_one :resource_import_result
belongs_to :budget_type
has_one :accept
#accepts_nested_attributes_for :exemplify
+ #before_save :create_manifestation
validates_associated :bookstore
validates :manifestation_id, :presence => true, :on => :create
validates :item_identifier, :allow_blank => true, :uniqueness => true,
:format => {:with => /\A[0-9A-Za-z_]+\Z/}
@@ -44,129 +45,24 @@
integer :patron_ids, :multiple => true
time :created_at
time :updated_at
end
+ enju_circulation_item_model if defined?(EnjuCirculation)
+
attr_accessor :library_id, :manifestation_id
- if defined?(EnjuCirculation)
- FOR_CHECKOUT_CIRCULATION_STATUS = [
- 'Available On Shelf',
- 'On Loan',
- 'Waiting To Be Reshelved'
- ]
- FOR_CHECKOUT_USE_RESTRICTION = [
- 'Available For Supply Without Return',
- 'Limited Circulation, Long Loan Period',
- 'Limited Circulation, Short Loan Period',
- 'No Reproduction',
- 'Overnight Only',
- 'Renewals Not Permitted',
- 'Supervision Required',
- 'Term Loan',
- 'User Signature Required',
- 'Limited Circulation, Normal Loan Period'
- ]
- scope :for_checkout, includes(:circulation_status, :use_restriction).where(
- 'circulation_statuses.name' => FOR_CHECKOUT_CIRCULATION_STATUS,
- 'use_restrictions.name' => FOR_CHECKOUT_USE_RESTRICTION
- ).where('item_identifier IS NOT NULL')
- scope :removed, includes(:circulation_status).where('circulation_statuses.name' => 'Removed')
- has_many :checkouts
- has_many :reserves
- has_many :checked_items, :dependent => :destroy
- has_many :baskets, :through => :checked_items
- belongs_to :circulation_status, :validate => true
- belongs_to :checkout_type
- has_many :lending_policies, :dependent => :destroy
- has_one :item_has_use_restriction, :dependent => :destroy
- has_one :use_restriction, :through => :item_has_use_restriction
- validates_associated :circulation_status, :checkout_type
- validates_presence_of :circulation_status, :checkout_type
- searchable do
- integer :circulation_status_id
- end
- attr_accessible :item_has_use_restriction_attributes
- accepts_nested_attributes_for :item_has_use_restriction
-
- def set_circulation_status
- self.circulation_status = CirculationStatus.where(:name => 'In Process').first if self.circulation_status.nil?
- end
-
- def checkout_status(user)
- user.user_group.user_group_has_checkout_types.where(:checkout_type_id => self.checkout_type.id).first
- end
-
- def reserved?
- return true if manifestation.next_reservation
- false
- end
-
- def rent?
- return true if self.checkouts.not_returned.select(:item_id).detect{|checkout| checkout.item_id == self.id}
- false
- end
-
- def reserved_by_user?(user)
- if manifestation.next_reservation
- return true if manifestation.next_reservation.user == user
- end
- false
- end
-
- def available_for_checkout?
- if circulation_status.name == 'On Loan'
- false
- else
- manifestation.items.for_checkout.include?(self)
- end
- end
-
- def checkout!(user)
- self.circulation_status = CirculationStatus.where(:name => 'On Loan').first
- if self.reserved_by_user?(user)
- manifestation.next_reservation.update_attributes(:checked_out_at => Time.zone.now)
- manifestation.next_reservation.sm_complete!
- end
- save!
- end
-
- def checkin!
- self.circulation_status = CirculationStatus.where(:name => 'Available On Shelf').first
- save(:validate => false)
- end
-
- def retain(librarian)
- Item.transaction do
- reservation = manifestation.next_reservation
- unless reservation.nil?
- reservation.item = self
- reservation.sm_retain!
- reservation.send_message(librarian)
- end
- end
- end
-
- def lending_rule(user)
- lending_policies.where(:user_group_id => user.user_group.id).first
- end
-
- def not_for_loan?
- !manifestation.items.for_checkout.include?(self)
- end
- end
-
if defined?(EnjuInventory)
has_many :inventories, :dependent => :destroy
has_many :inventory_files, :through => :inventories
searchable do
integer :inventory_file_ids, :multiple => true
end
def self.inventory_items(inventory_file, mode = 'not_on_shelf')
- item_ids = Item.select(:id).collect(&:id)
- inventory_item_ids = inventory_file.items.select('items.id').collect(&:id)
+ item_ids = Item.pluck(:id)
+ inventory_item_ids = inventory_file.items.pluck('items.id')
case mode
when 'not_on_shelf'
Item.where(:id => (item_ids - inventory_item_ids))
when 'not_in_catalog'
Item.where(:id => (inventory_item_ids - item_ids))
@@ -247,9 +143,15 @@
if defined?(EnjuCirculation)
checkouts.not_returned.empty?
else
true
end
+ end
+ end
+
+ def create_manifestation
+ if manifestation_id
+ self.manifestation = Manifestation.find(manifestation_id)
end
end
end
# == Schema Information
#