Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

複数冊の予約取り置きの割り当てを修正 #1940

Merged
merged 4 commits into from
Jan 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/models/concerns/enju_circulation/enju_basket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ def basket_checkout(librarian)

Item.transaction do
checked_items.each do |checked_item|
checkout = user.checkouts.new(
checked_item.item.reload

checkout = user.checkouts.create!(
librarian: librarian,
item: checked_item.item,
basket: self,
library: librarian.profile.library,
shelf: checked_item.item.shelf,
due_date: checked_item.due_date
)
checkout.save!
checked_item.item.checkout!(user)
end
CheckedItem.where(basket_id: id).destroy_all
Expand Down
9 changes: 4 additions & 5 deletions app/models/concerns/enju_circulation/enju_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,10 @@ def available_for_checkout?

def checkout!(user)
Item.transaction do
if user_reservation(user)
unless user_reservation.state_machine.in_state?(:completed)
user_reservation.checked_out_at = Time.zone.now
user_reservation.state_machine.transition_to!(:completed)
end
reserve = user_reservation(user)
if reserve && !reserve.state_machine.in_state?(:completed)
reserve.checked_out_at = Time.zone.now
reserve.state_machine.transition_to!(:completed)
end

update!(circulation_status: CirculationStatus.find_by(name: 'On Loan'))
Expand Down
4 changes: 3 additions & 1 deletion spec/controllers/checked_items_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,9 @@
it 'assigns a newly created checked_item as @checked_item' do
old_count = items(:item_00021).manifestation.reserves.waiting.count
post :create, params: { checked_item: { item_identifier: '00021' }, basket_id: 11 }
assigns(:checked_item).should be_valid
expect(items(:item_00021).user_reservation(Basket.find(11).user)).to be_truthy
expect(assigns(:checked_item)).not_to be_valid
expect(assigns(:checked_item).errors[:base]).to include(I18n.t('activerecord.errors.messages.checked_item.reserved_item_included'))
assigns(:checked_item).item.manifestation.reserves.waiting.count.should eq old_count
assigns(:checked_item).librarian.should eq users(:admin)
end
Expand Down
Loading