Class: Cats::Core::HubAuthorization

Inherits:
ApplicationRecord show all
Defined in:
app/models/cats/core/hub_authorization.rb

Constant Summary collapse

SOURCE =
"Source".freeze
DESTINATION =
"Destination".freeze
AUTHORIZATION_TYPES =
[SOURCE, DESTINATION].freeze

Instance Method Summary collapse

Instance Method Details

#set_unitObject



25
26
27
28
29
30
31
# File 'app/models/cats/core/hub_authorization.rb', line 25

def set_unit
  return if unit

  return unless dispatch_plan_item

  self.unit = dispatch_plan_item.unit
end

#validate_quantityObject



33
34
35
36
37
38
39
40
41
# File 'app/models/cats/core/hub_authorization.rb', line 33

def validate_quantity
  return unless quantity && unit && dispatch_plan_item

  authorizations = HubAuthorization.where(
    dispatch_plan_item: dispatch_plan_item,
    authorization_type: authorization_type
  )
  ValidationUtil.validate_quantity(self, "dispatch_plan_item", authorizations, "allocated")
end