enju_circulation 0.1.2 → 0.2.0.beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.rdoc +3 -3
- data/app/controllers/carrier_type_has_checkout_types_controller.rb +14 -4
- data/app/controllers/checked_items_controller.rb +13 -2
- data/app/controllers/checkins_controller.rb +13 -3
- data/app/controllers/checkout_types_controller.rb +12 -2
- data/app/controllers/checkouts_controller.rb +26 -25
- data/app/controllers/circulation_statuses_controller.rb +11 -1
- data/app/controllers/concerns/enju_circulation/controller.rb +12 -0
- data/app/controllers/demands_controller.rb +12 -2
- data/app/controllers/item_has_use_restrictions_controller.rb +13 -2
- data/app/controllers/lending_policies_controller.rb +18 -4
- data/app/controllers/manifestation_checkout_stats_controller.rb +14 -6
- data/app/controllers/manifestation_reserve_stats_controller.rb +15 -4
- data/app/controllers/reserves_controller.rb +17 -9
- data/app/controllers/use_restrictions_controller.rb +11 -1
- data/app/controllers/user_checkout_stats_controller.rb +14 -4
- data/app/controllers/user_group_has_checkout_types_controller.rb +12 -2
- data/app/controllers/user_reserve_stats_controller.rb +14 -4
- data/app/helpers/items_helper.rb +2 -2
- data/app/jobs/manifestation_checkout_stat_job.rb +7 -0
- data/app/jobs/manifestation_reserve_stat_job.rb +7 -0
- data/app/jobs/user_checkout_stat_job.rb +7 -0
- data/app/jobs/user_reserve_stat_job.rb +7 -0
- data/app/models/checked_item.rb +1 -1
- data/app/models/concerns/enju_circulation/enju_accept.rb +16 -0
- data/app/models/concerns/enju_circulation/enju_basket.rb +30 -0
- data/app/models/concerns/enju_circulation/enju_carrier_type.rb +11 -0
- data/app/models/concerns/enju_circulation/enju_item.rb +157 -0
- data/app/models/concerns/enju_circulation/enju_manifestation.rb +77 -0
- data/app/models/concerns/enju_circulation/enju_profile.rb +13 -0
- data/app/models/concerns/enju_circulation/enju_user.rb +50 -0
- data/app/models/concerns/enju_circulation/enju_user_group.rb +17 -0
- data/app/models/concerns/enju_circulation/enju_withdraw.rb +16 -0
- data/app/models/manifestation_checkout_stat_state_machine.rb +1 -1
- data/app/models/reserve.rb +7 -2
- data/app/policies/carrier_type_has_checkout_type_policy.rb +21 -0
- data/app/policies/checked_item_policy.rb +21 -0
- data/app/policies/checkin_policy.rb +21 -0
- data/app/policies/checkout_policy.rb +39 -0
- data/app/policies/checkout_type_policy.rb +23 -0
- data/app/policies/circulation_status_policy.rb +23 -0
- data/app/policies/demand_policy.rb +21 -0
- data/app/policies/item_has_use_restriction_policy.rb +21 -0
- data/app/policies/item_policy.rb +27 -0
- data/app/policies/lending_policy_policy.rb +21 -0
- data/app/policies/manifestation_checkout_stat_policy.rb +21 -0
- data/app/policies/manifestation_reserve_stat_policy.rb +21 -0
- data/app/policies/reserve_policy.rb +37 -0
- data/app/policies/use_restriction_policy.rb +23 -0
- data/app/policies/user_checkout_stat_policy.rb +21 -0
- data/app/policies/user_group_has_checkout_type_policy.rb +21 -0
- data/app/policies/user_reserve_stat_policy.rb +21 -0
- data/app/views/carrier_type_has_checkout_types/index.html.erb +3 -3
- data/app/views/carrier_type_has_checkout_types/show.html.erb +1 -1
- data/app/views/carrier_types/_carrier_type_has_checkout_type_fields.html.erb +5 -0
- data/app/views/carrier_types/_checkout_form.html.erb +2 -4
- data/app/views/checkout_types/index.html.erb +4 -4
- data/app/views/checkout_types/show.html.erb +2 -2
- data/app/views/checkouts/_index.html.erb +1 -1
- data/app/views/checkouts/_index_overdue.html.erb +4 -5
- data/app/views/checkouts/_index_user.html.erb +5 -5
- data/app/views/checkouts/_list.html.erb +2 -2
- data/app/views/checkouts/_reserved_facet.html.erb +2 -2
- data/app/views/checkouts/edit.html.erb +1 -1
- data/app/views/checkouts/index.html.erb +2 -2
- data/app/views/checkouts/index.rss.builder +2 -2
- data/app/views/checkouts/index.txt.erb +1 -1
- data/app/views/checkouts/show.html.erb +10 -6
- data/app/views/circulation_statuses/index.html.erb +4 -4
- data/app/views/circulation_statuses/show.html.erb +1 -1
- data/app/views/reserves/_state_facet.html.erb +2 -2
- data/app/views/reserves/index.html.erb +6 -4
- data/app/views/reserves/show.html.erb +1 -1
- data/app/views/use_restrictions/index.html.erb +4 -4
- data/app/views/use_restrictions/show.html.erb +1 -1
- data/app/views/user_group_has_checkout_types/index.html.erb +3 -3
- data/app/views/user_group_has_checkout_types/show.html.erb +1 -1
- data/app/views/user_groups/_checkout_form.html.erb +2 -16
- data/app/views/user_groups/_user_group_has_checkout_type_fields.html.erb +14 -0
- data/db/migrate/20160703184619_add_most_recent_to_reserve_transitions.rb +9 -0
- data/db/migrate/20160703184650_add_most_recent_to_manifestation_checkout_stat_transitions.rb +9 -0
- data/db/migrate/20160703184723_add_most_recent_to_manifestation_reserve_stat_transitions.rb +9 -0
- data/db/migrate/20160703184747_add_most_recent_to_user_checkout_stat_transitions.rb +9 -0
- data/db/migrate/20160703184805_add_most_recent_to_user_reserve_stat_transitions.rb +9 -0
- data/db/migrate/20160703190209_add_foreign_key_on_manifestation_id_to_reserve.rb +5 -0
- data/lib/enju_circulation/version.rb +1 -1
- data/lib/enju_circulation.rb +0 -20
- data/lib/generators/enju_circulation/setup/setup_generator.rb +16 -4
- data/lib/tasks/enju_circulation_tasks.rake +1 -1
- data/spec/controllers/carrier_type_has_checkout_types_controller_spec.rb +13 -13
- data/spec/controllers/checked_items_controller_spec.rb +6 -6
- data/spec/controllers/checkins_controller_spec.rb +6 -6
- data/spec/controllers/checkout_types_controller_spec.rb +11 -11
- data/spec/controllers/checkouts_controller_spec.rb +72 -71
- data/spec/controllers/circulation_statuses_controller_spec.rb +12 -12
- data/spec/controllers/item_has_use_restrictions_controller_spec.rb +11 -11
- data/spec/controllers/lending_policies_controller_spec.rb +14 -14
- data/spec/controllers/manifestation_checkout_stats_controller_spec.rb +6 -6
- data/spec/controllers/manifestation_reserve_stats_controller_spec.rb +6 -6
- data/spec/controllers/reserves_controller_spec.rb +5 -5
- data/spec/controllers/use_restrictions_controller_spec.rb +14 -14
- data/spec/controllers/user_checkout_stats_controller_spec.rb +8 -8
- data/spec/controllers/user_group_has_checkout_types_controller_spec.rb +11 -11
- data/spec/controllers/user_reserve_stats_controller_spec.rb +8 -8
- data/spec/dummy/app/assets/javascripts/application.js +1 -0
- data/spec/dummy/app/controllers/application_controller.rb +8 -4
- data/spec/dummy/app/models/user.rb +3 -5
- data/spec/dummy/config/application.rb +6 -37
- data/spec/dummy/config/environments/development.rb +22 -18
- data/spec/dummy/config/environments/production.rb +46 -34
- data/spec/dummy/config/environments/test.rb +19 -14
- data/spec/dummy/config/initializers/enju_leaf.rb +5 -0
- data/spec/dummy/db/migrate/20150924115059_create_withdraws.rb +13 -0
- data/spec/dummy/db/migrate/20151213070943_add_translation_table_to_library_group.rb +13 -0
- data/spec/dummy/db/migrate/20151213072705_add_footer_banner_to_library_group.rb +9 -0
- data/spec/dummy/db/schema.rb +30 -2
- data/spec/fixtures/profiles.yml +1 -1
- data/spec/models/manifestation_checkout_stat_spec.rb +3 -4
- data/spec/models/manifestation_reserve_stat_spec.rb +1 -1
- data/spec/models/user_checkout_stat_spec.rb +1 -1
- data/spec/models/user_reserve_stat_spec.rb +1 -1
- data/spec/support/devise.rb +2 -2
- data/spec/views/checkout_types/index.html.erb_spec.rb +1 -0
- data/spec/views/checkout_types/show.html.erb_spec.rb +1 -0
- data/spec/views/checkouts/index.html.erb_spec.rb +1 -3
- data/spec/views/checkouts/show.html.erb_spec.rb +5 -4
- data/spec/views/profiles/show.html.erb_spec.rb +2 -1
- data/spec/views/reserves/index.html.erb_spec.rb +3 -0
- data/spec/views/use_restrictions/index.html.erb_spec.rb +1 -0
- data/spec/views/use_restrictions/show.html.erb_spec.rb +1 -0
- metadata +147 -38
- data/app/models/enju_circulation/ability.rb +0 -114
- data/app/views/circulation_statuses/show.mobile.erb +0 -24
- data/app/workers/manifestation_checkout_stat_queue.rb +0 -7
- data/app/workers/manifestation_reserve_stat_queue.rb +0 -7
- data/app/workers/user_checkout_stat_queue.rb +0 -7
- data/app/workers/user_reserve_stat_queue.rb +0 -7
- data/lib/enju_circulation/accept.rb +0 -23
- data/lib/enju_circulation/basket.rb +0 -37
- data/lib/enju_circulation/carrier_type.rb +0 -15
- data/lib/enju_circulation/controller.rb +0 -21
- data/lib/enju_circulation/item.rb +0 -166
- data/lib/enju_circulation/manifestation.rb +0 -84
- data/lib/enju_circulation/profile.rb +0 -23
- data/lib/enju_circulation/user.rb +0 -61
- data/lib/enju_circulation/user_group.rb +0 -21
- data/lib/enju_circulation/withdraw.rb +0 -23
- data/spec/dummy/app/models/ability.rb +0 -111
- data/spec/dummy/app/models/local_agent.rb +0 -13
- data/spec/dummy/config/application.yml +0 -42
data/app/helpers/items_helper.rb
CHANGED
@@ -7,10 +7,10 @@ module ItemsHelper
|
|
7
7
|
current = true if params[:circulation_status] == circulation_status.name
|
8
8
|
if current
|
9
9
|
content_tag :strong do
|
10
|
-
link_to("#{circulation_status.display_name.localize} (" + facet.count.to_s + ")", url_for(params.merge(circulation_status: circulation_status.name, page: nil, view: nil, only_path: true)))
|
10
|
+
link_to("#{circulation_status.display_name.localize} (" + facet.count.to_s + ")", url_for(params.permit.merge(circulation_status: circulation_status.name, page: nil, view: nil, only_path: true)))
|
11
11
|
end
|
12
12
|
else
|
13
|
-
link_to("#{circulation_status.display_name.localize} (" + facet.count.to_s + ")", url_for(params.merge(circulation_status: circulation_status.name, page: nil, view: nil, only_path: true)))
|
13
|
+
link_to("#{circulation_status.display_name.localize} (" + facet.count.to_s + ")", url_for(params.permit.merge(circulation_status: circulation_status.name, page: nil, view: nil, only_path: true)))
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
data/app/models/checked_item.rb
CHANGED
@@ -12,7 +12,7 @@ class CheckedItem < ActiveRecord::Base
|
|
12
12
|
|
13
13
|
before_validation :set_item
|
14
14
|
before_validation :set_due_date, on: :create
|
15
|
-
|
15
|
+
strip_attributes only: :item_identifier
|
16
16
|
|
17
17
|
#attr_protected :user_id
|
18
18
|
attr_accessor :item_identifier, :ignore_restriction, :due_date_string
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module EnjuCirculation
|
2
|
+
module EnjuAccept
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
before_save :accept!, on: :create
|
7
|
+
end
|
8
|
+
|
9
|
+
def accept!
|
10
|
+
circulation_status = CirculationStatus.where(name: 'Available On Shelf').first
|
11
|
+
item.update_column(:circulation_status_id, circulation_status.id) if circulation_status
|
12
|
+
use_restriction = UseRestriction.where(name: 'Limited Circulation, Normal Loan Period').first
|
13
|
+
item.use_restriction = use_restriction if use_restriction
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module EnjuCirculation
|
2
|
+
module EnjuBasket
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
has_many :checked_items, dependent: :destroy
|
7
|
+
has_many :items, through: :checked_items
|
8
|
+
has_many :checkouts
|
9
|
+
has_many :checkins
|
10
|
+
end
|
11
|
+
|
12
|
+
def basket_checkout(librarian)
|
13
|
+
return nil if checked_items.size == 0
|
14
|
+
Item.transaction do
|
15
|
+
checked_items.each do |checked_item|
|
16
|
+
checkout = user.checkouts.new
|
17
|
+
checkout.librarian = librarian
|
18
|
+
checkout.item = checked_item.item
|
19
|
+
checkout.basket = self
|
20
|
+
checkout.library = librarian.profile.library
|
21
|
+
checkout.shelf = checked_item.item.shelf
|
22
|
+
checkout.due_date = checked_item.due_date
|
23
|
+
checked_item.item.checkout!(user)
|
24
|
+
checkout.save!
|
25
|
+
end
|
26
|
+
CheckedItem.destroy_all(basket_id: id)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module EnjuCirculation
|
2
|
+
module EnjuCarrierType
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
has_many :carrier_type_has_checkout_types, dependent: :destroy
|
7
|
+
has_many :checkout_types, through: :carrier_type_has_checkout_types
|
8
|
+
accepts_nested_attributes_for :carrier_type_has_checkout_types, allow_destroy: true, reject_if: :all_blank
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,157 @@
|
|
1
|
+
module EnjuCirculation
|
2
|
+
module EnjuItem
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
FOR_CHECKOUT_CIRCULATION_STATUS = [
|
7
|
+
'Available On Shelf',
|
8
|
+
'On Loan',
|
9
|
+
'Waiting To Be Reshelved'
|
10
|
+
]
|
11
|
+
FOR_CHECKOUT_USE_RESTRICTION = [
|
12
|
+
'Available For Supply Without Return',
|
13
|
+
'Limited Circulation, Long Loan Period',
|
14
|
+
'Limited Circulation, Short Loan Period',
|
15
|
+
'No Reproduction',
|
16
|
+
'Overnight Only',
|
17
|
+
'Renewals Not Permitted',
|
18
|
+
'Supervision Required',
|
19
|
+
'Term Loan',
|
20
|
+
'User Signature Required',
|
21
|
+
'Limited Circulation, Normal Loan Period'
|
22
|
+
]
|
23
|
+
|
24
|
+
scope :for_checkout, ->(identifier_conditions = 'item_identifier IS NOT NULL') {
|
25
|
+
includes(:circulation_status, :use_restriction).where(
|
26
|
+
'circulation_statuses.name' => FOR_CHECKOUT_CIRCULATION_STATUS,
|
27
|
+
'use_restrictions.name' => FOR_CHECKOUT_USE_RESTRICTION
|
28
|
+
).where(identifier_conditions)
|
29
|
+
}
|
30
|
+
scope :removed, -> { includes(:circulation_status).where('circulation_statuses.name' => 'Removed') }
|
31
|
+
has_many :checkouts
|
32
|
+
has_many :reserves
|
33
|
+
has_many :checked_items
|
34
|
+
has_many :baskets, :through => :checked_items
|
35
|
+
belongs_to :circulation_status, :validate => true
|
36
|
+
belongs_to :checkout_type
|
37
|
+
has_many :lending_policies, :dependent => :destroy
|
38
|
+
has_one :item_has_use_restriction, :dependent => :destroy
|
39
|
+
has_one :use_restriction, :through => :item_has_use_restriction
|
40
|
+
validates_associated :circulation_status, :checkout_type
|
41
|
+
validates_presence_of :circulation_status, :checkout_type
|
42
|
+
searchable do
|
43
|
+
string :circulation_status do
|
44
|
+
circulation_status.name
|
45
|
+
end
|
46
|
+
end
|
47
|
+
accepts_nested_attributes_for :item_has_use_restriction
|
48
|
+
|
49
|
+
before_update :delete_lending_policy
|
50
|
+
end
|
51
|
+
|
52
|
+
def set_circulation_status
|
53
|
+
self.circulation_status = CirculationStatus.where(:name => 'In Process').first if self.circulation_status.nil?
|
54
|
+
end
|
55
|
+
|
56
|
+
def checkout_status(user)
|
57
|
+
return nil unless user
|
58
|
+
user.profile.user_group.user_group_has_checkout_types.where(:checkout_type_id => self.checkout_type.id).first
|
59
|
+
end
|
60
|
+
|
61
|
+
def reserved?
|
62
|
+
return true if manifestation.next_reservation
|
63
|
+
false
|
64
|
+
end
|
65
|
+
|
66
|
+
def rent?
|
67
|
+
return true if self.checkouts.not_returned.select(:item_id).detect{|checkout| checkout.item_id == self.id}
|
68
|
+
false
|
69
|
+
end
|
70
|
+
|
71
|
+
def reserved_by_user?(user)
|
72
|
+
if manifestation.next_reservation
|
73
|
+
return true if manifestation.next_reservation.user == user
|
74
|
+
end
|
75
|
+
false
|
76
|
+
end
|
77
|
+
|
78
|
+
def available_for_checkout?
|
79
|
+
if circulation_status.name == 'On Loan'
|
80
|
+
false
|
81
|
+
else
|
82
|
+
manifestation.items.for_checkout.include?(self)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def checkout!(user)
|
87
|
+
self.circulation_status = CirculationStatus.where(name: 'On Loan').first
|
88
|
+
if reserved_by_user?(user)
|
89
|
+
manifestation.next_reservation.update_attributes(checked_out_at: Time.zone.now)
|
90
|
+
manifestation.next_reservation.transition_to!(:completed)
|
91
|
+
end
|
92
|
+
save!
|
93
|
+
end
|
94
|
+
|
95
|
+
def checkin!
|
96
|
+
self.circulation_status = CirculationStatus.where(name: 'Available On Shelf').first
|
97
|
+
save(validate: false)
|
98
|
+
end
|
99
|
+
|
100
|
+
def retain(librarian)
|
101
|
+
self.class.transaction do
|
102
|
+
reservation = manifestation.next_reservation
|
103
|
+
unless reservation.nil?
|
104
|
+
reservation.item = self
|
105
|
+
reservation.transition_to!(:retained)
|
106
|
+
reservation.send_message(librarian)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def retained?
|
112
|
+
if manifestation.next_reservation.try(:current_state) == 'retained' and manifestation.next_reservation.item == self
|
113
|
+
return true
|
114
|
+
else
|
115
|
+
false
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def lending_rule(user)
|
120
|
+
policy = lending_policies.where(user_group_id: user.profile.user_group.id).first
|
121
|
+
if policy
|
122
|
+
policy
|
123
|
+
else
|
124
|
+
create_lending_policy(user)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def not_for_loan?
|
129
|
+
!manifestation.items.for_checkout.include?(self)
|
130
|
+
end
|
131
|
+
|
132
|
+
def create_lending_policy(user)
|
133
|
+
rule = user.profile.user_group.user_group_has_checkout_types.where(checkout_type_id: checkout_type_id).first
|
134
|
+
return nil unless rule
|
135
|
+
LendingPolicy.create!(
|
136
|
+
item_id: id,
|
137
|
+
user_group_id: rule.user_group_id,
|
138
|
+
fixed_due_date: rule.fixed_due_date,
|
139
|
+
loan_period: rule.checkout_period,
|
140
|
+
renewal: rule.checkout_renewal_limit
|
141
|
+
)
|
142
|
+
end
|
143
|
+
|
144
|
+
def delete_lending_policy
|
145
|
+
return nil unless changes[:checkout_type_id]
|
146
|
+
lending_policies.delete_all
|
147
|
+
end
|
148
|
+
|
149
|
+
def next_reservation
|
150
|
+
Reserve.waiting.where(:item_id => id).first
|
151
|
+
end
|
152
|
+
|
153
|
+
def latest_checkout
|
154
|
+
checkouts.order('checkouts.id').first
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module EnjuCirculation
|
2
|
+
module EnjuManifestation
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
has_many :reserves, :foreign_key => :manifestation_id
|
7
|
+
|
8
|
+
searchable do
|
9
|
+
boolean :reservable do
|
10
|
+
items.for_checkout.exists?
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def next_reservation
|
16
|
+
self.reserves.waiting.order('reserves.created_at ASC').readonly(false).first
|
17
|
+
end
|
18
|
+
|
19
|
+
def available_checkout_types(user)
|
20
|
+
if user
|
21
|
+
user.profile.user_group.user_group_has_checkout_types.available_for_carrier_type(self.carrier_type)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def is_reservable_by?(user)
|
26
|
+
return false if items.for_checkout.empty?
|
27
|
+
unless user.has_role?('Librarian')
|
28
|
+
unless items.size == (items.size - user.checkouts.overdue(Time.zone.now).collect(&:item).size)
|
29
|
+
return false
|
30
|
+
end
|
31
|
+
end
|
32
|
+
true
|
33
|
+
end
|
34
|
+
|
35
|
+
def is_reserved_by?(user)
|
36
|
+
return nil unless user
|
37
|
+
reserve = Reserve.waiting.where(:user_id => user.id, :manifestation_id => id).first
|
38
|
+
if reserve
|
39
|
+
reserve
|
40
|
+
else
|
41
|
+
false
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def is_reserved?
|
46
|
+
if self.reserves.present?
|
47
|
+
true
|
48
|
+
else
|
49
|
+
false
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def checkouts(start_date, end_date)
|
54
|
+
Checkout.completed(start_date, end_date).where(:item_id => self.items.collect(&:id))
|
55
|
+
end
|
56
|
+
|
57
|
+
def checkout_period(user)
|
58
|
+
if available_checkout_types(user)
|
59
|
+
available_checkout_types(user).collect(&:checkout_period).max || 0
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def reservation_expired_period(user)
|
64
|
+
if available_checkout_types(user)
|
65
|
+
available_checkout_types(user).collect(&:reservation_expired_period).max || 0
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def is_checked_out_by?(user)
|
70
|
+
if items.size > items.size - user.checkouts.not_returned.collect(&:item).size
|
71
|
+
true
|
72
|
+
else
|
73
|
+
false
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module EnjuCirculation
|
2
|
+
module EnjuProfile
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
def reset_checkout_icalendar_token
|
6
|
+
self.checkout_icalendar_token = SecureRandom.hex(16)
|
7
|
+
end
|
8
|
+
|
9
|
+
def delete_checkout_icalendar_token
|
10
|
+
self.checkout_icalendar_token = nil
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module EnjuCirculation
|
2
|
+
module EnjuUser
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
has_many :checkouts, :dependent => :nullify
|
7
|
+
has_many :reserves, :dependent => :destroy
|
8
|
+
has_many :reserved_manifestations, :through => :reserves, :source => :manifestation
|
9
|
+
has_many :checkout_stat_has_users
|
10
|
+
has_many :user_checkout_stats, :through => :checkout_stat_has_users
|
11
|
+
has_many :reserve_stat_has_users
|
12
|
+
has_many :user_reserve_stats, :through => :reserve_stat_has_users
|
13
|
+
has_many :baskets, :dependent => :destroy
|
14
|
+
|
15
|
+
before_destroy :check_item_before_destroy
|
16
|
+
end
|
17
|
+
|
18
|
+
def check_item_before_destroy
|
19
|
+
# TODO: 貸出記録を残す場合
|
20
|
+
if checkouts.size > 0
|
21
|
+
raise 'This user has items still checked out.'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def checked_item_count
|
26
|
+
checkout_count = {}
|
27
|
+
CheckoutType.all.each do |checkout_type|
|
28
|
+
# 資料種別ごとの貸出中の冊数を計算
|
29
|
+
checkout_count[:"#{checkout_type.name}"] = self.checkouts.count_by_sql(["
|
30
|
+
SELECT count(item_id) FROM checkouts
|
31
|
+
WHERE item_id IN (
|
32
|
+
SELECT id FROM items
|
33
|
+
WHERE checkout_type_id = ?
|
34
|
+
)
|
35
|
+
AND user_id = ? AND checkin_id IS NULL", checkout_type.id, self.id]
|
36
|
+
)
|
37
|
+
end
|
38
|
+
checkout_count
|
39
|
+
end
|
40
|
+
|
41
|
+
def reached_reservation_limit?(manifestation)
|
42
|
+
return true if profile.user_group.user_group_has_checkout_types.available_for_carrier_type(manifestation.carrier_type).where(:user_group_id => profile.user_group.id).collect(&:reservation_limit).max.to_i <= reserves.waiting.size
|
43
|
+
false
|
44
|
+
end
|
45
|
+
|
46
|
+
def has_overdue?(day = 1)
|
47
|
+
true if checkouts.where(checkin_id: nil).where(Checkout.arel_table[:due_date].lt day.days.ago).count >= 1
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module EnjuCirculation
|
2
|
+
module EnjuUserGroup
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
has_many :user_group_has_checkout_types, dependent: :destroy
|
7
|
+
has_many :checkout_types, through: :user_group_has_checkout_types
|
8
|
+
has_many :lending_policies
|
9
|
+
accepts_nested_attributes_for :user_group_has_checkout_types, :allow_destroy => true, :reject_if => :all_blank
|
10
|
+
|
11
|
+
validates_numericality_of :number_of_day_to_notify_due_date,
|
12
|
+
:number_of_day_to_notify_overdue,
|
13
|
+
:number_of_time_to_notify_overdue,
|
14
|
+
:greater_than_or_equal_to => 0
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module EnjuCirculation
|
2
|
+
module EnjuWithdraw
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
before_save :withdraw!, on: :create
|
7
|
+
end
|
8
|
+
|
9
|
+
def withdraw!
|
10
|
+
circulation_status = CirculationStatus.where(name: 'Removed').first
|
11
|
+
item.update_column(:circulation_status_id, circulation_status.id) if circulation_status
|
12
|
+
item.use_restriction = UseRestriction.where(name: 'Not For Loan').first
|
13
|
+
item.index!
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -9,7 +9,7 @@ class ManifestationCheckoutStatStateMachine
|
|
9
9
|
|
10
10
|
after_transition(to: :started) do |manifestation_checkout_stat|
|
11
11
|
manifestation_checkout_stat.update_column(:started_at, Time.zone.now)
|
12
|
-
|
12
|
+
manifestation_checkout_stat.calculate_count!
|
13
13
|
end
|
14
14
|
|
15
15
|
after_transition(to: :completed) do |manifestation_checkout_stat|
|
data/app/models/reserve.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
1
|
class Reserve < ActiveRecord::Base
|
3
2
|
include Statesman::Adapters::ActiveRecordQueries
|
4
3
|
scope :hold, -> { where('item_id IS NOT NULL') }
|
@@ -60,6 +59,12 @@ class Reserve < ActiveRecord::Base
|
|
60
59
|
validate :check_expired_at
|
61
60
|
before_validation :set_user, on: :update
|
62
61
|
before_validation :set_request_status, on: :create
|
62
|
+
after_save do
|
63
|
+
if item
|
64
|
+
item.checkouts.map{|checkout| checkout.index}
|
65
|
+
Sunspot.commit
|
66
|
+
end
|
67
|
+
end
|
63
68
|
|
64
69
|
attr_accessor :user_number, :item_identifier, :force_retaining
|
65
70
|
|
@@ -86,7 +91,7 @@ class Reserve < ActiveRecord::Base
|
|
86
91
|
end
|
87
92
|
time :created_at
|
88
93
|
text :item_identifier do
|
89
|
-
manifestation.items.pluck(:item_identifier)
|
94
|
+
manifestation.items.pluck(:item_identifier) if manifestation
|
90
95
|
end
|
91
96
|
text :title do
|
92
97
|
manifestation.try(:titles)
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class CarrierTypeHasCheckoutTypePolicy < ApplicationPolicy
|
2
|
+
def index?
|
3
|
+
user.try(:has_role?, 'Librarian')
|
4
|
+
end
|
5
|
+
|
6
|
+
def show?
|
7
|
+
user.try(:has_role?, 'Librarian')
|
8
|
+
end
|
9
|
+
|
10
|
+
def create?
|
11
|
+
user.try(:has_role?, 'Administrator')
|
12
|
+
end
|
13
|
+
|
14
|
+
def update?
|
15
|
+
user.try(:has_role?, 'Administrator')
|
16
|
+
end
|
17
|
+
|
18
|
+
def destroy?
|
19
|
+
user.try(:has_role?, 'Administrator')
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class CheckedItemPolicy < ApplicationPolicy
|
2
|
+
def index?
|
3
|
+
user.try(:has_role?, 'Librarian')
|
4
|
+
end
|
5
|
+
|
6
|
+
def show?
|
7
|
+
user.try(:has_role?, 'Librarian')
|
8
|
+
end
|
9
|
+
|
10
|
+
def create?
|
11
|
+
user.try(:has_role?, 'Librarian')
|
12
|
+
end
|
13
|
+
|
14
|
+
def update?
|
15
|
+
user.try(:has_role?, 'Librarian')
|
16
|
+
end
|
17
|
+
|
18
|
+
def destroy?
|
19
|
+
user.try(:has_role?, 'Librarian')
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class CheckinPolicy < ApplicationPolicy
|
2
|
+
def index?
|
3
|
+
user.try(:has_role?, 'Librarian')
|
4
|
+
end
|
5
|
+
|
6
|
+
def show?
|
7
|
+
user.try(:has_role?, 'Librarian')
|
8
|
+
end
|
9
|
+
|
10
|
+
def create?
|
11
|
+
user.try(:has_role?, 'Librarian')
|
12
|
+
end
|
13
|
+
|
14
|
+
def update?
|
15
|
+
user.try(:has_role?, 'Librarian')
|
16
|
+
end
|
17
|
+
|
18
|
+
def destroy?
|
19
|
+
user.try(:has_role?, 'Librarian')
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
class CheckoutPolicy < ApplicationPolicy
|
2
|
+
def index?
|
3
|
+
true
|
4
|
+
end
|
5
|
+
|
6
|
+
def show?
|
7
|
+
if user.try(:has_role?, 'Librarian')
|
8
|
+
true
|
9
|
+
elsif user and user == record.user
|
10
|
+
true
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def create?
|
15
|
+
user.try(:has_role?, 'Librarian')
|
16
|
+
end
|
17
|
+
|
18
|
+
def update?
|
19
|
+
if user.try(:has_role?, 'Librarian')
|
20
|
+
true
|
21
|
+
elsif user and user == record.user
|
22
|
+
true
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def destroy?
|
27
|
+
if record.checkin
|
28
|
+
if user.try(:has_role?, 'Librarian')
|
29
|
+
true
|
30
|
+
elsif user and user == record.user
|
31
|
+
true
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def remove_all?
|
37
|
+
true if user.try(:has_role?, 'User')
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class CheckoutTypePolicy < ApplicationPolicy
|
2
|
+
def index?
|
3
|
+
true if user.try(:has_role?, 'Librarian')
|
4
|
+
end
|
5
|
+
|
6
|
+
def show?
|
7
|
+
true if user.try(:has_role?, 'Librarian')
|
8
|
+
end
|
9
|
+
|
10
|
+
def create?
|
11
|
+
true if user.try(:has_role?, 'Administrator')
|
12
|
+
end
|
13
|
+
|
14
|
+
def update?
|
15
|
+
true if user.try(:has_role?, 'Administrator')
|
16
|
+
end
|
17
|
+
|
18
|
+
def destroy?
|
19
|
+
if user.try(:has_role?, 'Administrator')
|
20
|
+
true if record.items.empty?
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class CirculationStatusPolicy < ApplicationPolicy
|
2
|
+
def index?
|
3
|
+
true
|
4
|
+
end
|
5
|
+
|
6
|
+
def show?
|
7
|
+
true if user.try(:has_role?, 'Librarian')
|
8
|
+
end
|
9
|
+
|
10
|
+
def create?
|
11
|
+
false
|
12
|
+
end
|
13
|
+
|
14
|
+
def update?
|
15
|
+
if user.try(:has_role?, 'Administrator')
|
16
|
+
true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def destroy?
|
21
|
+
false
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class DemandPolicy < ApplicationPolicy
|
2
|
+
def index?
|
3
|
+
true if user.try(:has_role?, 'Librarian')
|
4
|
+
end
|
5
|
+
|
6
|
+
def show?
|
7
|
+
true if user.try(:has_role?, 'Librarian')
|
8
|
+
end
|
9
|
+
|
10
|
+
def create?
|
11
|
+
true if user.try(:has_role?, 'Librarian')
|
12
|
+
end
|
13
|
+
|
14
|
+
def update?
|
15
|
+
true if user.try(:has_role?, 'Librarian')
|
16
|
+
end
|
17
|
+
|
18
|
+
def destroy?
|
19
|
+
true if user.try(:has_role?, 'Librarian')
|
20
|
+
end
|
21
|
+
end
|