Class: Cats::Core::TransportRequisition
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Cats::Core::TransportRequisition
- Defined in:
- app/models/cats/core/transport_requisition.rb
Constant Summary collapse
Instance Method Summary collapse
Instance Method Details
#approve(user) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/models/cats/core/transport_requisition.rb', line 30 def approve(user) raise(StandardError, "Transport requisition is already approved.") if status == APPROVED begin self.status = APPROVED self.approved_by = user save! self rescue ActiveRecord::RecordInvalid => e error = e.record.errors.(:status)[0] raise(StandardError, error) end end |
#approved? ⇒ Boolean
44 45 46 |
# File 'app/models/cats/core/transport_requisition.rb', line 44 def approved? status == APPROVED end |
#quantity ⇒ Object
25 26 27 28 |
# File 'app/models/cats/core/transport_requisition.rb', line 25 def quantity quantities = transport_requisition_items.map { |item| UnitConversion.convert(item.unit, unit, item.quantity) } quantities.sum end |
#validate_status ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'app/models/cats/core/transport_requisition.rb', line 48 def validate_status return unless status return if status == DRAFT return if transport_requisition_items.count.positive? errors.add(:status, 'cannot be set to "APPROVED" because the requisition has no items.') if status == APPROVED end |