Class: Cats::Core::DispatchPlan
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Cats::Core::DispatchPlan
- Defined in:
- app/models/cats/core/dispatch_plan.rb
Constant Summary collapse
Class Method Summary collapse
- .ransackable_associations(_auth_object = nil) ⇒ Object
- .ransackable_attributes(_auth_object = nil) ⇒ Object
Instance Method Summary collapse
- #approve ⇒ Object
-
#quantity ⇒ Object
A method which returns the total quantity in the dispatch plan based on dispatch plan item quantities.
- #region ⇒ Object
- #validate_dispatchable ⇒ Object
Class Method Details
.ransackable_associations(_auth_object = nil) ⇒ Object
79 80 81 82 83 84 85 |
# File 'app/models/cats/core/dispatch_plan.rb', line 79 def self.ransackable_associations(_auth_object = nil) %w[ dispatchable reported_by approved_by ] end |
.ransackable_attributes(_auth_object = nil) ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'app/models/cats/core/dispatch_plan.rb', line 70 def self.ransackable_attributes(_auth_object = nil) %w[ approved_by_id prepared_by_id status upstream ] end |
Instance Method Details
#approve ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/models/cats/core/dispatch_plan.rb', line 39 def approve raise(StandardError, "Dispatch plan already approved.") if status == APPROVED raise(StandardError, "Dispatch plan is empty.") if dispatch_plan_items.count.zero? # Raise error if the total dispatch plan quantity is not equal to the # dispatchable quantity if dispatchable.instance_of?(RhnRequest) && dispatchable.quantity != quantity raise(StandardError, "Requested quantity and plan quantity do not match.") end self.status = APPROVED dispatchable&.allocate if dispatchable.instance_of?(RhnRequest) save! end |
#quantity ⇒ Object
A method which returns the total quantity in the dispatch plan based on dispatch plan item quantities.
57 58 59 60 61 |
# File 'app/models/cats/core/dispatch_plan.rb', line 57 def quantity raise(StandardError, "Dispatchable must be RHN request.") unless dispatchable.instance_of?(RhnRequest) UnitConversion.harmonized_total(dispatch_plan_items, dispatchable.unit) end |
#region ⇒ Object
63 64 65 66 67 68 |
# File 'app/models/cats/core/dispatch_plan.rb', line 63 def region return nil if dispatchable.instance_of?(RhnRequest) return dispatch_plan_items.first.source.parent.name if dispatchable.nil? dispatchable.region.name end |
#validate_dispatchable ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'app/models/cats/core/dispatch_plan.rb', line 30 def validate_dispatchable # Check if dispatchable is already completed and raise error if so. return unless dispatchable return if dispatchable.status == RhnRequest::APPROVED errors.add(:dispatchable, "is already completed.") if id.nil? && dispatchable.status == Dispatchable::COMPLETED end |