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
@@ -1,12 +1,12 @@
|
|
1
1
|
module Cats
|
2
2
|
module Core
|
3
3
|
class Location < ApplicationRecord
|
4
|
-
REGION =
|
5
|
-
ZONE =
|
6
|
-
WOREDA =
|
7
|
-
FDP =
|
8
|
-
HUB =
|
9
|
-
WAREHOUSE =
|
4
|
+
REGION = "Region".freeze
|
5
|
+
ZONE = "Zone".freeze
|
6
|
+
WOREDA = "Woreda".freeze
|
7
|
+
FDP = "Fdp".freeze
|
8
|
+
HUB = "Hub".freeze
|
9
|
+
WAREHOUSE = "Warehouse".freeze
|
10
10
|
|
11
11
|
LOCATION_TYPES = [REGION, ZONE, WOREDA, FDP, HUB, WAREHOUSE].freeze
|
12
12
|
|
@@ -14,7 +14,7 @@ module Cats
|
|
14
14
|
|
15
15
|
validates :code, :name, :location_type, presence: true
|
16
16
|
validates :code, uniqueness: true
|
17
|
-
validates :location_type, inclusion: {
|
17
|
+
validates :location_type, inclusion: {in: LOCATION_TYPES}
|
18
18
|
validate :validate_location_parent
|
19
19
|
|
20
20
|
delegate(:code, to: :parent, prefix: true, allow_nil: true)
|
@@ -35,7 +35,7 @@ module Cats
|
|
35
35
|
return if location_type == REGION && parent.nil?
|
36
36
|
|
37
37
|
# Check that parent is not nil for locations other than region
|
38
|
-
errors.add(:location,
|
38
|
+
errors.add(:location, "parent cannot be empty") if location_type != REGION && parent.nil?
|
39
39
|
|
40
40
|
# At this point, we may return if parent.nil? is true
|
41
41
|
# because the above statement already took care of that.
|
@@ -53,6 +53,10 @@ module Cats
|
|
53
53
|
|
54
54
|
Store.find_by(code: "FDP-ST-#{code}")
|
55
55
|
end
|
56
|
+
|
57
|
+
def self.ransackable_attributes(auth_object = nil)
|
58
|
+
["code", "location_type", "name"]
|
59
|
+
end
|
56
60
|
end
|
57
61
|
end
|
58
62
|
end
|
@@ -4,9 +4,9 @@ module Cats
|
|
4
4
|
before_validation :set_unit
|
5
5
|
|
6
6
|
belongs_to :receipt_authorization
|
7
|
-
belongs_to :unit, class_name:
|
7
|
+
belongs_to :unit, class_name: "Cats::Core::UnitOfMeasure"
|
8
8
|
|
9
|
-
validates :quantity, presence: true, numericality: {
|
9
|
+
validates :quantity, presence: true, numericality: {greater_than: 0}
|
10
10
|
validate :validate_quantity
|
11
11
|
|
12
12
|
delegate(:abbreviation, to: :unit, prefix: true)
|
@@ -6,11 +6,11 @@ module Cats
|
|
6
6
|
belongs_to :recipient, polymorphic: true
|
7
7
|
|
8
8
|
def message
|
9
|
-
{
|
9
|
+
{id: id, read: !read_at.nil?, created_at: created_at}.merge(to_notification.message)
|
10
10
|
end
|
11
11
|
|
12
12
|
def self.messages(notifications)
|
13
|
-
notifications.
|
13
|
+
notifications.map(&:message)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
@@ -4,14 +4,14 @@ module Cats
|
|
4
4
|
belongs_to :transport_offer
|
5
5
|
belongs_to :transport_bid_item
|
6
6
|
|
7
|
-
validates :price, presence: true, numericality: {
|
8
|
-
validates :rank, numericality: {
|
7
|
+
validates :price, presence: true, numericality: {greater_than_or_equal_to: 0}
|
8
|
+
validates :rank, numericality: {greater_than: 0}, allow_nil: true
|
9
9
|
validate :validate_rank_is_set_for_winner
|
10
10
|
|
11
11
|
delegate(:route, to: :transport_bid_item)
|
12
12
|
|
13
13
|
def mark_as_winner(rank)
|
14
|
-
raise(StandardError,
|
14
|
+
raise(StandardError, "Offer item already marked as winner.") if winner
|
15
15
|
|
16
16
|
self.rank = rank
|
17
17
|
self.winner = true
|
@@ -21,7 +21,7 @@ module Cats
|
|
21
21
|
def validate_rank_is_set_for_winner
|
22
22
|
return if rank
|
23
23
|
|
24
|
-
errors.add(:winner,
|
24
|
+
errors.add(:winner, "cannot be set for a non-ranked offer item.") if winner
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
@@ -1,15 +1,15 @@
|
|
1
1
|
module Cats
|
2
2
|
module Core
|
3
3
|
class Plan < ApplicationRecord
|
4
|
-
DRAFT =
|
5
|
-
APPROVED =
|
6
|
-
NEEDS_APPROVED =
|
4
|
+
DRAFT = "Draft".freeze
|
5
|
+
APPROVED = "Approved".freeze
|
6
|
+
NEEDS_APPROVED = "Needs Approved".freeze
|
7
7
|
|
8
8
|
STATUSES = [DRAFT, APPROVED, NEEDS_APPROVED].freeze
|
9
9
|
|
10
|
-
BELG =
|
11
|
-
MEHER =
|
12
|
-
ANNUAL =
|
10
|
+
BELG = "Belg".freeze
|
11
|
+
MEHER = "Meher".freeze
|
12
|
+
ANNUAL = "Annual".freeze
|
13
13
|
SEASONS = [BELG, MEHER, ANNUAL].freeze
|
14
14
|
|
15
15
|
belongs_to :program
|
@@ -23,10 +23,10 @@ module Cats
|
|
23
23
|
delegate(:code, to: :program, prefix: true)
|
24
24
|
|
25
25
|
validates :reference_no, :year, :status, presence: true
|
26
|
-
validates :total_days, :rounds, presence: true, numericality: {
|
27
|
-
validates :season, presence: true, inclusion: {
|
26
|
+
validates :total_days, :rounds, presence: true, numericality: {greater_than: 0}
|
27
|
+
validates :season, presence: true, inclusion: {in: SEASONS}
|
28
28
|
validates :reference_no, uniqueness: true
|
29
|
-
validates :status, inclusion: {
|
29
|
+
validates :status, inclusion: {in: STATUSES}
|
30
30
|
|
31
31
|
def no_of_round_days
|
32
32
|
total_days / rounds
|
@@ -3,16 +3,16 @@ module Cats
|
|
3
3
|
class PlanItem < ApplicationRecord
|
4
4
|
belongs_to :plan
|
5
5
|
|
6
|
-
belongs_to :region, -> { where(location_type: Cats::Core::Location::REGION) }, class_name:
|
7
|
-
belongs_to :zone, -> { where(location_type: Cats::Core::Location::ZONE) }, class_name:
|
8
|
-
belongs_to :woreda, -> { where(location_type: Cats::Core::Location::WOREDA) }, class_name:
|
9
|
-
belongs_to :fdp, -> { where(location_type: Cats::Core::Location::FDP) }, class_name:
|
6
|
+
belongs_to :region, -> { where(location_type: Cats::Core::Location::REGION) }, class_name: "Cats::Core::Location"
|
7
|
+
belongs_to :zone, -> { where(location_type: Cats::Core::Location::ZONE) }, class_name: "Cats::Core::Location"
|
8
|
+
belongs_to :woreda, -> { where(location_type: Cats::Core::Location::WOREDA) }, class_name: "Cats::Core::Location"
|
9
|
+
belongs_to :fdp, -> { where(location_type: Cats::Core::Location::FDP) }, class_name: "Cats::Core::Location"
|
10
10
|
belongs_to :operator
|
11
11
|
|
12
12
|
has_many :beneficiary_plan_items
|
13
13
|
has_many :plan_item_details, through: :beneficiary_plan_items
|
14
14
|
|
15
|
-
validates :plan_id, uniqueness: {
|
15
|
+
validates :plan_id, uniqueness: {scope: :fdp_id}
|
16
16
|
|
17
17
|
delegate(:name, to: :region, prefix: true)
|
18
18
|
delegate(:name, to: :zone, prefix: true)
|
@@ -4,8 +4,8 @@ module Cats
|
|
4
4
|
belongs_to :beneficiary_plan_item
|
5
5
|
belongs_to :ration
|
6
6
|
|
7
|
-
validates :quantity, presence: true, numericality: {
|
8
|
-
validates :beneficiary_plan_item_id, uniqueness: {
|
7
|
+
validates :quantity, presence: true, numericality: {greater_than: 0}
|
8
|
+
validates :beneficiary_plan_item_id, uniqueness: {scope: :ration_id}
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
@@ -6,7 +6,7 @@ module Cats
|
|
6
6
|
|
7
7
|
validates :code, presence: true, uniqueness: true
|
8
8
|
validates :year, :implementing_agency, presence: true
|
9
|
-
validates :year, numericality: {
|
9
|
+
validates :year, numericality: {greater_than: 2000}
|
10
10
|
|
11
11
|
delegate(:code, to: :program, prefix: true)
|
12
12
|
delegate(:reference_no, to: :source, prefix: true)
|
@@ -1,19 +1,19 @@
|
|
1
1
|
module Cats
|
2
2
|
module Core
|
3
3
|
class PurchaseOrder < ApplicationRecord
|
4
|
-
LOCAL =
|
5
|
-
FOREIGN =
|
4
|
+
LOCAL = "Local".freeze
|
5
|
+
FOREIGN = "Foreign".freeze
|
6
6
|
PURCHASE_TYPES = [LOCAL, FOREIGN].freeze
|
7
7
|
|
8
8
|
belongs_to :cash_donation
|
9
9
|
belongs_to :commodity_category
|
10
10
|
belongs_to :currency
|
11
|
-
belongs_to :unit, class_name:
|
11
|
+
belongs_to :unit, class_name: "Cats::Core::UnitOfMeasure"
|
12
12
|
|
13
13
|
validates :reference_no, :order_date, :supplier, :purchase_type, presence: true
|
14
14
|
validates :reference_no, uniqueness: true
|
15
|
-
validates :purchase_type, inclusion: {
|
16
|
-
validates :quantity, :price, presence: true, numericality: {
|
15
|
+
validates :purchase_type, inclusion: {in: PURCHASE_TYPES}
|
16
|
+
validates :quantity, :price, presence: true, numericality: {greater_than: 0}
|
17
17
|
|
18
18
|
delegate(:name, to: :commodity_category, prefix: true)
|
19
19
|
delegate(:name, to: :unit, prefix: true)
|
@@ -6,7 +6,7 @@ module Cats
|
|
6
6
|
belongs_to :unit_of_measure
|
7
7
|
|
8
8
|
validates :reference_no, presence: true, uniqueness: true
|
9
|
-
validates :quantity, :no_of_days, presence: true, numericality: {
|
9
|
+
validates :quantity, :no_of_days, presence: true, numericality: {greater_than: 0}
|
10
10
|
|
11
11
|
delegate(:name, to: :commodity_category, prefix: true)
|
12
12
|
delegate(:name, to: :beneficiary_category, prefix: true)
|
@@ -4,11 +4,11 @@ module Cats
|
|
4
4
|
before_validation :set_unit
|
5
5
|
|
6
6
|
belongs_to :receipt_authorization
|
7
|
-
belongs_to :unit, class_name:
|
7
|
+
belongs_to :unit, class_name: "Cats::Core::UnitOfMeasure"
|
8
8
|
|
9
|
-
validates :commodity_status, presence: true, inclusion: {
|
10
|
-
validates :commodity_grade, inclusion: {
|
11
|
-
validates :quantity, presence: true, numericality: {
|
9
|
+
validates :commodity_status, presence: true, inclusion: {in: Commodity::COMMODITY_STATUSES}
|
10
|
+
validates :commodity_grade, inclusion: {in: Commodity::COMMODITY_GRADES}, allow_nil: true
|
11
|
+
validates :quantity, presence: true, numericality: {greater_than: 0}
|
12
12
|
# validates :reference_no, presence: true
|
13
13
|
validate :validate_quantity
|
14
14
|
|
@@ -27,7 +27,7 @@ module Cats
|
|
27
27
|
|
28
28
|
receipts = Receipt.where(receipt_authorization: receipt_authorization)
|
29
29
|
losses = LostCommodity.where(receipt_authorization: receipt_authorization)
|
30
|
-
ValidationUtil.validate_quantity(self,
|
30
|
+
ValidationUtil.validate_quantity(self, "receipt_authorization", receipts + losses, "authorized")
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
@@ -5,14 +5,18 @@ module Cats
|
|
5
5
|
has_many :lost_commodities
|
6
6
|
has_many :receipt_transactions
|
7
7
|
|
8
|
-
validates :received_quantity, presence: true, numericality: {
|
8
|
+
validates :received_quantity, presence: true, numericality: {greater_than_or_equal_to: 0}
|
9
9
|
validate :validate_quantity
|
10
10
|
|
11
11
|
def validate_quantity
|
12
12
|
return unless dispatch && quantity && unit
|
13
13
|
|
14
14
|
authorizations = ReceiptAuthorization.where(dispatch: dispatch)
|
15
|
-
ValidationUtil.validate_quantity(self,
|
15
|
+
ValidationUtil.validate_quantity(self, "dispatch", authorizations, "dispatch")
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.ransackable_attributes(auth_object = nil)
|
19
|
+
["authorized_by_id", "dispatch_id", "received_quantity", "quantity", "status", "store_id", "unit_id"]
|
16
20
|
end
|
17
21
|
end
|
18
22
|
end
|
@@ -4,10 +4,10 @@ module Cats
|
|
4
4
|
before_validation :set_unit
|
5
5
|
|
6
6
|
belongs_to :receipt_authorization
|
7
|
-
belongs_to :destination, class_name:
|
7
|
+
belongs_to :destination, class_name: "Cats::Core::Stack"
|
8
8
|
|
9
9
|
validates :transaction_date, presence: true
|
10
|
-
validates :quantity, presence: true, numericality: {
|
10
|
+
validates :quantity, presence: true, numericality: {greater_than: 0}
|
11
11
|
validates :receipt_number, presence: true
|
12
12
|
validate :validate_receipt, :validate_quantity
|
13
13
|
|
@@ -26,14 +26,14 @@ module Cats
|
|
26
26
|
return unless receipt_authorization
|
27
27
|
|
28
28
|
status = receipt_authorization.status
|
29
|
-
errors.add(:receipt_authorization,
|
29
|
+
errors.add(:receipt_authorization, "must be confirmed.") if status == ReceiptAuthorization::AUTHORIZED
|
30
30
|
end
|
31
31
|
|
32
32
|
def validate_quantity
|
33
33
|
return unless quantity && destination && receipt_authorization
|
34
34
|
|
35
35
|
transactions = ReceiptTransaction.where(receipt_authorization: receipt_authorization)
|
36
|
-
ValidationUtil.validate_quantity(self,
|
36
|
+
ValidationUtil.validate_quantity(self, "receipt_authorization", transactions, "authorized")
|
37
37
|
end
|
38
38
|
|
39
39
|
def commit
|
@@ -45,6 +45,10 @@ module Cats
|
|
45
45
|
save!
|
46
46
|
end
|
47
47
|
end
|
48
|
+
|
49
|
+
def self.ransackable_attributes(auth_object = nil)
|
50
|
+
["destination_id", "quantity", "receipt_authorization_id", "receipt_number", "status", "transaction_date", "unit_id"]
|
51
|
+
end
|
48
52
|
end
|
49
53
|
end
|
50
54
|
end
|
@@ -5,16 +5,16 @@ module Cats
|
|
5
5
|
|
6
6
|
before_validation :set_unit
|
7
7
|
|
8
|
-
ALLOCATED =
|
8
|
+
ALLOCATED = "Allocated".freeze
|
9
9
|
STATUSES << ALLOCATED
|
10
10
|
|
11
11
|
belongs_to :commodity
|
12
|
-
belongs_to :unit, class_name:
|
12
|
+
belongs_to :unit, class_name: "Cats::Core::UnitOfMeasure"
|
13
13
|
|
14
14
|
validates :reference_no, :request_date, :quantity, presence: true
|
15
15
|
validates :reference_no, uniqueness: true
|
16
|
-
validates :quantity, numericality: {
|
17
|
-
validates :status, presence: true, inclusion: {
|
16
|
+
validates :quantity, numericality: {greater_than_or_equal_to: 0}
|
17
|
+
validates :status, presence: true, inclusion: {in: STATUSES}
|
18
18
|
validate :validate_commodity_status, :validate_quantity
|
19
19
|
|
20
20
|
delegate(:batch_no, to: :commodity, prefix: true)
|
@@ -39,7 +39,7 @@ module Cats
|
|
39
39
|
def validate_commodity_status
|
40
40
|
return unless commodity
|
41
41
|
|
42
|
-
errors.add(:commodity,
|
42
|
+
errors.add(:commodity, "should be approved first.") unless commodity.status == Commodity::APPROVED
|
43
43
|
end
|
44
44
|
|
45
45
|
def validate_quantity
|
@@ -61,21 +61,21 @@ module Cats
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def approve
|
64
|
-
raise(StandardError,
|
64
|
+
raise(StandardError, "Request is not in draft state.") unless status == DRAFT
|
65
65
|
|
66
66
|
self.status = APPROVED
|
67
67
|
save!
|
68
68
|
end
|
69
69
|
|
70
70
|
def complete
|
71
|
-
raise(StandardError,
|
71
|
+
raise(StandardError, "Request is not approved.") unless status == APPROVED
|
72
72
|
|
73
73
|
self.status = COMPLETED
|
74
74
|
save!
|
75
75
|
end
|
76
76
|
|
77
77
|
def allocate
|
78
|
-
raise(StandardError,
|
78
|
+
raise(StandardError, "Request is not completed.") unless status == COMPLETED
|
79
79
|
|
80
80
|
self.status = ALLOCATED
|
81
81
|
save!
|
@@ -12,7 +12,7 @@ module Cats
|
|
12
12
|
|
13
13
|
return if role.application_module_id == menu.application_module.id
|
14
14
|
|
15
|
-
errors.add(:base,
|
15
|
+
errors.add(:base, "Application module does not match for role and menu")
|
16
16
|
end
|
17
17
|
|
18
18
|
delegate(:label, to: :menu, prefix: false)
|
@@ -4,13 +4,21 @@ module Cats
|
|
4
4
|
belongs_to :beneficiary
|
5
5
|
belongs_to :round_plan_item
|
6
6
|
belongs_to :commodity_category
|
7
|
-
belongs_to :unit, class_name:
|
7
|
+
belongs_to :unit, class_name: "UnitOfMeasure"
|
8
8
|
|
9
|
-
validates :quantity, presence: true, numericality: {
|
9
|
+
validates :quantity, presence: true, numericality: {greater_than: 0}
|
10
10
|
|
11
11
|
delegate(:full_name, to: :beneficiary, prefix: true)
|
12
12
|
delegate(:name, to: :commodity_category, prefix: true)
|
13
13
|
delegate(:abbreviation, to: :unit, prefix: true)
|
14
|
+
|
15
|
+
def self.ransackable_attributes(auth_object = nil)
|
16
|
+
["beneficiary_id", "commodity_category_id", "quantity", "received", "round_plan_item_id", "unit_id"]
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.ransackable_associations(auth_object = nil)
|
20
|
+
["beneficiary", "commodity_category", "round_plan_item", "unit"]
|
21
|
+
end
|
14
22
|
end
|
15
23
|
end
|
16
24
|
end
|
@@ -3,14 +3,14 @@ module Cats
|
|
3
3
|
class RoundPlan < ApplicationRecord
|
4
4
|
include Dispatchable
|
5
5
|
|
6
|
-
NEEDS_APPROVED =
|
7
|
-
IN_PROGRESS =
|
6
|
+
NEEDS_APPROVED = "Needs Approved".freeze
|
7
|
+
IN_PROGRESS = "In Progress".freeze
|
8
8
|
|
9
9
|
STATUSES << NEEDS_APPROVED
|
10
10
|
STATUSES << IN_PROGRESS
|
11
11
|
|
12
12
|
belongs_to :plan
|
13
|
-
belongs_to :region, class_name:
|
13
|
+
belongs_to :region, class_name: "Cats::Core::Location"
|
14
14
|
|
15
15
|
has_many :round_plan_items
|
16
16
|
has_many :round_rations
|
@@ -20,7 +20,7 @@ module Cats
|
|
20
20
|
|
21
21
|
validates :rounds, presence: true
|
22
22
|
validates :reference_no, presence: true, uniqueness: true
|
23
|
-
validates :status, presence: true, inclusion: {
|
23
|
+
validates :status, presence: true, inclusion: {in: RoundPlan::STATUSES}
|
24
24
|
validate :validate_region
|
25
25
|
validate :validate_rounds, on: :create
|
26
26
|
|
@@ -37,15 +37,15 @@ module Cats
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def approve
|
40
|
-
raise(StandardError,
|
40
|
+
raise(StandardError, "Plan is not in draft state.") unless status == DRAFT
|
41
41
|
|
42
|
-
raise(StandardError,
|
42
|
+
raise(StandardError, "Empty plan cannot be approved.") if round_plan_items.count.zero?
|
43
43
|
|
44
44
|
update!(status: APPROVED)
|
45
45
|
end
|
46
46
|
|
47
47
|
def in_progress
|
48
|
-
raise(StandardError,
|
48
|
+
raise(StandardError, "Plan is not approved.") unless status == APPROVED || status == IN_PROGRESS
|
49
49
|
|
50
50
|
self.status = IN_PROGRESS
|
51
51
|
save!
|
@@ -54,22 +54,26 @@ module Cats
|
|
54
54
|
def validate_rounds
|
55
55
|
return unless rounds && plan
|
56
56
|
|
57
|
-
errors.add(:rounds,
|
57
|
+
errors.add(:rounds, "cannot be an empty list") if rounds.empty?
|
58
58
|
|
59
59
|
existing_rounds = plan.round_plans.where(region: region).map(&:rounds).sum([])
|
60
60
|
rounds.each do |round|
|
61
61
|
if round > plan.rounds
|
62
|
-
errors.add(:rounds,
|
62
|
+
errors.add(:rounds, "cannot exceed the total number of rounds specified in the plan.")
|
63
63
|
break
|
64
64
|
end
|
65
65
|
end
|
66
|
-
errors.add(:rounds,
|
66
|
+
errors.add(:rounds, "cannot be repeated.") unless existing_rounds - rounds == existing_rounds
|
67
67
|
end
|
68
68
|
|
69
69
|
def validate_region
|
70
70
|
return unless region
|
71
71
|
|
72
|
-
errors.add(:region,
|
72
|
+
errors.add(:region, "is not valid.") unless region.location_type == Location::REGION
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.ransackable_attributes(auth_object = nil)
|
76
|
+
["plan_id", "reference_no", "region_id", "rounds", "status"]
|
73
77
|
end
|
74
78
|
end
|
75
79
|
end
|
@@ -2,10 +2,10 @@ module Cats
|
|
2
2
|
module Core
|
3
3
|
class RoundPlanItem < ApplicationRecord
|
4
4
|
belongs_to :round_plan
|
5
|
-
belongs_to :region, -> { where(location_type: Cats::Core::Location::REGION) }, class_name:
|
6
|
-
belongs_to :zone, -> { where(location_type: Cats::Core::Location::ZONE) }, class_name:
|
7
|
-
belongs_to :woreda, -> { where(location_type: Cats::Core::Location::WOREDA) }, class_name:
|
8
|
-
belongs_to :fdp, -> { where(location_type: Cats::Core::Location::FDP) }, class_name:
|
5
|
+
belongs_to :region, -> { where(location_type: Cats::Core::Location::REGION) }, class_name: "Cats::Core::Location"
|
6
|
+
belongs_to :zone, -> { where(location_type: Cats::Core::Location::ZONE) }, class_name: "Cats::Core::Location"
|
7
|
+
belongs_to :woreda, -> { where(location_type: Cats::Core::Location::WOREDA) }, class_name: "Cats::Core::Location"
|
8
|
+
belongs_to :fdp, -> { where(location_type: Cats::Core::Location::FDP) }, class_name: "Cats::Core::Location"
|
9
9
|
belongs_to :operator
|
10
10
|
|
11
11
|
has_many :beneficiary_round_plan_items
|
@@ -13,7 +13,7 @@ module Cats
|
|
13
13
|
has_many :round_beneficiaries
|
14
14
|
|
15
15
|
validates :plan_item_id, presence: true
|
16
|
-
validates :round_plan_id, uniqueness: {
|
16
|
+
validates :round_plan_id, uniqueness: {scope: :fdp_id}
|
17
17
|
|
18
18
|
delegate(:reference_no, to: :round_plan, prefix: true)
|
19
19
|
delegate(:name, to: :region, prefix: true)
|
@@ -21,6 +21,10 @@ module Cats
|
|
21
21
|
delegate(:name, to: :woreda, prefix: true)
|
22
22
|
delegate(:name, to: :fdp, prefix: true)
|
23
23
|
delegate(:name, to: :operator, prefix: true)
|
24
|
+
|
25
|
+
def self.ransackable_attributes(auth_object = nil)
|
26
|
+
["fdp_id", "operator_id", "plan_item_id", "region_id", "round_plan_id", "woreda_id", "zone_id"]
|
27
|
+
end
|
24
28
|
end
|
25
29
|
end
|
26
30
|
end
|
@@ -3,10 +3,10 @@ module Cats
|
|
3
3
|
class RoundPlanItemDetail < ApplicationRecord
|
4
4
|
belongs_to :beneficiary_round_plan_item
|
5
5
|
belongs_to :round_ration
|
6
|
-
belongs_to :unit, class_name:
|
6
|
+
belongs_to :unit, class_name: "Cats::Core::UnitOfMeasure"
|
7
7
|
|
8
|
-
validates :quantity, presence: true, numericality: {
|
9
|
-
validates :beneficiary_round_plan_item_id, uniqueness: {
|
8
|
+
validates :quantity, presence: true, numericality: {greater_than: 0}
|
9
|
+
validates :beneficiary_round_plan_item_id, uniqueness: {scope: :round_ration_id}
|
10
10
|
|
11
11
|
delegate(:abbreviation, to: :unit, prefix: true)
|
12
12
|
delegate(:commodity_category_name, to: :round_ration, prefix: false)
|
@@ -6,8 +6,8 @@ module Cats
|
|
6
6
|
belongs_to :unit_of_measure
|
7
7
|
belongs_to :round_plan
|
8
8
|
|
9
|
-
validates :quantity, presence: true, numericality: {
|
10
|
-
validates :no_of_days, presence: true, numericality: {
|
9
|
+
validates :quantity, presence: true, numericality: {greater_than_or_equal_to: 0}
|
10
|
+
validates :no_of_days, presence: true, numericality: {greater_than: 0}
|
11
11
|
|
12
12
|
delegate(:name, to: :commodity_category, prefix: true)
|
13
13
|
delegate(:name, to: :beneficiary_category, prefix: true)
|
@@ -3,11 +3,11 @@ module Cats
|
|
3
3
|
class Route < ApplicationRecord
|
4
4
|
before_validation :set_name, on: %i[create update]
|
5
5
|
|
6
|
-
belongs_to :region, class_name:
|
7
|
-
belongs_to :source, class_name:
|
8
|
-
belongs_to :destination, class_name:
|
6
|
+
belongs_to :region, class_name: "Cats::Core::Location"
|
7
|
+
belongs_to :source, class_name: "Cats::Core::Location"
|
8
|
+
belongs_to :destination, class_name: "Cats::Core::Location"
|
9
9
|
|
10
|
-
validates :source_id, uniqueness: {
|
10
|
+
validates :source_id, uniqueness: {scope: :destination_id}
|
11
11
|
validate :validate_region, :validate_source, :validate_destination, :validate_route
|
12
12
|
|
13
13
|
delegate(:name, to: :region, prefix: true)
|
@@ -21,19 +21,19 @@ module Cats
|
|
21
21
|
def validate_region
|
22
22
|
return unless region
|
23
23
|
|
24
|
-
errors.add(:region,
|
24
|
+
errors.add(:region, "should be a valid region.") unless region.location_type == Location::REGION
|
25
25
|
end
|
26
26
|
|
27
27
|
def validate_source
|
28
28
|
return unless source
|
29
29
|
|
30
|
-
errors.add(:source,
|
30
|
+
errors.add(:source, "cannot be a region.") if source.location_type == Location::REGION
|
31
31
|
end
|
32
32
|
|
33
33
|
def validate_destination
|
34
34
|
return unless destination
|
35
35
|
|
36
|
-
errors.add(:destination,
|
36
|
+
errors.add(:destination, "cannot be a region.") if destination.location_type == Location::REGION
|
37
37
|
end
|
38
38
|
|
39
39
|
def validate_route
|
@@ -41,7 +41,11 @@ module Cats
|
|
41
41
|
|
42
42
|
return unless destination
|
43
43
|
|
44
|
-
errors.add(:base,
|
44
|
+
errors.add(:base, "Source and destination cannot be the same") if source == destination
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.ransackable_attributes(auth_object = nil)
|
48
|
+
["destination_id", "name", "region_id", "source_id"]
|
45
49
|
end
|
46
50
|
end
|
47
51
|
end
|