cats_core 1.5.17 → 1.5.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +7 -7
- data/app/controllers/cats/core/access_controller.rb +4 -4
- data/app/controllers/cats/core/application_controller.rb +4 -4
- data/app/controllers/cats/core/commodities_controller.rb +7 -7
- data/app/controllers/cats/core/commodity_categories_controller.rb +4 -4
- data/app/controllers/cats/core/dispatch_authorizations_controller.rb +22 -9
- data/app/controllers/cats/core/dispatch_plan_items_controller.rb +4 -4
- data/app/controllers/cats/core/dispatch_plans_controller.rb +10 -10
- data/app/controllers/cats/core/dispatch_transactions_controller.rb +5 -5
- data/app/controllers/cats/core/dispatches_controller.rb +19 -19
- data/app/controllers/cats/core/loans_controller.rb +1 -1
- data/app/controllers/cats/core/locations_controller.rb +4 -4
- data/app/controllers/cats/core/menus_controller.rb +1 -1
- data/app/controllers/cats/core/notifications_controller.rb +5 -5
- data/app/controllers/cats/core/purchase_orders_controller.rb +3 -3
- data/app/controllers/cats/core/receipt_authorizations_controller.rb +29 -17
- data/app/controllers/cats/core/receipt_transactions_controller.rb +4 -4
- data/app/controllers/cats/core/receipts_controller.rb +1 -1
- data/app/controllers/cats/core/roles_controller.rb +3 -3
- data/app/controllers/cats/core/round_beneficiaries_controller.rb +13 -13
- data/app/controllers/cats/core/round_plans_controller.rb +13 -13
- data/app/controllers/cats/core/routes_controller.rb +2 -2
- data/app/controllers/cats/core/spaces_controller.rb +1 -1
- data/app/controllers/cats/core/stack_transactions_controller.rb +3 -3
- data/app/controllers/cats/core/stacks_controller.rb +15 -7
- data/app/controllers/cats/core/stores_controller.rb +14 -14
- data/app/controllers/cats/core/swaps_controller.rb +2 -2
- data/app/controllers/cats/core/transporters_controller.rb +1 -1
- data/app/controllers/cats/core/users_controller.rb +24 -12
- data/app/controllers/concerns/cats/core/common.rb +24 -23
- data/app/helpers/cats/core/document_helper.rb +1 -1
- data/app/models/cats/core/authorization.rb +9 -9
- data/app/models/cats/core/beneficiary.rb +6 -6
- data/app/models/cats/core/beneficiary_plan_item.rb +9 -9
- data/app/models/cats/core/beneficiary_round_plan_item.rb +2 -2
- data/app/models/cats/core/cash_donation.rb +1 -1
- data/app/models/cats/core/commodity.rb +47 -33
- data/app/models/cats/core/commodity_donation.rb +2 -2
- data/app/models/cats/core/commodity_substitution.rb +15 -7
- data/app/models/cats/core/contract_item.rb +2 -2
- data/app/models/cats/core/dispatch.rb +36 -21
- data/app/models/cats/core/dispatch_authorization.rb +31 -5
- data/app/models/cats/core/dispatch_plan.rb +19 -10
- data/app/models/cats/core/dispatch_plan_item.rb +27 -14
- data/app/models/cats/core/dispatch_transaction.rb +15 -5
- data/app/models/cats/core/gift_certificate.rb +3 -3
- data/app/models/cats/core/hub_authorization.rb +7 -7
- data/app/models/cats/core/loan.rb +2 -2
- data/app/models/cats/core/location.rb +12 -8
- data/app/models/cats/core/lost_commodity.rb +2 -2
- data/app/models/cats/core/notification.rb +2 -2
- data/app/models/cats/core/offer_item.rb +4 -4
- data/app/models/cats/core/plan.rb +9 -9
- data/app/models/cats/core/plan_item.rb +5 -5
- data/app/models/cats/core/plan_item_detail.rb +2 -2
- data/app/models/cats/core/project.rb +1 -1
- data/app/models/cats/core/purchase_order.rb +5 -5
- data/app/models/cats/core/ration.rb +1 -1
- data/app/models/cats/core/receipt.rb +5 -5
- data/app/models/cats/core/receipt_authorization.rb +6 -2
- data/app/models/cats/core/receipt_transaction.rb +8 -4
- data/app/models/cats/core/rhn_request.rb +8 -8
- data/app/models/cats/core/role_menu.rb +1 -1
- data/app/models/cats/core/round_beneficiary.rb +10 -2
- data/app/models/cats/core/round_plan.rb +15 -11
- data/app/models/cats/core/round_plan_item.rb +9 -5
- data/app/models/cats/core/round_plan_item_detail.rb +3 -3
- data/app/models/cats/core/round_ration.rb +2 -2
- data/app/models/cats/core/route.rb +12 -8
- data/app/models/cats/core/stack.rb +52 -34
- data/app/models/cats/core/stack_transaction.rb +3 -3
- data/app/models/cats/core/stacking_rule.rb +2 -2
- data/app/models/cats/core/store.rb +29 -7
- data/app/models/cats/core/swap.rb +5 -5
- data/app/models/cats/core/transaction.rb +6 -6
- data/app/models/cats/core/transport_bid.rb +13 -13
- data/app/models/cats/core/transport_bid_item.rb +2 -2
- data/app/models/cats/core/transport_offer.rb +3 -3
- data/app/models/cats/core/transport_order.rb +8 -8
- data/app/models/cats/core/transport_order_item.rb +2 -2
- data/app/models/cats/core/transport_plan.rb +7 -7
- data/app/models/cats/core/transport_plan_item.rb +2 -2
- data/app/models/cats/core/transport_requisition.rb +9 -9
- data/app/models/cats/core/transport_requisition_detail.rb +2 -2
- data/app/models/cats/core/transport_requisition_item.rb +3 -3
- data/app/models/cats/core/transporter.rb +4 -0
- data/app/models/cats/core/unit_conversion.rb +4 -4
- data/app/models/cats/core/unit_of_measure.rb +4 -4
- data/app/models/cats/core/user.rb +11 -11
- data/app/models/concerns/cats/core/dispatchable.rb +3 -3
- data/app/notifications/cats/core/allocation_notification.rb +1 -1
- data/app/notifications/cats/core/dispatch_authorization_notification.rb +5 -1
- data/app/notifications/cats/core/dispatch_notification.rb +1 -1
- data/app/notifications/cats/core/receipt_authorization_notification.rb +1 -1
- data/app/notifications/cats/core/round_plan_notification.rb +1 -1
- data/app/notifications/cats/core/simple_notification.rb +1 -1
- data/app/serializers/cats/core/cash_donation_serializer.rb +1 -1
- data/app/serializers/cats/core/commodity_donation_serializer.rb +2 -2
- data/app/serializers/cats/core/commodity_serializer.rb +2 -2
- data/app/serializers/cats/core/dispatch_authorization_serializer.rb +2 -2
- data/app/serializers/cats/core/dispatch_plan_item_serializer.rb +3 -3
- data/app/serializers/cats/core/dispatch_plan_serializer.rb +1 -1
- data/app/serializers/cats/core/dispatch_serializer.rb +2 -2
- data/app/serializers/cats/core/dispatch_transaction_serializer.rb +1 -1
- data/app/serializers/cats/core/loan_serializer.rb +1 -1
- data/app/serializers/cats/core/purchase_order_serializer.rb +2 -2
- data/app/serializers/cats/core/receipt_authorization_serializer.rb +2 -2
- data/app/serializers/cats/core/receipt_serializer.rb +1 -1
- data/app/serializers/cats/core/receipt_transaction_serializer.rb +2 -2
- data/app/serializers/cats/core/round_beneficiary_serializer.rb +1 -1
- data/app/serializers/cats/core/round_plan_serializer.rb +1 -1
- data/app/serializers/cats/core/stack_serializer.rb +1 -1
- data/app/serializers/cats/core/store_serializer.rb +1 -1
- data/app/serializers/cats/core/swap_serializer.rb +2 -2
- data/app/services/cats/core/authorization_service.rb +22 -21
- data/app/services/cats/core/beneficiary_service.rb +11 -11
- data/app/services/cats/core/dispatch_plan_service.rb +10 -10
- data/app/services/cats/core/dispatch_service.rb +31 -31
- data/app/services/cats/core/notification_service.rb +5 -5
- data/app/services/cats/core/round_plan_service.rb +23 -23
- data/app/services/cats/core/space_service.rb +11 -11
- data/app/services/cats/core/stack_service.rb +10 -10
- data/app/services/cats/core/token_auth_service.rb +4 -4
- data/app/services/cats/core/user_service.rb +19 -0
- data/app/utils/cats/core/util.rb +1 -1
- data/config/routes.rb +110 -105
- data/config/spring.rb +1 -0
- data/db/migrate/20210715114910_create_cats_core_users.rb +3 -3
- data/db/migrate/20210715120018_create_cats_core_roles.rb +14 -14
- data/db/migrate/20210715121244_create_cats_core_menus.rb +3 -3
- data/db/migrate/20210715122141_create_cats_core_menu_items.rb +3 -3
- data/db/migrate/20210715122423_create_cats_core_role_menus.rb +13 -13
- data/db/migrate/20210717031810_create_cats_core_plans.rb +4 -4
- data/db/migrate/20210717032024_create_cats_core_plan_items.rb +18 -18
- data/db/migrate/20210717032260_create_cats_core_beneficiary_categories.rb +3 -3
- data/db/migrate/20210717032270_create_cats_core_rations.rb +10 -10
- data/db/migrate/20210717032290_create_cats_core_beneficiary_plan_items.rb +7 -7
- data/db/migrate/20210717032295_create_cats_core_plan_item_details.rb +7 -7
- data/db/migrate/20210717032330_create_cats_core_commodity_donations.rb +12 -12
- data/db/migrate/20210717032408_create_cats_core_cash_donations.rb +6 -6
- data/db/migrate/20210717032602_create_cats_core_gift_certificates.rb +12 -12
- data/db/migrate/20210717032855_create_cats_core_purchase_orders.rb +12 -12
- data/db/migrate/20210717032927_create_cats_core_projects.rb +3 -3
- data/db/migrate/20210717033223_create_cats_core_commodities.rb +10 -10
- data/db/migrate/20210717140855_create_cats_core_stores.rb +3 -3
- data/db/migrate/20210717171101_create_cats_core_stacks.rb +11 -11
- data/db/migrate/20210718040129_create_cats_core_routes.rb +9 -9
- data/db/migrate/20210718042755_create_cats_core_rhn_requests.rb +6 -6
- data/db/migrate/20210718043328_create_cats_core_dispatch_plans.rb +7 -7
- data/db/migrate/20210718043401_create_cats_core_dispatch_plan_items.rb +17 -17
- data/db/migrate/20210718045516_create_cats_core_dispatches.rb +13 -13
- data/db/migrate/20210718055414_create_cats_core_dispatch_authorizations.rb +13 -13
- data/db/migrate/20210718202957_create_cats_core_dispatch_transactions.rb +11 -11
- data/db/migrate/20210727074646_create_cats_core_receipt_authorizations.rb +13 -13
- data/db/migrate/20210727105834_create_cats_core_receipts.rb +6 -6
- data/db/migrate/20210728041505_create_cats_core_lost_commodities.rb +6 -6
- data/db/migrate/20210814160628_create_cats_core_receipt_transactions.rb +10 -10
- data/db/migrate/20210814175406_create_cats_core_stack_transactions.rb +10 -10
- data/db/migrate/20211024063240_add_status_to_cats_core_rhn_requests.rb +1 -1
- data/db/migrate/20211030133752_add_status_to_cats_core_commodities.rb +1 -1
- data/db/migrate/20211215114737_create_cats_core_transport_plans.rb +4 -4
- data/db/migrate/20211215114835_create_cats_core_transport_plan_items.rb +9 -9
- data/db/migrate/20211215121151_create_cats_core_transport_bids.rb +4 -4
- data/db/migrate/20211215124452_create_cats_core_transport_bid_items.rb +10 -10
- data/db/migrate/20211229160125_create_cats_core_transport_offers.rb +7 -7
- data/db/migrate/20211229160126_create_cats_core_offer_items.rb +6 -6
- data/db/migrate/20211229160127_create_cats_core_transport_contracts.rb +6 -6
- data/db/migrate/20211229160128_create_cats_core_contract_items.rb +9 -9
- data/db/migrate/20211229160129_create_cats_core_commodity_substitutions.rb +10 -10
- data/db/migrate/20220103152802_create_cats_core_tenderers.rb +6 -6
- data/db/migrate/20220107121752_create_cats_core_round_plans.rb +7 -7
- data/db/migrate/20220107122280_create_cats_core_round_rations.rb +12 -12
- data/db/migrate/20220107125025_create_cats_core_round_plan_items.rb +19 -19
- data/db/migrate/20220107126025_create_cats_core_beneficiary_round_plan_items.rb +8 -8
- data/db/migrate/20220107132433_create_cats_core_round_plan_item_details.rb +9 -9
- data/db/migrate/20220209083928_create_cats_core_hub_authorizations.rb +12 -12
- data/db/migrate/20220416143416_create_cats_core_unit_conversions.rb +6 -6
- data/db/migrate/20220417105839_create_cats_core_transport_requisitions.rb +12 -12
- data/db/migrate/20220417123835_create_cats_core_transport_requisition_items.rb +9 -9
- data/db/migrate/20220417151821_create_cats_core_transport_requisition_details.rb +6 -6
- data/db/migrate/20220506082329_create_cats_core_transport_orders.rb +10 -10
- data/db/migrate/20220506083042_create_cats_core_transport_order_items.rb +13 -13
- data/db/migrate/20220511082354_create_cats_core_beneficiaries.rb +6 -6
- data/db/migrate/20220626063501_create_cats_core_loans.rb +6 -6
- data/db/migrate/20220626063757_create_cats_core_swaps.rb +12 -12
- data/db/migrate/20220626132050_create_cats_core_round_beneficiaries.rb +13 -13
- data/db/migrate/20220923190857_create_cats_core_application_settings.rb +3 -3
- data/lib/cats/core/engine.rb +4 -4
- data/lib/cats/core/version.rb +1 -1
- data/lib/cats_core.rb +8 -8
- data/spec/factories/cats/core/application_modules.rb +1 -1
- data/spec/factories/cats/core/application_settings.rb +1 -1
- data/spec/factories/cats/core/beneficiaries.rb +3 -3
- data/spec/factories/cats/core/beneficiary_categories.rb +1 -1
- data/spec/factories/cats/core/beneficiary_plan_items.rb +1 -1
- data/spec/factories/cats/core/beneficiary_round_plan_items.rb +1 -1
- data/spec/factories/cats/core/cash_donations.rb +1 -1
- data/spec/factories/cats/core/commodities.rb +1 -1
- data/spec/factories/cats/core/commodity_categories.rb +1 -1
- data/spec/factories/cats/core/commodity_donations.rb +1 -1
- data/spec/factories/cats/core/commodity_substitutions.rb +2 -2
- data/spec/factories/cats/core/contract_items.rb +1 -1
- data/spec/factories/cats/core/currencies.rb +1 -1
- data/spec/factories/cats/core/dispatch_authorizations.rb +7 -11
- data/spec/factories/cats/core/dispatch_plan_items.rb +16 -1
- data/spec/factories/cats/core/dispatch_plans.rb +1 -1
- data/spec/factories/cats/core/dispatch_transactions.rb +2 -4
- data/spec/factories/cats/core/dispatches.rb +16 -25
- data/spec/factories/cats/core/donors.rb +1 -1
- data/spec/factories/cats/core/gift_certificates.rb +1 -1
- data/spec/factories/cats/core/hub_authorizations.rb +1 -1
- data/spec/factories/cats/core/loans.rb +1 -1
- data/spec/factories/cats/core/locations.rb +6 -6
- data/spec/factories/cats/core/lost_commodities.rb +1 -1
- data/spec/factories/cats/core/menu_items.rb +1 -1
- data/spec/factories/cats/core/menus.rb +1 -1
- data/spec/factories/cats/core/notification_rules.rb +1 -1
- data/spec/factories/cats/core/notifications.rb +2 -2
- data/spec/factories/cats/core/offer_items.rb +1 -1
- data/spec/factories/cats/core/operators.rb +1 -1
- data/spec/factories/cats/core/plan_item_details.rb +1 -1
- data/spec/factories/cats/core/plan_items.rb +1 -1
- data/spec/factories/cats/core/plans.rb +1 -1
- data/spec/factories/cats/core/programs.rb +1 -1
- data/spec/factories/cats/core/projects.rb +1 -1
- data/spec/factories/cats/core/purchase_orders.rb +1 -1
- data/spec/factories/cats/core/rations.rb +1 -1
- data/spec/factories/cats/core/receipt_authorizations.rb +1 -1
- data/spec/factories/cats/core/receipt_transactions.rb +2 -2
- data/spec/factories/cats/core/receipts.rb +1 -1
- data/spec/factories/cats/core/rhn_requests.rb +1 -1
- data/spec/factories/cats/core/role_menus.rb +1 -1
- data/spec/factories/cats/core/roles.rb +1 -1
- data/spec/factories/cats/core/round_beneficiaries.rb +1 -1
- data/spec/factories/cats/core/round_plan_item_details.rb +3 -3
- data/spec/factories/cats/core/round_plan_items.rb +1 -1
- data/spec/factories/cats/core/round_plans.rb +1 -1
- data/spec/factories/cats/core/round_rations.rb +1 -1
- data/spec/factories/cats/core/routes.rb +1 -1
- data/spec/factories/cats/core/stack_transactions.rb +1 -1
- data/spec/factories/cats/core/stacking_rules.rb +1 -1
- data/spec/factories/cats/core/stacks.rb +1 -1
- data/spec/factories/cats/core/stores.rb +1 -1
- data/spec/factories/cats/core/suppliers.rb +1 -1
- data/spec/factories/cats/core/swaps.rb +1 -1
- data/spec/factories/cats/core/tenderers.rb +1 -1
- data/spec/factories/cats/core/transport_bid_items.rb +1 -1
- data/spec/factories/cats/core/transport_bids.rb +1 -1
- data/spec/factories/cats/core/transport_contracts.rb +1 -1
- data/spec/factories/cats/core/transport_offers.rb +1 -1
- data/spec/factories/cats/core/transport_order_items.rb +1 -1
- data/spec/factories/cats/core/transport_orders.rb +1 -1
- data/spec/factories/cats/core/transport_plan_items.rb +1 -1
- data/spec/factories/cats/core/transport_plans.rb +1 -1
- data/spec/factories/cats/core/transport_requisition_details.rb +1 -1
- data/spec/factories/cats/core/transport_requisition_items.rb +1 -1
- data/spec/factories/cats/core/transport_requisitions.rb +1 -1
- data/spec/factories/cats/core/transporters.rb +1 -1
- data/spec/factories/cats/core/unit_conversions.rb +1 -1
- data/spec/factories/cats/core/unit_of_measures.rb +1 -1
- data/spec/factories/cats/core/users.rb +2 -2
- metadata +18 -2
@@ -2,37 +2,37 @@ module Cats
|
|
2
2
|
module Core
|
3
3
|
class Commodity < ApplicationRecord
|
4
4
|
# Statuses
|
5
|
-
DRAFT =
|
6
|
-
APPROVED =
|
7
|
-
ALLOCATED =
|
5
|
+
DRAFT = "Draft".freeze
|
6
|
+
APPROVED = "Approved".freeze
|
7
|
+
ALLOCATED = "Allocated".freeze
|
8
8
|
STATUSES = [DRAFT, APPROVED, ALLOCATED].freeze
|
9
9
|
|
10
10
|
# Grades
|
11
|
-
GRADE1 =
|
12
|
-
GRADE2 =
|
13
|
-
GRADE3 =
|
11
|
+
GRADE1 = "Grade1".freeze
|
12
|
+
GRADE2 = "Grade2".freeze
|
13
|
+
GRADE3 = "Grade3".freeze
|
14
14
|
COMMODITY_GRADES = [GRADE1, GRADE2, GRADE3].freeze
|
15
15
|
|
16
16
|
# Commodity statuses
|
17
|
-
GOOD =
|
18
|
-
DAMAGED =
|
19
|
-
LEAKAGE =
|
20
|
-
WET =
|
21
|
-
MOLDY =
|
22
|
-
INFESTED =
|
23
|
-
INSECT_INFECTED =
|
24
|
-
FAECES_FROM_RODENTS =
|
25
|
-
UNDERWEIGHT_PACKAGE =
|
17
|
+
GOOD = "Good".freeze
|
18
|
+
DAMAGED = "Damaged".freeze
|
19
|
+
LEAKAGE = "Leakage".freeze
|
20
|
+
WET = "Wet".freeze
|
21
|
+
MOLDY = "Moldy".freeze
|
22
|
+
INFESTED = "Infested".freeze
|
23
|
+
INSECT_INFECTED = "Insect Infected".freeze
|
24
|
+
FAECES_FROM_RODENTS = "Faeces From Rodents".freeze
|
25
|
+
UNDERWEIGHT_PACKAGE = "Underweight Package".freeze
|
26
26
|
COMMODITY_STATUSES = [GOOD, DAMAGED, LEAKAGE, WET, MOLDY, INFESTED, INSECT_INFECTED, FAECES_FROM_RODENTS,
|
27
|
-
|
27
|
+
UNDERWEIGHT_PACKAGE].freeze
|
28
28
|
|
29
29
|
# Arrival Statuses
|
30
|
-
AT_SOURCE =
|
31
|
-
AT_ORIGIN_PORT =
|
32
|
-
IN_LOCAL_TRANSIT =
|
33
|
-
IN_INTERNATIONAL_TRANSIT =
|
34
|
-
AT_DESTINATION_PORT =
|
35
|
-
ARRIVED =
|
30
|
+
AT_SOURCE = "At Source".freeze
|
31
|
+
AT_ORIGIN_PORT = "At Origin Port".freeze
|
32
|
+
IN_LOCAL_TRANSIT = "In Local Transit".freeze
|
33
|
+
IN_INTERNATIONAL_TRANSIT = "In International Transit".freeze
|
34
|
+
AT_DESTINATION_PORT = "At Destination Port".freeze
|
35
|
+
ARRIVED = "Arrived".freeze
|
36
36
|
ARRIVAL_STATUSES = [
|
37
37
|
AT_SOURCE,
|
38
38
|
AT_ORIGIN_PORT,
|
@@ -44,18 +44,18 @@ module Cats
|
|
44
44
|
|
45
45
|
belongs_to :unit_of_measure
|
46
46
|
belongs_to :project
|
47
|
-
belongs_to :package_unit, class_name:
|
47
|
+
belongs_to :package_unit, class_name: "Cats::Core::UnitOfMeasure", optional: true
|
48
48
|
|
49
49
|
validates :best_use_before, presence: true
|
50
50
|
validates :batch_no, presence: true, uniqueness: true
|
51
|
-
validates :quantity, presence: true, numericality: {
|
52
|
-
validates :volume_per_metric_ton, numericality: {
|
53
|
-
validates :arrival_status, presence: true, inclusion: {
|
54
|
-
validates :status, presence: true, inclusion: {
|
55
|
-
validates :commodity_grade, inclusion: {
|
51
|
+
validates :quantity, presence: true, numericality: {greater_than: 0}
|
52
|
+
validates :volume_per_metric_ton, numericality: {greater_than: 0, allow_nil: true}
|
53
|
+
validates :arrival_status, presence: true, inclusion: {in: ARRIVAL_STATUSES}
|
54
|
+
validates :status, presence: true, inclusion: {in: STATUSES}
|
55
|
+
validates :commodity_grade, inclusion: {in: COMMODITY_GRADES}, allow_nil: true
|
56
56
|
validate :validate_updateability, on: :update
|
57
57
|
|
58
|
-
delegate(:abbreviation, to: :unit_of_measure, prefix:
|
58
|
+
delegate(:abbreviation, to: :unit_of_measure, prefix: "unit")
|
59
59
|
delegate(:code, to: :project, prefix: true)
|
60
60
|
delegate(:abbreviation, to: :package_unit, prefix: true, allow_nil: true)
|
61
61
|
|
@@ -72,18 +72,18 @@ module Cats
|
|
72
72
|
|
73
73
|
return if status_changed?
|
74
74
|
|
75
|
-
errors.add(:base,
|
75
|
+
errors.add(:base, "Commodity cannot be updated because it is in approved state.") if status == APPROVED
|
76
76
|
end
|
77
77
|
|
78
78
|
def approve
|
79
|
-
raise(StandardError,
|
79
|
+
raise(StandardError, "Commodity already approved.") if status == APPROVED
|
80
80
|
|
81
81
|
result = false
|
82
82
|
Cats::Core::Commodity.transaction do
|
83
83
|
self.status = APPROVED
|
84
84
|
save!
|
85
|
-
store = Cats::Core::Store.find_by(code:
|
86
|
-
raise(StandardError,
|
85
|
+
store = Cats::Core::Store.find_by(code: "SUP-STORE")
|
86
|
+
raise(StandardError, "Supplier store does not exist.") unless store
|
87
87
|
|
88
88
|
stack = Cats::Core::Stack.create!(
|
89
89
|
code: batch_no,
|
@@ -108,6 +108,20 @@ module Cats
|
|
108
108
|
requests = RhnRequest.where(commodity: self)
|
109
109
|
UnitConversion.harmonized_total(requests, unit_of_measure)
|
110
110
|
end
|
111
|
+
|
112
|
+
def self.ransackable_attributes(auth_object = nil)
|
113
|
+
[
|
114
|
+
"arrival_status",
|
115
|
+
"batch_no",
|
116
|
+
"best_use_before",
|
117
|
+
"commodity_grade",
|
118
|
+
"package_unit_id",
|
119
|
+
"project_id",
|
120
|
+
"quantity",
|
121
|
+
"shipping_reference",
|
122
|
+
"status"
|
123
|
+
]
|
124
|
+
end
|
111
125
|
end
|
112
126
|
end
|
113
127
|
end
|
@@ -3,9 +3,9 @@ module Cats
|
|
3
3
|
class CommodityDonation < Donation
|
4
4
|
belongs_to :plan, optional: true
|
5
5
|
belongs_to :commodity_category
|
6
|
-
belongs_to :unit, class_name:
|
6
|
+
belongs_to :unit, class_name: "UnitOfMeasure"
|
7
7
|
|
8
|
-
validates :quantity, presence: true, numericality: {
|
8
|
+
validates :quantity, presence: true, numericality: {greater_than: 0}
|
9
9
|
|
10
10
|
delegate(:reference_no, to: :plan, prefix: true, allow_nil: true)
|
11
11
|
delegate(:name, to: :commodity_category, prefix: true)
|
@@ -2,21 +2,29 @@ module Cats
|
|
2
2
|
module Core
|
3
3
|
class CommoditySubstitution < ApplicationRecord
|
4
4
|
belongs_to :program
|
5
|
-
belongs_to :commodity, class_name:
|
6
|
-
belongs_to :replaced_by, class_name:
|
5
|
+
belongs_to :commodity, class_name: "Cats::Core::CommodityCategory"
|
6
|
+
belongs_to :replaced_by, class_name: "Cats::Core::CommodityCategory"
|
7
7
|
|
8
8
|
validates :ratio, presence: true
|
9
|
-
validates :program_id, uniqueness: {
|
9
|
+
validates :program_id, uniqueness: {scope: %i[commodity_id replaced_by_id]}
|
10
10
|
validate :validate_ratio
|
11
11
|
|
12
12
|
def validate_ratio
|
13
13
|
return unless ratio
|
14
14
|
|
15
|
-
left, right = ratio.split(
|
16
|
-
left_correct =
|
17
|
-
|
15
|
+
left, right = ratio.split(":")
|
16
|
+
left_correct = begin
|
17
|
+
Integer(left).is_a?(Integer)
|
18
|
+
rescue
|
19
|
+
false
|
20
|
+
end
|
21
|
+
right_correct = begin
|
22
|
+
Integer(right).is_a?(Integer)
|
23
|
+
rescue
|
24
|
+
false
|
25
|
+
end
|
18
26
|
|
19
|
-
errors.add(:ratio,
|
27
|
+
errors.add(:ratio, "is not in correct format.") unless left_correct && right_correct
|
20
28
|
end
|
21
29
|
end
|
22
30
|
end
|
@@ -3,9 +3,9 @@ module Cats
|
|
3
3
|
class ContractItem < ApplicationRecord
|
4
4
|
belongs_to :transport_contract
|
5
5
|
belongs_to :route
|
6
|
-
belongs_to :unit, class_name:
|
6
|
+
belongs_to :unit, class_name: "Cats::Core::UnitOfMeasure"
|
7
7
|
|
8
|
-
validates :price, presence: true, numericality: {
|
8
|
+
validates :price, presence: true, numericality: {greater_than: 0}
|
9
9
|
|
10
10
|
delegate(:name, to: :route, prefix: true)
|
11
11
|
delegate(:contract_no, to: :transport_contract, prefix: false)
|
@@ -1,19 +1,19 @@
|
|
1
1
|
module Cats
|
2
2
|
module Core
|
3
3
|
class Dispatch < ApplicationRecord
|
4
|
-
DRAFT =
|
5
|
-
APPROVED =
|
6
|
-
READY_TO_START =
|
7
|
-
STARTED =
|
8
|
-
RECEIVED =
|
9
|
-
STACKED =
|
4
|
+
DRAFT = "Draft".freeze
|
5
|
+
APPROVED = "Approved".freeze
|
6
|
+
READY_TO_START = "Ready to Start".freeze
|
7
|
+
STARTED = "Started".freeze
|
8
|
+
RECEIVED = "Received".freeze
|
9
|
+
STACKED = "Stacked".freeze
|
10
10
|
|
11
11
|
DISPATCH_STATUSES = [DRAFT, APPROVED, READY_TO_START, STARTED, RECEIVED, STACKED].freeze
|
12
12
|
|
13
|
-
belongs_to :prepared_by, class_name:
|
13
|
+
belongs_to :prepared_by, class_name: "Cats::Core::User"
|
14
14
|
belongs_to :transporter
|
15
15
|
belongs_to :dispatch_plan_item
|
16
|
-
belongs_to :unit, class_name:
|
16
|
+
belongs_to :unit, class_name: "Cats::Core::UnitOfMeasure"
|
17
17
|
|
18
18
|
has_many :dispatch_authorizations
|
19
19
|
has_many :receipt_authorizations
|
@@ -21,10 +21,10 @@ module Cats
|
|
21
21
|
has_many :receipt_transactions, through: :receipt_authorizations
|
22
22
|
|
23
23
|
validates :reference_no, :plate_no, :driver_name, :driver_phone, :quantity, :commodity_status, presence: true
|
24
|
-
validates :dispatch_status, presence: true, inclusion: {
|
24
|
+
validates :dispatch_status, presence: true, inclusion: {in: DISPATCH_STATUSES}
|
25
25
|
validates :reference_no, uniqueness: true
|
26
|
-
validates :quantity, numericality: {
|
27
|
-
validates :commodity_status, inclusion: {
|
26
|
+
validates :quantity, numericality: {greater_than_or_equal_to: 0}
|
27
|
+
validates :commodity_status, inclusion: {in: Cats::Core::Commodity::COMMODITY_STATUSES}
|
28
28
|
validate :validate_dispatch_plan_status
|
29
29
|
|
30
30
|
delegate(:name, to: :transporter, prefix: true)
|
@@ -39,14 +39,14 @@ module Cats
|
|
39
39
|
return unless dispatch_plan_item
|
40
40
|
|
41
41
|
status = dispatch_plan_item.dispatch_plan.status
|
42
|
-
errors.add(:dispatch_plan,
|
42
|
+
errors.add(:dispatch_plan, "should be approved first.") unless status == DispatchPlan::APPROVED
|
43
43
|
end
|
44
44
|
|
45
45
|
def approve
|
46
|
-
raise(StandardError,
|
46
|
+
raise(StandardError, "Dispatch has to be in draft state.") unless dispatch_status == Dispatch::DRAFT
|
47
47
|
|
48
48
|
# Check if dispatch has authorizations
|
49
|
-
raise(StandardError,
|
49
|
+
raise(StandardError, "Dispatch has no authorizations.") unless dispatch_authorizations.count.positive?
|
50
50
|
|
51
51
|
dispatch_total = UnitConversion.harmonized_total(dispatch_authorizations, unit)
|
52
52
|
self.dispatch_status = APPROVED
|
@@ -67,7 +67,7 @@ module Cats
|
|
67
67
|
|
68
68
|
# Check if destination is an FDP and create receipt authorization
|
69
69
|
location = dispatch_plan_item.destination
|
70
|
-
authorized_by = User.find_by(first_name:
|
70
|
+
authorized_by = User.find_by(first_name: "SYSTEM-USER")
|
71
71
|
return unless location.location_type == Location::FDP
|
72
72
|
|
73
73
|
store = location.fdp_store
|
@@ -83,7 +83,7 @@ module Cats
|
|
83
83
|
end
|
84
84
|
|
85
85
|
def receive
|
86
|
-
raise(StandardError,
|
86
|
+
raise(StandardError, "Dispatch is not started.") unless dispatch_status == Dispatch::STARTED
|
87
87
|
|
88
88
|
self.dispatch_status = RECEIVED
|
89
89
|
save!
|
@@ -102,10 +102,10 @@ module Cats
|
|
102
102
|
def self.search_commodity(batch_no)
|
103
103
|
commodity = Commodity.find_by(batch_no: batch_no)
|
104
104
|
dispatches = Dispatch.includes(:dispatch_transactions)
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
105
|
+
.joins(:transporter)
|
106
|
+
.where(
|
107
|
+
dispatch_status: [APPROVED, STARTED]
|
108
|
+
)
|
109
109
|
dispatches.map do |dispatch|
|
110
110
|
{
|
111
111
|
batch_no: batch_no,
|
@@ -114,10 +114,25 @@ module Cats
|
|
114
114
|
unit: commodity.unit_abbreviation,
|
115
115
|
location: dispatch.transporter.name,
|
116
116
|
location_detail: "Plate No.: #{dispatch.plate_no}, Driver: #{dispatch.driver_name}",
|
117
|
-
stack:
|
117
|
+
stack: ""
|
118
118
|
}
|
119
119
|
end
|
120
120
|
end
|
121
|
+
|
122
|
+
def self.ransackable_attributes(auth_object = nil)
|
123
|
+
[
|
124
|
+
"commodity_status",
|
125
|
+
"dispatch_plan_item_id",
|
126
|
+
"dispatch_status",
|
127
|
+
"driver_name",
|
128
|
+
"driver_phone",
|
129
|
+
"plate_no",
|
130
|
+
"prepared_by_id",
|
131
|
+
"quantity",
|
132
|
+
"transporter_id",
|
133
|
+
"unit_id"
|
134
|
+
]
|
135
|
+
end
|
121
136
|
end
|
122
137
|
end
|
123
138
|
end
|
@@ -3,23 +3,49 @@ module Cats
|
|
3
3
|
class DispatchAuthorization < Authorization
|
4
4
|
has_many :dispatch_transactions
|
5
5
|
|
6
|
-
validate :
|
6
|
+
validate :validate_dispatch_plan_item_quantity, :validate_commodity_availability_in_store
|
7
7
|
|
8
8
|
def validate_dispatch_status
|
9
9
|
return unless dispatch
|
10
10
|
|
11
|
-
errors.add(:dispatch,
|
11
|
+
errors.add(:dispatch, "is not in draft state.") unless dispatch.dispatch_status == Dispatch::DRAFT
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
14
|
+
def validate_dispatch_plan_item_quantity
|
15
|
+
return if status == CONFIRMED
|
16
|
+
|
15
17
|
return unless dispatch && quantity && unit
|
16
18
|
|
17
19
|
authorizations = DispatchAuthorization.joins(:dispatch).where(
|
18
|
-
dispatch: {
|
20
|
+
dispatch: {dispatch_plan_item_id: dispatch.dispatch_plan_item_id}
|
19
21
|
)
|
20
22
|
quantity_attribs = %w[dispatch_plan_item quantity]
|
21
23
|
unit_attribs = %w[dispatch_plan_item unit]
|
22
|
-
ValidationUtil.validate_quantity(self,
|
24
|
+
ValidationUtil.validate_quantity(self, "dispatch", authorizations, "allocated", quantity_attribs, unit_attribs)
|
25
|
+
end
|
26
|
+
|
27
|
+
def validate_commodity_availability_in_store
|
28
|
+
return if status == CONFIRMED
|
29
|
+
|
30
|
+
return unless dispatch && store && quantity && unit
|
31
|
+
|
32
|
+
commodity = dispatch.dispatch_plan_item.commodity
|
33
|
+
stacks = Stack.where(store: store, commodity: commodity)
|
34
|
+
if stacks.count == 0
|
35
|
+
errors.add(:store, "does not contain commodity #{commodity.batch_no}.")
|
36
|
+
return
|
37
|
+
end
|
38
|
+
stack_quantity = stacks.map { |s| UnitConversion.convert(s.unit, unit, s.quantity) }.sum
|
39
|
+
authorizations = DispatchAuthorization.where(dispatch: dispatch)
|
40
|
+
authorized = authorizations.map { |a| UnitConversion.convert(a.unit, unit, a.quantity) }.sum
|
41
|
+
authorized -= quantity_was if persisted?
|
42
|
+
|
43
|
+
diff = quantity + authorized - stack_quantity
|
44
|
+
errors.add(:quantity, "exceeds available quantity in store by #{diff} #{unit.abbreviation}.") if diff.positive?
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.ransackable_attributes(auth_object = nil)
|
48
|
+
["authorized_by_id", "dispatch_id", "quantity", "status", "store_id", "unit_id"]
|
23
49
|
end
|
24
50
|
end
|
25
51
|
end
|
@@ -1,18 +1,18 @@
|
|
1
1
|
module Cats
|
2
2
|
module Core
|
3
3
|
class DispatchPlan < ApplicationRecord
|
4
|
-
DRAFT =
|
5
|
-
APPROVED =
|
4
|
+
DRAFT = "Draft".freeze
|
5
|
+
APPROVED = "Approved".freeze
|
6
6
|
STATUSES = [DRAFT, APPROVED].freeze
|
7
7
|
|
8
8
|
belongs_to :dispatchable, polymorphic: true, optional: true
|
9
|
-
belongs_to :prepared_by, class_name:
|
10
|
-
belongs_to :approved_by, class_name:
|
9
|
+
belongs_to :prepared_by, class_name: "Cats::Core::User"
|
10
|
+
belongs_to :approved_by, class_name: "Cats::Core::User", optional: true
|
11
11
|
|
12
12
|
has_many :dispatch_plan_items
|
13
13
|
|
14
14
|
validates :reference_no, presence: true, uniqueness: true
|
15
|
-
validates :status, inclusion: {
|
15
|
+
validates :status, inclusion: {in: STATUSES}
|
16
16
|
validate :validate_dispatchable, on: :create
|
17
17
|
|
18
18
|
delegate(:request_reference, to: :dispatchable, allow_nil: true)
|
@@ -33,18 +33,18 @@ module Cats
|
|
33
33
|
|
34
34
|
return if dispatchable.status == RhnRequest::APPROVED
|
35
35
|
|
36
|
-
errors.add(:dispatchable,
|
36
|
+
errors.add(:dispatchable, "is already completed.") if id.nil? && dispatchable.status == Dispatchable::COMPLETED
|
37
37
|
end
|
38
38
|
|
39
39
|
def approve
|
40
|
-
raise(StandardError,
|
40
|
+
raise(StandardError, "Dispatch plan already approved.") if status == APPROVED
|
41
41
|
|
42
|
-
raise(StandardError,
|
42
|
+
raise(StandardError, "Dispatch plan is empty.") if dispatch_plan_items.count.zero?
|
43
43
|
|
44
44
|
# Raise error if the total dispatch plan quantity is not equal to the
|
45
45
|
# dispatchable quantity
|
46
46
|
if dispatchable.instance_of?(RhnRequest) && dispatchable.quantity != quantity
|
47
|
-
raise(StandardError,
|
47
|
+
raise(StandardError, "Requested quantity and plan quantity do not match.")
|
48
48
|
end
|
49
49
|
|
50
50
|
self.status = APPROVED
|
@@ -55,7 +55,7 @@ module Cats
|
|
55
55
|
# A method which returns the total quantity in the dispatch plan
|
56
56
|
# based on dispatch plan item quantities.
|
57
57
|
def quantity
|
58
|
-
raise(StandardError,
|
58
|
+
raise(StandardError, "Dispatchable must be RHN request.") unless dispatchable.instance_of?(RhnRequest)
|
59
59
|
|
60
60
|
UnitConversion.harmonized_total(dispatch_plan_items, dispatchable.unit)
|
61
61
|
end
|
@@ -66,6 +66,15 @@ module Cats
|
|
66
66
|
|
67
67
|
dispatchable.region.name
|
68
68
|
end
|
69
|
+
|
70
|
+
def self.ransackable_attributes(auth_object = nil)
|
71
|
+
[
|
72
|
+
"approved_by_id",
|
73
|
+
"prepared_by_id",
|
74
|
+
"status",
|
75
|
+
"upstream"
|
76
|
+
]
|
77
|
+
end
|
69
78
|
end
|
70
79
|
end
|
71
80
|
end
|
@@ -1,25 +1,25 @@
|
|
1
1
|
module Cats
|
2
2
|
module Core
|
3
3
|
class DispatchPlanItem < ApplicationRecord
|
4
|
-
AUTHORIZED =
|
5
|
-
SOURCE_AUTHORIZED =
|
6
|
-
DESTINATION_AUTHORIZED =
|
7
|
-
UNAUTHORIZED =
|
4
|
+
AUTHORIZED = "Authorized".freeze
|
5
|
+
SOURCE_AUTHORIZED = "Source Authorized".freeze
|
6
|
+
DESTINATION_AUTHORIZED = "Destination Authorized".freeze
|
7
|
+
UNAUTHORIZED = "Unauthorized".freeze
|
8
8
|
STATUSES = [AUTHORIZED, DESTINATION_AUTHORIZED, SOURCE_AUTHORIZED, UNAUTHORIZED].freeze
|
9
9
|
|
10
|
-
belongs_to :source, class_name:
|
11
|
-
belongs_to :destination, class_name:
|
10
|
+
belongs_to :source, class_name: "Cats::Core::Location"
|
11
|
+
belongs_to :destination, class_name: "Cats::Core::Location"
|
12
12
|
belongs_to :dispatch_plan
|
13
13
|
belongs_to :commodity
|
14
|
-
belongs_to :unit, class_name:
|
14
|
+
belongs_to :unit, class_name: "Cats::Core::UnitOfMeasure"
|
15
15
|
|
16
16
|
has_many :dispatches
|
17
17
|
has_many :hub_authorizations
|
18
18
|
|
19
19
|
validates :reference_no, presence: true, uniqueness: true
|
20
|
-
validates :commodity_status, presence: true, inclusion: {
|
21
|
-
validates :quantity, presence: true, numericality: {
|
22
|
-
validates :status, presence: true, inclusion: {
|
20
|
+
validates :commodity_status, presence: true, inclusion: {in: Commodity::COMMODITY_STATUSES}
|
21
|
+
validates :quantity, presence: true, numericality: {greater_than: 0}
|
22
|
+
validates :status, presence: true, inclusion: {in: STATUSES}
|
23
23
|
|
24
24
|
delegate(:reference_no, to: :dispatch_plan, prefix: :plan, allow_nil: true)
|
25
25
|
delegate(:batch_no, :name, to: :commodity, prefix: true)
|
@@ -39,7 +39,7 @@ module Cats
|
|
39
39
|
#
|
40
40
|
def authorize
|
41
41
|
count = hub_authorizations.count
|
42
|
-
raise(StandardError,
|
42
|
+
raise(StandardError, "No authorization entries found.") if count.zero?
|
43
43
|
|
44
44
|
source_auth = hub_authorizations.where(authorization_type: HubAuthorization::SOURCE)
|
45
45
|
dest_auth = hub_authorizations.where(authorization_type: HubAuthorization::DESTINATION)
|
@@ -47,14 +47,14 @@ module Cats
|
|
47
47
|
if source_auth.count.positive? && dest_auth.count.zero? && status == SOURCE_AUTHORIZED
|
48
48
|
raise(
|
49
49
|
StandardError,
|
50
|
-
|
50
|
+
"Plan item already authorized by source. Destination hub authorizations are required."
|
51
51
|
)
|
52
52
|
end
|
53
53
|
|
54
54
|
if source_auth.count.zero? && dest_auth.count.positive? && status == DESTINATION_AUTHORIZED
|
55
55
|
raise(
|
56
56
|
StandardError,
|
57
|
-
|
57
|
+
"Plan item already authorized by destination. Source hub authorizations are required."
|
58
58
|
)
|
59
59
|
end
|
60
60
|
|
@@ -80,13 +80,26 @@ module Cats
|
|
80
80
|
return if quantity == self.quantity
|
81
81
|
|
82
82
|
diff = self.quantity - quantity
|
83
|
-
desc = type.split(
|
83
|
+
desc = type.split(" ")[0].downcase
|
84
84
|
amount = "#{diff} #{unit.abbreviation}"
|
85
85
|
raise(
|
86
86
|
StandardError,
|
87
87
|
"Authorized #{desc} quantity is not the same as plan item quantity (#{amount} unaccounted for)."
|
88
88
|
)
|
89
89
|
end
|
90
|
+
|
91
|
+
def self.ransackable_attributes(auth_object = nil)
|
92
|
+
[
|
93
|
+
"commodity_id",
|
94
|
+
"commodity_status",
|
95
|
+
"destination_id",
|
96
|
+
"dispatch_plan_id",
|
97
|
+
"quantity",
|
98
|
+
"source_id",
|
99
|
+
"status",
|
100
|
+
"unit_id"
|
101
|
+
]
|
102
|
+
end
|
90
103
|
end
|
91
104
|
end
|
92
105
|
end
|
@@ -3,11 +3,10 @@ module Cats
|
|
3
3
|
class DispatchTransaction < Transaction
|
4
4
|
before_validation :set_unit
|
5
5
|
|
6
|
-
belongs_to :source, class_name:
|
6
|
+
belongs_to :source, class_name: "Cats::Core::Stack"
|
7
7
|
belongs_to :dispatch_authorization
|
8
8
|
|
9
|
-
validates :source_id, uniqueness: {
|
10
|
-
# validates :reference_no, presence: true
|
9
|
+
validates :source_id, uniqueness: {scope: :dispatch_authorization_id}
|
11
10
|
validate :validate_dispatch
|
12
11
|
validate :validate_source_quantity, :validate_authorized_quantity, unless: :skip_quantity_validation
|
13
12
|
|
@@ -35,7 +34,7 @@ module Cats
|
|
35
34
|
return unless dispatch_authorization
|
36
35
|
|
37
36
|
status = dispatch_authorization.dispatch.dispatch_status
|
38
|
-
errors.add(:base,
|
37
|
+
errors.add(:base, "Dispatch must be approved first.") if status == Dispatch::DRAFT
|
39
38
|
end
|
40
39
|
|
41
40
|
def validate_source_quantity
|
@@ -56,7 +55,7 @@ module Cats
|
|
56
55
|
return unless quantity && unit && dispatch_authorization
|
57
56
|
|
58
57
|
transactions = DispatchTransaction.where(dispatch_authorization: dispatch_authorization)
|
59
|
-
ValidationUtil.validate_quantity(self,
|
58
|
+
ValidationUtil.validate_quantity(self, "dispatch_authorization", transactions, "authorized")
|
60
59
|
end
|
61
60
|
|
62
61
|
def skip_quantity_validation
|
@@ -67,6 +66,17 @@ module Cats
|
|
67
66
|
|
68
67
|
![Dispatch::DRAFT, Dispatch::APPROVED].include?(dispatch_authorization.dispatch.dispatch_status)
|
69
68
|
end
|
69
|
+
|
70
|
+
def self.ransackable_attributes(auth_object = nil)
|
71
|
+
[
|
72
|
+
"dispatch_authorization_id",
|
73
|
+
"quantity",
|
74
|
+
"source_id",
|
75
|
+
"status",
|
76
|
+
"transaction_date",
|
77
|
+
"unit_id"
|
78
|
+
]
|
79
|
+
end
|
70
80
|
end
|
71
81
|
end
|
72
82
|
end
|
@@ -3,13 +3,13 @@ module Cats
|
|
3
3
|
class GiftCertificate < ApplicationRecord
|
4
4
|
belongs_to :donation, optional: true
|
5
5
|
belongs_to :commodity_category
|
6
|
-
belongs_to :unit, class_name:
|
6
|
+
belongs_to :unit, class_name: "UnitOfMeasure"
|
7
7
|
belongs_to :currency
|
8
|
-
belongs_to :destination_warehouse, class_name:
|
8
|
+
belongs_to :destination_warehouse, class_name: "Location"
|
9
9
|
|
10
10
|
validates :reference_no, presence: true, uniqueness: true
|
11
11
|
validates :gift_date, :quantity, :requested_by, :customs_office, presence: true
|
12
|
-
validates :quantity, numericality: {
|
12
|
+
validates :quantity, numericality: {greater_than: 0}
|
13
13
|
|
14
14
|
delegate(:name, to: :commodity_category, prefix: true)
|
15
15
|
delegate(:name, to: :destination_warehouse, prefix: true)
|
@@ -3,18 +3,18 @@ module Cats
|
|
3
3
|
class HubAuthorization < ApplicationRecord
|
4
4
|
before_validation :set_unit
|
5
5
|
|
6
|
-
SOURCE =
|
7
|
-
DESTINATION =
|
6
|
+
SOURCE = "Source".freeze
|
7
|
+
DESTINATION = "Destination".freeze
|
8
8
|
AUTHORIZATION_TYPES = [SOURCE, DESTINATION].freeze
|
9
9
|
|
10
10
|
belongs_to :dispatch_plan_item, optional: true
|
11
11
|
belongs_to :store
|
12
|
-
belongs_to :authorized_by, class_name:
|
13
|
-
belongs_to :unit, class_name:
|
12
|
+
belongs_to :authorized_by, class_name: "Cats::Core::User"
|
13
|
+
belongs_to :unit, class_name: "Cats::Core::UnitOfMeasure"
|
14
14
|
|
15
15
|
validates :quantity, :authorization_type, presence: true
|
16
|
-
validates :quantity, numericality: {
|
17
|
-
validates :authorization_type, inclusion: {
|
16
|
+
validates :quantity, numericality: {greater_than: 0}
|
17
|
+
validates :authorization_type, inclusion: {in: AUTHORIZATION_TYPES}
|
18
18
|
validate :validate_quantity, on: %i[create update]
|
19
19
|
|
20
20
|
delegate(:plan_reference_no, to: :dispatch_plan_item)
|
@@ -37,7 +37,7 @@ module Cats
|
|
37
37
|
dispatch_plan_item: dispatch_plan_item,
|
38
38
|
authorization_type: authorization_type
|
39
39
|
)
|
40
|
-
ValidationUtil.validate_quantity(self,
|
40
|
+
ValidationUtil.validate_quantity(self, "dispatch_plan_item", authorizations, "allocated")
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
@@ -2,11 +2,11 @@ module Cats
|
|
2
2
|
module Core
|
3
3
|
class Loan < ApplicationRecord
|
4
4
|
belongs_to :commodity_category
|
5
|
-
belongs_to :unit, class_name:
|
5
|
+
belongs_to :unit, class_name: "UnitOfMeasure"
|
6
6
|
|
7
7
|
validates :reference_no, presence: true, uniqueness: true
|
8
8
|
validates :lender, :agreement_date, presence: true
|
9
|
-
validates :quantity, presence: true, numericality: {
|
9
|
+
validates :quantity, presence: true, numericality: {greater_than: 0}
|
10
10
|
|
11
11
|
delegate(:name, to: :commodity_category, prefix: true)
|
12
12
|
delegate(:abbreviation, to: :unit, prefix: true)
|