Sha256: 81c49efaa703e7a487b952aa6a194ecaa2c32d30b6573b4daefa5f7915a9109b

Contents?: true

Size: 874 Bytes

Versions: 10

Compression:

Stored size: 874 Bytes

Contents

module EnjuCirculation
  module EnjuBasket
    extend ActiveSupport::Concern

    included do
      has_many :checked_items, dependent: :destroy
      has_many :items, through: :checked_items
      has_many :checkouts
      has_many :checkins
    end

    def basket_checkout(librarian)
      return nil if checked_items.size == 0
      Item.transaction do
        checked_items.each do |checked_item|
          checkout = user.checkouts.new
          checkout.librarian = librarian
          checkout.item = checked_item.item
          checkout.basket = self
          checkout.library = librarian.profile.library
          checkout.shelf = checked_item.item.shelf
          checkout.due_date = checked_item.due_date
          checked_item.item.checkout!(user)
          checkout.save!
        end
        CheckedItem.destroy_all(basket_id: id)
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
enju_circulation-0.2.5 app/models/concerns/enju_circulation/enju_basket.rb
enju_circulation-0.2.4 app/models/concerns/enju_circulation/enju_basket.rb
enju_circulation-0.2.3 app/models/concerns/enju_circulation/enju_basket.rb
enju_circulation-0.2.2 app/models/concerns/enju_circulation/enju_basket.rb
enju_circulation-0.2.1 app/models/concerns/enju_circulation/enju_basket.rb
enju_circulation-0.2.0 app/models/concerns/enju_circulation/enju_basket.rb
enju_circulation-0.2.0.beta.4 app/models/concerns/enju_circulation/enju_basket.rb
enju_circulation-0.2.0.beta.3 app/models/concerns/enju_circulation/enju_basket.rb
enju_circulation-0.2.0.beta.2 app/models/concerns/enju_circulation/enju_basket.rb
enju_circulation-0.2.0.beta.1 app/models/concerns/enju_circulation/enju_basket.rb