Class: CheckedItem
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- CheckedItem
- Defined in:
- app/models/checked_item.rb
Instance Attribute Summary collapse
-
#ignore_restriction ⇒ Object
Returns the value of attribute ignore_restriction.
-
#item_identifier ⇒ Object
Returns the value of attribute item_identifier.
Instance Method Summary collapse
Instance Attribute Details
#ignore_restriction ⇒ Object
Returns the value of attribute ignore_restriction.
15 16 17 |
# File 'app/models/checked_item.rb', line 15 def ignore_restriction @ignore_restriction end |
#item_identifier ⇒ Object
Returns the value of attribute item_identifier.
15 16 17 |
# File 'app/models/checked_item.rb', line 15 def item_identifier @item_identifier end |
Instance Method Details
#available_for_checkout? ⇒ Boolean
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/models/checked_item.rb', line 17 def available_for_checkout? if self.item.blank? errors[:base] << I18n.t('activerecord.errors.messages.checked_item.item_not_found') return false end if item.rent? errors[:base] << I18n.t('activerecord.errors.messages.checked_item.already_checked_out') end unless item.available_for_checkout? errors[:base] << I18n.t('activerecord.errors.messages.checked_item.not_available_for_checkout') return false end if item_checkout_type.blank? errors[:base] << I18n.t('activerecord.errors.messages.checked_item.this_group_cannot_checkout') return false end # ここまでは絶対に貸出ができない場合 return true if self.ignore_restriction == "1" if item.not_for_loan? errors[:base] << I18n.t('activerecord.errors.messages.checked_item.not_available_for_checkout') end if item.reserved? if self.item.manifestation.next_reservation.user == self.basket.user self.item.manifestation.next_reservation.sm_complete else errors[:base] << I18n.t('activerecord.errors.messages.checked_item.reserved_item_included') end end checkout_count = basket.user.checked_item_count CheckoutType.all.each do |checkout_type| #carrier_type = self.item.manifestation.carrier_type if checkout_count[:"#{checkout_type.name}"] + self.basket.checked_items.count(:id) >= self.item_checkout_type.checkout_limit errors[:base] << I18n.t('activerecord.errors.messages.checked_item.excessed_checkout_limit') break end end if errors[:base].empty? true else false end end |
#item_checkout_type ⇒ Object
68 69 70 71 72 |
# File 'app/models/checked_item.rb', line 68 def item_checkout_type if item and basket basket.user.user_group.user_group_has_checkout_types.available_for_item(item).first end end |
#set_due_date ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'app/models/checked_item.rb', line 74 def set_due_date return nil unless self.item_checkout_type lending_rule = self.item.lending_rule(self.basket.user) return nil if lending_rule.nil? if lending_rule.fixed_due_date.blank? #self.due_date = item_checkout_type.checkout_period.days.since Time.zone.today self.due_date = lending_rule.loan_period.days.since(Time.zone.now).end_of_day else #self.due_date = item_checkout_type.fixed_due_date self.due_date = lending_rule.fixed_due_date.tomorrow.end_of_day end # 返却期限日が閉館日の場合 while item.shelf.library.closed?(due_date) if item_checkout_type.set_due_date_before_closing_day self.due_date = due_date.yesterday.end_of_day else self.due_date = due_date.tomorrow.end_of_day end end return self.due_date end |