Class: Cats::Core::RhnRequest
Constant Summary
collapse
- ALLOCATED =
"Allocated".freeze
Dispatchable::APPROVED, Dispatchable::COMPLETED, Dispatchable::DRAFT, Dispatchable::STATUSES
Instance Method Summary
collapse
Instance Method Details
#allocate ⇒ Object
77
78
79
80
81
82
|
# File 'app/models/cats/core/rhn_request.rb', line 77
def allocate
raise(StandardError, "Request is not completed.") unless status == COMPLETED
self.status = ALLOCATED
save!
end
|
#approve ⇒ Object
63
64
65
66
67
68
|
# File 'app/models/cats/core/rhn_request.rb', line 63
def approve
raise(StandardError, "Request is not in draft state.") unless status == DRAFT
self.status = APPROVED
save!
end
|
#complete ⇒ Object
70
71
72
73
74
75
|
# File 'app/models/cats/core/rhn_request.rb', line 70
def complete
raise(StandardError, "Request is not approved.") unless status == APPROVED
self.status = COMPLETED
save!
end
|
#request_quantity ⇒ Object
35
36
37
|
# File 'app/models/cats/core/rhn_request.rb', line 35
def request_quantity
quantity
end
|
#request_reference ⇒ Object
31
32
33
|
# File 'app/models/cats/core/rhn_request.rb', line 31
def request_reference
reference_no
end
|
#set_unit ⇒ Object
23
24
25
26
27
28
29
|
# File 'app/models/cats/core/rhn_request.rb', line 23
def set_unit
return if unit
return unless commodity
self.unit = commodity.unit
end
|
#validate_commodity_status ⇒ Object
39
40
41
42
43
|
# File 'app/models/cats/core/rhn_request.rb', line 39
def validate_commodity_status
return unless commodity
errors.add(:commodity, "should be approved first.") unless commodity.status == Commodity::APPROVED
end
|
#validate_quantity ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'app/models/cats/core/rhn_request.rb', line 45
def validate_quantity
return unless commodity && quantity && unit
requested = commodity.requested_quantity
remaining = commodity.quantity - requested
if quantity_was
additional = UnitConversion.convert(unit, commodity.unit_of_measure, quantity_was)
remaining += additional
end
new_quantity = UnitConversion.convert(unit, commodity.unit_of_measure, quantity)
return unless new_quantity > remaining
remaining = UnitConversion.convert(commodity.unit_of_measure, unit, remaining)
message = "exceeds commodity quantity. Maximum allowed is #{remaining} #{unit.abbreviation}"
errors.add(:quantity, message)
end
|