enju_circulation 0.3.9 → 0.4.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (181) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -3
  3. data/app/controllers/checkins_controller.rb +2 -2
  4. data/app/controllers/user_group_has_checkout_types_controller.rb +1 -1
  5. data/app/helpers/items_helper.rb +3 -3
  6. data/app/models/checked_item.rb +7 -17
  7. data/app/models/checkin.rb +3 -2
  8. data/app/models/checkout.rb +2 -2
  9. data/app/models/checkout_stat_has_user.rb +1 -1
  10. data/app/models/checkout_type.rb +9 -7
  11. data/app/models/circulation_status.rb +9 -8
  12. data/app/models/concerns/enju_circulation/enju_item.rb +2 -46
  13. data/app/models/concerns/enju_circulation/enju_user_group.rb +0 -1
  14. data/app/models/concerns/enju_circulation/enju_withdraw.rb +1 -7
  15. data/app/models/manifestation_checkout_stat_transition.rb +1 -1
  16. data/app/models/manifestation_reserve_stat_transition.rb +1 -1
  17. data/app/models/reserve.rb +5 -5
  18. data/app/models/reserve_state_machine.rb +3 -2
  19. data/app/models/reserve_transition.rb +1 -1
  20. data/app/models/retain.rb +15 -0
  21. data/app/models/user_checkout_stat_transition.rb +1 -1
  22. data/app/models/user_group_has_checkout_type.rb +15 -37
  23. data/app/models/user_reserve_stat_transition.rb +1 -1
  24. data/app/views/carrier_type_has_checkout_types/_form.html.erb +2 -2
  25. data/app/views/carrier_type_has_checkout_types/index.html.erb +2 -2
  26. data/app/views/carrier_type_has_checkout_types/show.html.erb +2 -2
  27. data/app/views/carrier_types/_carrier_type_has_checkout_type_fields.html.erb +1 -1
  28. data/app/views/checked_items/new.html.erb +1 -1
  29. data/app/views/checkins/_checkin.html.erb +1 -1
  30. data/app/views/checkout_types/_form.html.erb +1 -1
  31. data/app/views/checkout_types/index.html.erb +1 -1
  32. data/app/views/checkout_types/show.html.erb +2 -2
  33. data/app/views/checkouts/_index_user.html.erb +1 -1
  34. data/app/views/checkouts/_list.html.erb +2 -9
  35. data/app/views/checkouts/index.atom.builder +1 -1
  36. data/app/views/checkouts/index.ics.erb +1 -1
  37. data/app/views/checkouts/index.rss.builder +1 -1
  38. data/app/views/circulation_statuses/_form.html.erb +1 -1
  39. data/app/views/circulation_statuses/index.html.erb +1 -1
  40. data/app/views/circulation_statuses/show.html.erb +1 -1
  41. data/app/views/item_has_use_restrictions/index.html.erb +1 -1
  42. data/app/views/item_has_use_restrictions/show.html.erb +1 -1
  43. data/app/views/manifestation_checkout_stats/_group_by_carrier_type.html.erb +3 -3
  44. data/app/views/manifestation_checkout_stats/_group_by_checkout_type.html.erb +3 -3
  45. data/app/views/manifestations/_circulation_status.html.erb +3 -3
  46. data/app/views/profiles/_submenu_checkout.html.erb +1 -1
  47. data/app/views/reserves/_new.html.erb +1 -1
  48. data/app/views/reserves/_new_user.html.erb +1 -1
  49. data/app/views/reserves/edit.html.erb +1 -1
  50. data/app/views/reserves/index.atom.builder +1 -1
  51. data/app/views/reserves/index.html.erb +1 -1
  52. data/app/views/reserves/index.rss.builder +1 -1
  53. data/app/views/reserves/show.html.erb +1 -1
  54. data/app/views/use_restrictions/_form.html.erb +1 -1
  55. data/app/views/use_restrictions/index.html.erb +1 -1
  56. data/app/views/use_restrictions/show.html.erb +1 -1
  57. data/app/views/user_group_has_checkout_types/edit.html.erb +4 -4
  58. data/app/views/user_group_has_checkout_types/index.html.erb +2 -2
  59. data/app/views/user_group_has_checkout_types/new.html.erb +4 -4
  60. data/app/views/user_group_has_checkout_types/show.html.erb +4 -4
  61. data/app/views/user_groups/_user_group_has_checkout_type_fields.html.erb +2 -2
  62. data/config/locales/translation_en.yml +1 -14
  63. data/config/locales/translation_ja.yml +1 -14
  64. data/config/routes.rb +1 -2
  65. data/db/migrate/20110627122938_add_number_of_day_to_notify_overdue_to_user_group.rb +3 -3
  66. data/db/migrate/20190508160525_create_retains.rb +10 -0
  67. data/db/migrate/20190629134017_rename_user_group_has_checkout_type_due_date_before_to_due_date_after.rb +5 -0
  68. data/db/migrate/20190706052525_add_display_name_translations_to_circulation_status.rb +5 -0
  69. data/db/migrate/20190713114724_add_checkout_id_to_checkin.rb +5 -0
  70. data/db/migrate/20190814120827_add_display_name_translations_to_checkout_type.rb +5 -0
  71. data/lib/enju_circulation/version.rb +1 -1
  72. data/lib/generators/enju_circulation/setup/templates/db/fixtures/checkout_types.yml +3 -5
  73. data/lib/generators/enju_circulation/setup/templates/db/fixtures/circulation_statuses.yml +16 -48
  74. data/lib/tasks/enju_circulation_tasks.rake +7 -1
  75. data/spec/concerns/enju_accept_spec.rb +14 -14
  76. data/spec/controllers/accepts_controller_spec.rb +294 -0
  77. data/spec/controllers/baskets_controller_spec.rb +379 -0
  78. data/spec/controllers/checkins_controller_spec.rb +8 -130
  79. data/spec/controllers/items_controller_spec.rb +23 -43
  80. data/spec/dummy/app/mailers/application_mailer.rb +4 -0
  81. data/spec/dummy/app/models/user.rb +1 -1
  82. data/spec/dummy/bin/bundle +1 -1
  83. data/spec/dummy/bin/setup +1 -3
  84. data/spec/dummy/bin/update +4 -2
  85. data/spec/dummy/bin/yarn +3 -3
  86. data/spec/dummy/config/database.yml +70 -9
  87. data/spec/dummy/config/initializers/assets.rb +1 -0
  88. data/spec/dummy/db/development.sqlite3 +0 -0
  89. data/spec/dummy/db/migrate/113_create_events.rb +2 -4
  90. data/spec/dummy/db/migrate/20081028093607_create_event_import_files.rb +2 -4
  91. data/spec/dummy/db/migrate/20090519203307_create_participates.rb +2 -4
  92. data/spec/dummy/db/migrate/20100925074639_create_event_import_results.rb +2 -2
  93. data/spec/dummy/db/migrate/20140720192418_add_default_library_id_to_event_import_file.rb +1 -1
  94. data/spec/dummy/db/migrate/20140812152348_create_event_export_files.rb +1 -1
  95. data/spec/dummy/db/migrate/20140814070854_add_default_event_category_id_to_event_import_file.rb +1 -1
  96. data/spec/dummy/db/migrate/20151128142913_create_places.rb +14 -0
  97. data/spec/dummy/db/migrate/20151201163718_add_place_id_to_event.rb +5 -0
  98. data/spec/dummy/db/migrate/20160703184258_add_most_recent_to_event_import_file_transitions.rb +9 -0
  99. data/spec/dummy/db/migrate/20160703184311_add_most_recent_to_event_export_file_transitions.rb +9 -0
  100. data/spec/dummy/db/migrate/20180107160726_add_constraints_to_most_recent_for_user_import_file_transitions.rb +1 -1
  101. data/spec/dummy/db/migrate/20180107160740_add_constraints_to_most_recent_for_user_export_file_transitions.rb +1 -1
  102. data/spec/dummy/db/migrate/20180107164558_add_constraints_to_most_recent_for_event_import_file_transitions.rb +13 -0
  103. data/spec/dummy/db/migrate/20180107164617_add_constraints_to_most_recent_for_event_export_file_transitions.rb +13 -0
  104. data/spec/dummy/db/migrate/20181119170645_add_foreign_key_to_events_referencing_event_categories.rb +5 -0
  105. data/spec/dummy/db/migrate/20190630113817_add_display_name_translations_to_library_group.rb +12 -0
  106. data/spec/dummy/db/migrate/20190630115523_add_login_banner_translations_to_library_group.rb +6 -0
  107. data/spec/dummy/db/migrate/20190630151446_add_display_name_translations_to_role.rb +5 -0
  108. data/spec/dummy/db/migrate/20190630153136_add_display_name_translations_to_event.rb +6 -0
  109. data/spec/dummy/db/migrate/20190712163038_add_display_name_translations_to_carrier_type.rb +21 -0
  110. data/spec/dummy/db/migrate/20190713114940_add_profile_id_to_user.rb +5 -0
  111. data/spec/dummy/db/migrate/20190713115451_add_full_name_translations_to_profile.rb +5 -0
  112. data/spec/dummy/db/schema.rb +221 -184
  113. data/spec/dummy/db/test.sqlite3 +0 -0
  114. data/spec/dummy/private/system/carrier_types/attachments/000/000/001/original/book.png +0 -0
  115. data/spec/dummy/private/system/carrier_types/attachments/000/000/001/thumb/book.png +0 -0
  116. data/spec/factories/accept.rb +1 -1
  117. data/spec/factories/item.rb +4 -4
  118. data/spec/factories/reserve.rb +1 -5
  119. data/spec/fixtures/carrier_types.yml +16 -15
  120. data/spec/fixtures/checkins.yml +2 -1
  121. data/spec/fixtures/checkout_stat_has_users.yml +1 -1
  122. data/spec/fixtures/checkout_types.yml +11 -10
  123. data/spec/fixtures/checkouts.yml +2 -2
  124. data/spec/fixtures/circulation_statuses.yml +26 -34
  125. data/spec/fixtures/content_types.yml +20 -31
  126. data/spec/fixtures/event_categories.yml +23 -23
  127. data/spec/fixtures/frequencies.yml +17 -25
  128. data/spec/fixtures/items.yml +1 -1
  129. data/spec/fixtures/libraries.yml +30 -31
  130. data/spec/fixtures/library_groups.yml +43 -20
  131. data/spec/fixtures/request_status_types.yml +14 -14
  132. data/spec/fixtures/request_types.yml +13 -13
  133. data/spec/fixtures/reserve_transitions.yml +1 -1
  134. data/spec/fixtures/reserves.yml +3 -3
  135. data/spec/fixtures/roles.yml +22 -5
  136. data/spec/fixtures/shelves.yml +16 -15
  137. data/spec/fixtures/user_group_has_checkout_types.yml +24 -24
  138. data/spec/fixtures/user_groups.yml +23 -3
  139. data/spec/helpers/items_helper_spec.rb +1 -1
  140. data/spec/models/checkin_spec.rb +2 -1
  141. data/spec/models/checkout_spec.rb +2 -2
  142. data/spec/models/checkout_stat_has_user_spec.rb +1 -1
  143. data/spec/models/checkout_type_spec.rb +8 -7
  144. data/spec/models/circulation_status_spec.rb +8 -7
  145. data/spec/models/item_spec.rb +6 -8
  146. data/spec/models/manifestation_spec.rb +15 -18
  147. data/spec/models/reserve_spec.rb +3 -3
  148. data/spec/models/resource_export_file_spec.rb +0 -15
  149. data/spec/models/retain_spec.rb +16 -0
  150. data/spec/models/user_group_has_checkout_type_spec.rb +15 -32
  151. data/spec/models/withdraw_spec.rb +4 -6
  152. data/spec/policies/manifestation_policy_spec.rb +2 -1
  153. data/spec/rails_helper.rb +10 -3
  154. data/spec/views/items/index.html.erb_spec.rb +1 -4
  155. metadata +396 -446
  156. data/app/controllers/lending_policies_controller.rb +0 -106
  157. data/app/models/lending_policy.rb +0 -30
  158. data/app/views/lending_policies/_form.html.erb +0 -41
  159. data/app/views/lending_policies/edit.html.erb +0 -13
  160. data/app/views/lending_policies/index.html.erb +0 -42
  161. data/app/views/lending_policies/new.html.erb +0 -12
  162. data/app/views/lending_policies/show.html.erb +0 -50
  163. data/db/migrate/20090831220301_create_lending_policies.rb +0 -21
  164. data/spec/controllers/lending_policies_controller_spec.rb +0 -444
  165. data/spec/controllers/withdraws_controller_spec.rb +0 -26
  166. data/spec/dummy/config/locales/en.yml +0 -208
  167. data/spec/dummy/config/locales/ja.yml +0 -200
  168. data/spec/dummy/db/migrate/20190818075603_add_memo_to_manifestation.rb +0 -5
  169. data/spec/dummy/db/migrate/20190818075628_add_memo_to_item.rb +0 -5
  170. data/spec/dummy/db/migrate/20200425072340_create_manifestation_custom_properties.rb +0 -12
  171. data/spec/dummy/db/migrate/20200425072349_create_item_custom_properties.rb +0 -12
  172. data/spec/dummy/db/migrate/20200425074758_create_manifestation_custom_values.rb +0 -12
  173. data/spec/dummy/db/migrate/20200425074822_create_item_custom_values.rb +0 -12
  174. data/spec/fixtures/accepts.yml +0 -9
  175. data/spec/fixtures/bookstores.yml +0 -99
  176. data/spec/fixtures/budget_types.yml +0 -30
  177. data/spec/fixtures/exemplifies.yml +0 -168
  178. data/spec/fixtures/lending_policies.yml +0 -98
  179. data/spec/models/lending_policy_spec.rb +0 -23
  180. data/spec/system/items_spec.rb +0 -21
  181. data/spec/system/user_group_has_checkout_types.rb +0 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8acae0635971690b1966d9ec8c5c3f5c608528c624feb76f201ce0cc90b473e4
4
- data.tar.gz: 60815d7876aee8efe0aba781e33cc919c2ff5af9830761dc1aff778398522bea
3
+ metadata.gz: ae2524b7384336afe28edefb0a5fd0ea8004c5ca9a56e87048df9047fade290b
4
+ data.tar.gz: c178fa1fb96decbd1e5b567055dda1e052e17e84da7e4101bdb2606f1c95e467
5
5
  SHA512:
6
- metadata.gz: ec55abc5f36563dbba595a2984564c1f8f45911acf3fc24fdcddba3c4f0b0b3d66981081638a4ff7d768122ba510196e49d2546af9b4522b928d39d9aad6b1fe
7
- data.tar.gz: fc0727906cdea3789852dbee7c97684b600f4ca0b5aa143a8c75caff5c5f0f104a3ec6d284bb92c76a3d99121c974261341924a4d3450e94162c0dcde6fd5b9c
6
+ metadata.gz: 5f6c642dbfabfcce25d17386a11b4c34fc8aee9589b2147604c7efd8e8314cfea7440d6774d23593380657da02cda3abba621991ff140336bab16318cb63251f
7
+ data.tar.gz: d2dcf749b0de72a7be4e976f16d15cd7f3397b228a23f3582b028f1a8a9849378e7c6688ebe64ab115fda2b40fa296d9e8019148fd184567a42cbd8787b1dad5
data/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  # EnjuCirculation
2
- [![Travis CI](https://travis-ci.com/next-l/enju_circulation.svg?branch=1.3)](https://travis-ci.com/next-l/enju_circulation)
3
- [![Coverage Status](https://coveralls.io/repos/github/next-l/enju_circulation/badge.svg?branch=1.3)](https://coveralls.io/github/next-l/enju_circulation?branch=1.3)
4
- [![security](https://hakiri.io/github/next-l/enju_circulation/1.3.svg)](https://hakiri.io/github/next-l/enju_circulation/1.3)
2
+ [![CircleCI](https://circleci.com/gh/next-l/enju_circulation/tree/2.x.svg?style=svg)](https://circleci.com/gh/next-l/enju_circulation/tree/2.x)
3
+ [![Coverage Status](https://coveralls.io/repos/github/next-l/enju_circulation/badge.svg?branch=2.x)](https://coveralls.io/github/next-l/enju_circulation?branch=2.x)
5
4
 
6
5
  This project rocks and uses MIT-LICENSE.
7
6
 
@@ -77,12 +77,12 @@ class CheckinsController < ApplicationController
77
77
  end
78
78
  flash[:message] << message if message
79
79
  format.html { redirect_to checkins_url(basket_id: @checkin.basket_id) }
80
- format.json { render json: {result: @checkin, messages: flash[:message]}, status: :created, location: @checkin }
80
+ format.json { render json: @checkin, status: :created, location: @checkin }
81
81
  format.js { redirect_to checkins_url(basket_id: @basket.id, format: :js) }
82
82
  else
83
83
  @checkins = @basket.checkins.page(1)
84
84
  format.html { render action: "new" }
85
- format.json { render json: {messages: @checkin.errors}, status: :unprocessable_entity }
85
+ format.json { render json: @checkin.errors, status: :unprocessable_entity }
86
86
  format.js { render action: "index" }
87
87
  end
88
88
  end
@@ -101,7 +101,7 @@ class UserGroupHasCheckoutTypesController < ApplicationController
101
101
  :user_group_id, :checkout_type_id,
102
102
  :checkout_limit, :checkout_period, :checkout_renewal_limit,
103
103
  :reservation_limit, :reservation_expired_period,
104
- :set_due_date_before_closing_day, :fixed_due_date, :note, :position,
104
+ :set_due_date_after_closing_day, :fixed_due_date, :note, :position,
105
105
  :user_group, :checkout_type
106
106
  )
107
107
  end
@@ -1,16 +1,16 @@
1
1
  module ItemsHelper
2
2
  def circulation_status_facet(facet)
3
3
  string = ''
4
- circulation_status = CirculationStatus.where(name: facet.value).select([:name, :display_name]).first
4
+ circulation_status = CirculationStatus.where(name: facet.value).select([:name, :display_name_translations]).first
5
5
  if circulation_status
6
6
  # string << form_icon(circulation_status)
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(filtered_params.merge(circulation_status: circulation_status.name, page: nil, view: nil, only_path: true)))
10
+ link_to("#{circulation_status.display_name} (" + facet.count.to_s + ")", url_for(filtered_params.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(filtered_params.merge(circulation_status: circulation_status.name, page: nil, view: nil, only_path: true)))
13
+ link_to("#{circulation_status.display_name} (" + facet.count.to_s + ")", url_for(filtered_params.merge(circulation_status: circulation_status.name, page: nil, view: nil, only_path: true)))
14
14
  end
15
15
  end
16
16
  end
@@ -82,26 +82,16 @@ class CheckedItem < ApplicationRecord
82
82
  if due_date_string.present?
83
83
  self.due_date = Time.zone.parse(due_date_string).try(:end_of_day)
84
84
  else
85
- lending_rule = item.lending_rule(basket.user)
86
- return nil if lending_rule.nil?
87
-
88
- if lending_rule.fixed_due_date.blank?
89
- # self.due_date = item_checkout_type.checkout_period.days.since Time.zone.today
90
- self.due_date = lending_rule.loan_period.days.since(Time.zone.now).end_of_day
91
- else
92
- # self.due_date = item_checkout_type.fixed_due_date
93
- self.due_date = lending_rule.fixed_due_date.tomorrow.end_of_day
94
- end
85
+ due_date = item_checkout_type.checkout_period.days.since Time.zone.today
95
86
  # 返却期限日が閉館日の場合
96
- while item.shelf.library.closed?(due_date)
97
- if item_checkout_type.set_due_date_before_closing_day
98
- self.due_date = due_date.yesterday.end_of_day
99
- else
100
- self.due_date = due_date.tomorrow.end_of_day
101
- end
87
+ if item.shelf.library.closed?(due_date) && item_checkout_type.set_due_date_after_closing_day
88
+ self.due_date = due_date.tomorrow.end_of_day
89
+ else
90
+ self.due_date = due_date.end_of_day
102
91
  end
103
92
  end
104
- return due_date
93
+
94
+ self
105
95
  end
106
96
 
107
97
  def set_item
@@ -1,7 +1,7 @@
1
1
  class Checkin < ApplicationRecord
2
2
  default_scope { order('checkins.id DESC') }
3
3
  scope :on, lambda {|date| where('created_at >= ? AND created_at < ?', date.beginning_of_day, date.tomorrow.beginning_of_day)}
4
- has_one :checkout
4
+ has_one :checkout, dependent: :nullify
5
5
  belongs_to :item, touch: true
6
6
  belongs_to :librarian, class_name: 'User'
7
7
  belongs_to :basket
@@ -91,5 +91,6 @@ end
91
91
  # basket_id :integer
92
92
  # created_at :datetime
93
93
  # updated_at :datetime
94
- # lock_version :integer default("0"), not null
94
+ # lock_version :integer default(0), not null
95
+ # checkin_id :bigint
95
96
  #
@@ -174,8 +174,8 @@ end
174
174
  # librarian_id :integer
175
175
  # basket_id :integer
176
176
  # due_date :datetime
177
- # checkout_renewal_count :integer default("0"), not null
178
- # lock_version :integer default("0"), not null
177
+ # checkout_renewal_count :integer default(0), not null
178
+ # lock_version :integer default(0), not null
179
179
  # created_at :datetime
180
180
  # updated_at :datetime
181
181
  # shelf_id :integer
@@ -17,7 +17,7 @@ end
17
17
  # id :integer not null, primary key
18
18
  # user_checkout_stat_id :integer not null
19
19
  # user_id :integer not null
20
- # checkouts_count :integer default("0"), not null
20
+ # checkouts_count :integer default(0), not null
21
21
  # created_at :datetime
22
22
  # updated_at :datetime
23
23
  #
@@ -12,17 +12,19 @@ class CheckoutType < ApplicationRecord
12
12
  has_many :items
13
13
 
14
14
  paginates_per 10
15
+ translates :display_name
15
16
  end
16
17
 
17
18
  # == Schema Information
18
19
  #
19
20
  # Table name: checkout_types
20
21
  #
21
- # id :integer not null, primary key
22
- # name :string not null
23
- # display_name :text
24
- # note :text
25
- # position :integer
26
- # created_at :datetime
27
- # updated_at :datetime
22
+ # id :integer not null, primary key
23
+ # name :string not null
24
+ # display_name :text
25
+ # note :text
26
+ # position :integer
27
+ # created_at :datetime
28
+ # updated_at :datetime
29
+ # display_name_translations :jsonb not null
28
30
  #
@@ -2,9 +2,9 @@ class CirculationStatus < ApplicationRecord
2
2
  include MasterModel
3
3
  validates :name, presence: true, format: { with: /\A[0-9A-Za-z][0-9A-Za-z_\-\s,]*[0-9a-z]\Z/ }
4
4
 
5
- default_scope { order('circulation_statuses.position') }
6
5
  scope :available_for_checkout, -> { where(name: 'Available On Shelf') }
7
6
  has_many :items
7
+ translates :display_name
8
8
 
9
9
  private
10
10
 
@@ -17,11 +17,12 @@ end
17
17
  #
18
18
  # Table name: circulation_statuses
19
19
  #
20
- # id :integer not null, primary key
21
- # name :string not null
22
- # display_name :text
23
- # note :text
24
- # position :integer
25
- # created_at :datetime
26
- # updated_at :datetime
20
+ # id :integer not null, primary key
21
+ # name :string not null
22
+ # display_name :text
23
+ # note :text
24
+ # position :integer
25
+ # created_at :datetime
26
+ # updated_at :datetime
27
+ # display_name_translations :jsonb not null
27
28
  #
@@ -35,36 +35,24 @@ module EnjuCirculation
35
35
  has_many :reserves
36
36
  has_many :checked_items
37
37
  has_many :baskets, through: :checked_items
38
- belongs_to :circulation_status
38
+ belongs_to :circulation_status, validate: true
39
39
  belongs_to :checkout_type
40
- has_many :lending_policies, dependent: :destroy
41
40
  has_one :item_has_use_restriction, dependent: :destroy
42
41
  has_one :use_restriction, through: :item_has_use_restriction
42
+ validates_associated :circulation_status, :checkout_type
43
43
  validates :circulation_status, :checkout_type, presence: true
44
- validate :check_circulation_status
45
-
46
44
  searchable do
47
45
  string :circulation_status do
48
46
  circulation_status.name
49
47
  end
50
48
  end
51
49
  accepts_nested_attributes_for :item_has_use_restriction
52
-
53
- before_update :delete_lending_policy
54
50
  end
55
51
 
56
52
  def set_circulation_status
57
53
  self.circulation_status = CirculationStatus.find_by(name: 'In Process') if circulation_status.nil?
58
54
  end
59
55
 
60
- def check_circulation_status
61
- #circulation_status.name_will_change!
62
- #return unless circulation_status.name_change.first == 'Removed'
63
- return unless circulation_status.name == 'Removed'
64
- errors[:base] << I18n.t('activerecord.errors.models.item.attributes.circulation_status_id.is_rented') if rented?
65
- errors[:base] << I18n.t('activerecord.errors.models.item.attributes.circulation_status_id.is_reserved') if reserved?
66
- end
67
-
68
56
  def checkout_status(user)
69
57
  return nil unless user
70
58
  user.profile.user_group.user_group_has_checkout_types.find_by(checkout_type_id: checkout_type.id)
@@ -80,10 +68,6 @@ module EnjuCirculation
80
68
  false
81
69
  end
82
70
 
83
- def rented?
84
- rent?
85
- end
86
-
87
71
  def reserved_by_user?(user)
88
72
  if manifestation.next_reservation
89
73
  return true if manifestation.next_reservation.user == user
@@ -105,8 +89,6 @@ module EnjuCirculation
105
89
  manifestation.next_reservation.transition_to!(:completed)
106
90
  manifestation.reload
107
91
  end
108
-
109
- reload
110
92
  update!(circulation_status: CirculationStatus.find_by(name: 'On Loan'))
111
93
  end
112
94
 
@@ -135,36 +117,10 @@ module EnjuCirculation
135
117
  false
136
118
  end
137
119
 
138
- def lending_rule(user)
139
- policy = lending_policies.find_by(user_group_id: user.profile.user_group.id)
140
- if policy
141
- policy
142
- else
143
- create_lending_policy(user)
144
- end
145
- end
146
-
147
120
  def not_for_loan?
148
121
  !manifestation.items.for_checkout.include?(self)
149
122
  end
150
123
 
151
- def create_lending_policy(user)
152
- rule = user.profile.user_group.user_group_has_checkout_types.find_by(checkout_type_id: checkout_type_id)
153
- return nil unless rule
154
- LendingPolicy.create!(
155
- item_id: id,
156
- user_group_id: rule.user_group_id,
157
- fixed_due_date: rule.fixed_due_date,
158
- loan_period: rule.checkout_period,
159
- renewal: rule.checkout_renewal_limit
160
- )
161
- end
162
-
163
- def delete_lending_policy
164
- return nil unless changes[:checkout_type_id]
165
- lending_policies.delete_all
166
- end
167
-
168
124
  def next_reservation
169
125
  Reserve.waiting.find_by(item_id: id)
170
126
  end
@@ -5,7 +5,6 @@ module EnjuCirculation
5
5
  included do
6
6
  has_many :user_group_has_checkout_types, dependent: :destroy
7
7
  has_many :checkout_types, through: :user_group_has_checkout_types
8
- has_many :lending_policies
9
8
  accepts_nested_attributes_for :user_group_has_checkout_types, allow_destroy: true, reject_if: :all_blank
10
9
 
11
10
  validates :number_of_day_to_notify_due_date,
@@ -3,8 +3,7 @@ module EnjuCirculation
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  included do
6
- before_create :withdraw!
7
- validate :check_item
6
+ before_save :withdraw!, on: :create
8
7
  end
9
8
 
10
9
  def withdraw!
@@ -13,10 +12,5 @@ module EnjuCirculation
13
12
  item.use_restriction = UseRestriction.where(name: 'Not For Loan').first
14
13
  item.index!
15
14
  end
16
-
17
- def check_item
18
- errors.add(:item_id, :is_rented) if item.try(:rent?)
19
- errors.add(:item_id, :is_reserved) if item.try(:reserved?)
20
- end
21
15
  end
22
16
  end
@@ -12,7 +12,7 @@ end
12
12
  #
13
13
  # id :integer not null, primary key
14
14
  # to_state :string
15
- # metadata :text default("{}")
15
+ # metadata :text default({})
16
16
  # sort_key :integer
17
17
  # manifestation_checkout_stat_id :integer
18
18
  # created_at :datetime
@@ -12,7 +12,7 @@ end
12
12
  #
13
13
  # id :integer not null, primary key
14
14
  # to_state :string
15
- # metadata :text default("{}")
15
+ # metadata :text default({})
16
16
  # sort_key :integer
17
17
  # manifestation_reserve_stat_id :integer
18
18
  # created_at :datetime
@@ -2,7 +2,7 @@ class Reserve < ApplicationRecord
2
2
  include Statesman::Adapters::ActiveRecordQueries
3
3
  scope :hold, -> { where('item_id IS NOT NULL') }
4
4
  scope :not_hold, -> { where(item_id: nil) }
5
- scope :waiting, -> {not_in_state(:completed, :expired).where('canceled_at IS NULL AND (expired_at > ? OR expired_at IS NULL)', Time.zone.now).order('reserves.id DESC')}
5
+ scope :waiting, -> {not_in_state(:completed, :expired, :retained).where('canceled_at IS NULL AND (expired_at > ? OR expired_at IS NULL)', Time.zone.now).order('reserves.id DESC')}
6
6
  scope :retained, -> {in_state(:retained).where('retained_at IS NOT NULL')}
7
7
  scope :completed, -> {in_state(:completed).where('checked_out_at IS NOT NULL')}
8
8
  scope :canceled, -> {in_state(:canceled).where('canceled_at IS NOT NULL')}
@@ -371,7 +371,7 @@ class Reserve < ApplicationRecord
371
371
  end
372
372
 
373
373
  def manifestation_must_include_item
374
- if manifestation && item && !completed?
374
+ if item_id.present? && !completed?
375
375
  errors[:base] << I18n.t('reserve.invalid_item') unless manifestation.items.include?(item)
376
376
  end
377
377
  end
@@ -404,10 +404,10 @@ end
404
404
  # canceled_at :datetime
405
405
  # expired_at :datetime
406
406
  # deleted_at :datetime
407
- # expiration_notice_to_patron :boolean default("0")
408
- # expiration_notice_to_library :boolean default("0")
407
+ # expiration_notice_to_patron :boolean default(FALSE)
408
+ # expiration_notice_to_library :boolean default(FALSE)
409
409
  # pickup_location_id :integer
410
410
  # retained_at :datetime
411
411
  # postponed_at :datetime
412
- # lock_version :integer default("0"), not null
412
+ # lock_version :integer default(0), not null
413
413
  #
@@ -14,15 +14,16 @@ class ReserveStateMachine
14
14
  transition from: :requested, to: [:retained, :canceled, :expired, :completed]
15
15
 
16
16
  after_transition(to: :requested) do |reserve|
17
- reserve.update(request_status_type: RequestStatusType.find_by(name: 'In Process'), item_id: nil, retained_at: nil)
17
+ reserve.update(request_status_type: RequestStatusType.where(name: 'In Process').first, item_id: nil, retained_at: nil)
18
18
  end
19
19
 
20
20
  after_transition(to: :retained) do |reserve|
21
21
  # TODO: 「取り置き中」の状態を正しく表す
22
- reserve.update(request_status_type: RequestStatusType.find_by(name: 'In Process'), retained_at: Time.zone.now)
22
+ reserve.update(request_status_type: RequestStatusType.where(name: 'In Process').first, retained_at: Time.zone.now)
23
23
  Reserve.transaction do
24
24
  if reserve.item
25
25
  other_reserves = reserve.item.reserves.waiting
26
+ other_reserves += reserve.item.reserves.in_state(:retained)
26
27
  other_reserves.each{|r|
27
28
  if r != reserve
28
29
  r.transition_to!(:postponed)
@@ -12,7 +12,7 @@ end
12
12
  #
13
13
  # id :integer not null, primary key
14
14
  # to_state :string
15
- # metadata :text default("{}")
15
+ # metadata :text default({})
16
16
  # sort_key :integer
17
17
  # reserve_id :integer
18
18
  # created_at :datetime
@@ -0,0 +1,15 @@
1
+ class Retain < ApplicationRecord
2
+ belongs_to :reserve
3
+ belongs_to :item
4
+ end
5
+
6
+ # == Schema Information
7
+ #
8
+ # Table name: retains
9
+ #
10
+ # id :bigint not null, primary key
11
+ # reserve_id :bigint not null
12
+ # item_id :bigint not null
13
+ # created_at :datetime not null
14
+ # updated_at :datetime not null
15
+ #
@@ -12,7 +12,7 @@ end
12
12
  #
13
13
  # id :integer not null, primary key
14
14
  # to_state :string
15
- # metadata :text default("{}")
15
+ # metadata :text default({})
16
16
  # sort_key :integer
17
17
  # user_checkout_stat_id :integer
18
18
  # created_at :datetime
@@ -13,31 +13,9 @@ class UserGroupHasCheckoutType < ApplicationRecord
13
13
  validates :checkout_renewal_limit, numericality: {only_integer: true, greater_than_or_equal_to: 0}
14
14
  validates :reservation_limit, numericality: {only_integer: true, greater_than_or_equal_to: 0}
15
15
  validates :reservation_expired_period, numericality: {only_integer: true, greater_than_or_equal_to: 0}
16
- after_update :update_lending_policy
17
16
 
18
17
  acts_as_list scope: :user_group_id
19
18
 
20
- def create_lending_policy
21
- checkout_type.items.find_each do |item|
22
- policy = LendingPolicy.where(item_id: item.id, user_group_id: user_group_id).select(:id).first
23
- unless policy
24
- sql = ['INSERT INTO lending_policies (item_id, user_group_id, loan_period, renewal, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?)', item.id, user_group_id, checkout_period, checkout_renewal_limit, Time.zone.now, Time.zone.now]
25
- ActiveRecord::Base.connection.execute(
26
- self.class.send(:sanitize_sql_array, sql)
27
- )
28
- end
29
- end
30
- end
31
-
32
- def update_lending_policy
33
- checkout_type.items.each do |item|
34
- sql = ['UPDATE lending_policies SET loan_period = ?, renewal = ?, updated_at = ? WHERE user_group_id = ? AND item_id = ?', checkout_period, checkout_renewal_limit, Time.zone.now, user_group_id, item.id]
35
- ActiveRecord::Base.connection.execute(
36
- self.class.send(:sanitize_sql_array, sql)
37
- )
38
- end
39
- end
40
-
41
19
  def self.update_current_checkout_count
42
20
  sql = [
43
21
  'SELECT count(checkouts.id) as current_checkout_count,
@@ -68,19 +46,19 @@ end
68
46
  #
69
47
  # Table name: user_group_has_checkout_types
70
48
  #
71
- # id :integer not null, primary key
72
- # user_group_id :integer not null
73
- # checkout_type_id :integer not null
74
- # checkout_limit :integer default("0"), not null
75
- # checkout_period :integer default("0"), not null
76
- # checkout_renewal_limit :integer default("0"), not null
77
- # reservation_limit :integer default("0"), not null
78
- # reservation_expired_period :integer default("7"), not null
79
- # set_due_date_before_closing_day :boolean default("0"), not null
80
- # fixed_due_date :datetime
81
- # note :text
82
- # position :integer
83
- # created_at :datetime
84
- # updated_at :datetime
85
- # current_checkout_count :integer
49
+ # id :integer not null, primary key
50
+ # user_group_id :integer not null
51
+ # checkout_type_id :integer not null
52
+ # checkout_limit :integer default(0), not null
53
+ # checkout_period :integer default(0), not null
54
+ # checkout_renewal_limit :integer default(0), not null
55
+ # reservation_limit :integer default(0), not null
56
+ # reservation_expired_period :integer default(7), not null
57
+ # set_due_date_after_closing_day :boolean default(FALSE), not null
58
+ # fixed_due_date :datetime
59
+ # note :text
60
+ # position :integer
61
+ # created_at :datetime
62
+ # updated_at :datetime
63
+ # current_checkout_count :integer
86
64
  #
@@ -12,7 +12,7 @@ end
12
12
  #
13
13
  # id :integer not null, primary key
14
14
  # to_state :string
15
- # metadata :text default("{}")
15
+ # metadata :text default({})
16
16
  # sort_key :integer
17
17
  # user_reserve_stat_id :integer
18
18
  # created_at :datetime
@@ -3,11 +3,11 @@
3
3
 
4
4
  <div class="field">
5
5
  <%= f.label t('activerecord.models.carrier_type') -%><br />
6
- <%= f.select(:carrier_type_id, @carrier_types.collect{|m| [m.display_name.localize, m.id]}, include_blank: true) -%>
6
+ <%= f.select(:carrier_type_id, @carrier_types.collect{|m| [m.display_name, m.id]}, include_blank: true) -%>
7
7
  </div>
8
8
  <div class="field">
9
9
  <%= f.label t('activerecord.models.checkout_type') -%><br />
10
- <%= f.select(:checkout_type_id, @checkout_types.collect{|c| [c.display_name.localize, c.id]}, include_blank: true) -%>
10
+ <%= f.select(:checkout_type_id, @checkout_types.collect{|c| [c.display_name, c.id]}, include_blank: true) -%>
11
11
  </div>
12
12
  <div class="field">
13
13
  <%= f.label :note -%><br />
@@ -12,8 +12,8 @@
12
12
 
13
13
  <%- @carrier_type_has_checkout_types.each do |carrier_type_has_checkout_type| -%>
14
14
  <tr class="line<%= cycle("0", "1") -%>">
15
- <td><%= link_to carrier_type_has_checkout_type.carrier_type.display_name.localize, carrier_type_has_checkout_type.carrier_type -%></td>
16
- <td><%= link_to carrier_type_has_checkout_type.checkout_type.display_name.localize, carrier_type_has_checkout_type.checkout_type -%></td>
15
+ <td><%= link_to carrier_type_has_checkout_type.carrier_type.display_name, carrier_type_has_checkout_type.carrier_type -%></td>
16
+ <td><%= link_to carrier_type_has_checkout_type.checkout_type.display_name, carrier_type_has_checkout_type.checkout_type -%></td>
17
17
  <td><%= carrier_type_has_checkout_type.note -%></td>
18
18
  <td>
19
19
  <%= link_to t('page.show'), carrier_type_has_checkout_type -%>
@@ -5,12 +5,12 @@
5
5
 
6
6
  <p>
7
7
  <strong><%= t('activerecord.models.carrier_type') -%>:</strong>
8
- <%= link_to @carrier_type_has_checkout_type.carrier_type.display_name.localize, @carrier_type_has_checkout_type.carrier_type -%>
8
+ <%= link_to @carrier_type_has_checkout_type.carrier_type.display_name, @carrier_type_has_checkout_type.carrier_type -%>
9
9
  </p>
10
10
 
11
11
  <p>
12
12
  <strong><%= t('activerecord.models.checkout_type') -%>:</strong>
13
- <%= link_to @carrier_type_has_checkout_type.checkout_type.display_name.localize, @carrier_type_has_checkout_type.checkout_type -%>
13
+ <%= link_to @carrier_type_has_checkout_type.checkout_type.display_name, @carrier_type_has_checkout_type.checkout_type -%>
14
14
  </p>
15
15
 
16
16
  <p>
@@ -1,5 +1,5 @@
1
1
  <div class="nested-fields">
2
2
  <%= f.label :checkout_type_id -%>
3
- <%= f.select(:checkout_type_id, @checkout_types.collect{|c| [c.display_name.localize, c.id]}) %>
3
+ <%= f.select(:checkout_type_id, @checkout_types.collect{|c| [c.display_name, c.id]}) %>
4
4
  <%= link_to_remove_association t('page.remove'), f, data: {confirm: t('page.are_you_sure')} %><br />
5
5
  </div>
@@ -18,7 +18,7 @@
18
18
  <ul>
19
19
  <%- @basket.user.profile.user_group.user_group_has_checkout_types.each do |available_checkout_type| -%>
20
20
  <li>
21
- <%= available_checkout_type.checkout_type.display_name.localize -%>:
21
+ <%= available_checkout_type.checkout_type.display_name -%>:
22
22
  <%= @basket.user.checked_item_count[:"#{available_checkout_type.checkout_type.name}"] -%> / <%= available_checkout_type.checkout_limit -%>
23
23
  </li>
24
24
  <%- end -%>
@@ -15,7 +15,7 @@
15
15
  <% if checkin.item %>
16
16
  <%= link_to checkin.item.item_identifier, checkin.item -%>
17
17
  <br />
18
- (<%= link_to checkin.item.shelf.library.display_name.localize, checkin.item.shelf.library %>)
18
+ (<%= link_to checkin.item.shelf.library.display_name, checkin.item.shelf.library %>)
19
19
  <% if defined?(EnjuInterLibraryLoan) %>
20
20
  <br />
21
21
  <%- unless checkin.item.shelf.library == current_user.library -%>
@@ -3,7 +3,7 @@
3
3
 
4
4
  <div class="field">
5
5
  <%= f.label :name %><br />
6
- <%= f.text_field :name %>
6
+ <%= f.text_field :name, required: true %>
7
7
  </div>
8
8
  <div class="field">
9
9
  <%= f.label :display_name %><br />
@@ -23,7 +23,7 @@
23
23
  </td>
24
24
  <td><%= checkout_type.name -%></td>
25
25
  <td>
26
- <%= link_to checkout_type.display_name.localize, checkout_type -%>
26
+ <%= link_to checkout_type.display_name, checkout_type -%>
27
27
  <br />
28
28
  <%= checkout_type.note %>
29
29
  </td>
@@ -10,14 +10,14 @@
10
10
 
11
11
  <p>
12
12
  <strong><%= t('activerecord.attributes.checkout_type.display_name') -%>:</strong>
13
- <%= @checkout_type.display_name.localize -%>
13
+ <%= @checkout_type.display_name -%>
14
14
  </p>
15
15
 
16
16
  <p>
17
17
  <strong><%= t('activerecord.models.user_group') -%></strong>
18
18
  <ul>
19
19
  <%- @checkout_type.user_group_has_checkout_types.each do |available_user_group| -%>
20
- <li><%= link_to available_user_group.user_group.display_name.localize, available_user_group.user_group -%></li>
20
+ <li><%= link_to available_user_group.user_group.display_name, available_user_group.user_group -%></li>
21
21
  <%- end -%>
22
22
  </ul>
23
23
 
@@ -15,7 +15,7 @@
15
15
  <ul>
16
16
  <%- user.profile.user_group.user_group_has_checkout_types.each do |available_checkout_type| -%>
17
17
  <li>
18
- <%= available_checkout_type.checkout_type.display_name.localize -%>:
18
+ <%= available_checkout_type.checkout_type.display_name -%>:
19
19
  <%= user.checked_item_count[:"#{available_checkout_type.checkout_type.name}"] -%> / <%= available_checkout_type.checkout_limit -%>
20
20
  </li>
21
21
  <%- end -%>