cats_core 1.4.39 → 1.4.42

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/cats/core/cash_donations_controller.rb +19 -0
  3. data/app/controllers/cats/core/commodity_donations_controller.rb +22 -0
  4. data/app/controllers/cats/core/dispatch_plans_controller.rb +24 -0
  5. data/app/controllers/cats/core/loans_controller.rb +20 -0
  6. data/app/controllers/cats/core/purchase_orders_controller.rb +24 -0
  7. data/app/controllers/cats/core/swaps_controller.rb +21 -0
  8. data/app/models/cats/core/cash_donation.rb +11 -0
  9. data/app/models/cats/core/commodity_donation.rb +15 -0
  10. data/app/models/cats/core/dispatch_plan.rb +1 -1
  11. data/app/models/cats/core/donation.rb +2 -16
  12. data/app/models/cats/core/gift_certificate.rb +3 -23
  13. data/app/models/cats/core/loan.rb +15 -0
  14. data/app/models/cats/core/project.rb +4 -0
  15. data/app/models/cats/core/purchase_order.rb +5 -13
  16. data/app/models/cats/core/rhn_request.rb +4 -4
  17. data/app/models/cats/core/round_plan.rb +1 -4
  18. data/app/models/cats/core/swap.rb +19 -0
  19. data/app/models/concerns/cats/core/dispatchable.rb +8 -0
  20. data/app/serializers/cats/core/cash_donation_serializer.rb +8 -0
  21. data/app/serializers/cats/core/commodity_donation_serializer.rb +9 -0
  22. data/app/serializers/cats/core/loan_serializer.rb +8 -0
  23. data/app/serializers/cats/core/purchase_order_serializer.rb +9 -0
  24. data/app/serializers/cats/core/swap_serializer.rb +9 -0
  25. data/app/services/cats/core/dispatch_plan_service.rb +79 -0
  26. data/config/routes.rb +12 -0
  27. data/db/migrate/20210717032330_create_cats_core_commodity_donations.rb +29 -0
  28. data/db/migrate/20210717032408_create_cats_core_cash_donations.rb +20 -0
  29. data/db/migrate/20210717032602_create_cats_core_gift_certificates.rb +2 -8
  30. data/db/migrate/20210717032855_create_cats_core_purchase_orders.rb +9 -5
  31. data/db/migrate/20210717032927_create_cats_core_projects.rb +4 -0
  32. data/db/migrate/20220626063501_create_cats_core_loans.rb +21 -0
  33. data/db/migrate/20220626063757_create_cats_core_swaps.rb +29 -0
  34. data/lib/cats/core/version.rb +1 -1
  35. data/spec/factories/cats/core/cash_donations.rb +10 -0
  36. data/spec/factories/cats/core/{donations.rb → commodity_donations.rb} +3 -7
  37. data/spec/factories/cats/core/gift_certificates.rb +5 -6
  38. data/spec/factories/cats/core/loans.rb +11 -0
  39. data/spec/factories/cats/core/projects.rb +2 -1
  40. data/spec/factories/cats/core/purchase_orders.rb +3 -1
  41. data/spec/factories/cats/core/swaps.rb +13 -0
  42. metadata +27 -7
  43. data/db/migrate/20210717032330_create_cats_core_donations.rb +0 -36
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a86860a6e6a86d7d133ab9a050bffdd675d00c1fad85e9af8b9fabf24183711d
4
- data.tar.gz: 23001d95a8ce470d196ab560dd72d782f080ed8fed7e9067a12674b06084cf35
3
+ metadata.gz: b075feb71a427f4901c4fb32fe34f8b2ad2dfb902a3386b9c92b10fd6e809762
4
+ data.tar.gz: 283f7c441c7d3920fbe5a7ce4253d41d24fccbaa9432d634f7004abe2cfa531f
5
5
  SHA512:
6
- metadata.gz: 10324cc46243b87345e485e9f176cd1b4a9acc277d8c26aa5b1372c3dc211fa4e4a3f473e81ad94c1bcba0f67c8a9cbb988b5648f4bd70063ab10da0c4865636
7
- data.tar.gz: 0c530f68241d07329f96a399b2fcac5cffc30bb549c5ddb605739a49db2150cbef97b24e290459232d05f4bf67390ecf66c706bc2f552628743853b4d7bec86b
6
+ metadata.gz: 8975cb79857ea468f7c13b638ff8668849b3d0021d59df037f1d88ceb508090481fe10da028a5b5a54ee23117c270c1b67e1d8b9149bc9eeec421015ea92eda9
7
+ data.tar.gz: 54936908e0394ead9f8f8ffd887949f1f6afbd1fcb63d7cdf90b5d9d0f32dcd6a0b5f73009d326c03550b5ce43bce7d8bbf758e8a2a735b23c6b653302b48eba
@@ -0,0 +1,19 @@
1
+ module Cats
2
+ module Core
3
+ class CashDonationsController < ApplicationController
4
+ include Common
5
+
6
+ def index
7
+ super do
8
+ CashDonation.includes(:donor, :currency).all
9
+ end
10
+ end
11
+
12
+ private
13
+
14
+ def model_params
15
+ params.require(:payload).permit(:reference_no, :description, :donated_on, :donor_id, :amount, :currency_id)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,22 @@
1
+ module Cats
2
+ module Core
3
+ class CommodityDonationsController < ApplicationController
4
+ include Common
5
+
6
+ def index
7
+ super do
8
+ CommodityDonation.includes(:donor, :plan, :unit, :commodity_category).all
9
+ end
10
+ end
11
+
12
+ private
13
+
14
+ def model_params
15
+ params.require(:payload).permit(
16
+ :reference_no, :description, :shipping_reference, :donated_on, :donor_id, :plan_id, :quantity,
17
+ :commodity_category_id, :unit_id
18
+ )
19
+ end
20
+ end
21
+ end
22
+ end
@@ -27,6 +27,18 @@ module Cats
27
27
  render json: { success: false, error: e.message }, status: :unprocessable_entity
28
28
  end
29
29
 
30
+ def generate
31
+ service = DispatchPlanService.new
32
+ items = service.generate(params[:id])
33
+ render json: { success: true, data: serialize(items) }
34
+ end
35
+
36
+ def bulk_create
37
+ service = DispatchPlanService.new
38
+ plan = service.bulk_create(bulk_create_params, current_user)
39
+ render json: { success: true, data: serialize(plan) }
40
+ end
41
+
30
42
  def approve
31
43
  service = DispatchPlanService.new
32
44
  plan = DispatchPlan.find(params[:id])
@@ -41,6 +53,18 @@ module Cats
41
53
  def model_params
42
54
  params.require(:payload).permit(:reference_no, :dispatchable_id, :dispatchable_type)
43
55
  end
56
+
57
+ def bulk_create_params
58
+ params.require(:payload).permit(
59
+ :reference_no,
60
+ :dispatchable_id,
61
+ :dispatchable_type,
62
+ items: %i[
63
+ reference_no region zone woreda fdp commodity_category unit_id unit quantity source_id destination_id
64
+ commodity_id
65
+ ]
66
+ )
67
+ end
44
68
  end
45
69
  end
46
70
  end
@@ -0,0 +1,20 @@
1
+ module Cats
2
+ module Core
3
+ class LoansController < ApplicationController
4
+ include Common
5
+
6
+ def index
7
+ super do
8
+ Loan.includes(:commodity_category, :unit).all
9
+ end
10
+ end
11
+
12
+ private
13
+
14
+ def model_params
15
+ params.require(:payload).permit(:reference_no, :lender, :agreement_date, :repayment_date, :quantity, :unit_id,
16
+ :commodity_category_id)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,24 @@
1
+ module Cats
2
+ module Core
3
+ class PurchaseOrdersController < ApplicationController
4
+ include Common
5
+
6
+ def index
7
+ purchase_orders = Cats::Core::PurchaseOrder.where(cash_donation_id: params[:id]).includes(
8
+ :commodity_category,
9
+ :unit,
10
+ :currency
11
+ )
12
+ render json: { success: true, data: serialize(purchase_orders) }
13
+ end
14
+
15
+ private
16
+
17
+ def model_params
18
+ params.require(:payload).permit(:reference_no, :order_date, :requisition_no, :supplier, :cash_donation_id,
19
+ :commodity_category_id, :quantity, :purchase_type, :unit_id, :price,
20
+ :currency_id)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,21 @@
1
+ module Cats
2
+ module Core
3
+ class SwapsController < ApplicationController
4
+ include Common
5
+
6
+ def index
7
+ super do
8
+ Swap.includes(:issued_commodity, :issued_unit, :received_commodity, :received_unit).all
9
+ end
10
+ end
11
+
12
+ private
13
+
14
+ def model_params
15
+ params.require(:payload).permit(:reference_no, :swapper, :agreement_date, :issued_commodity_id,
16
+ :issued_quantity, :received_commodity_id, :received_quantity,
17
+ :issued_unit_id, :received_unit_id)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,11 @@
1
+ module Cats
2
+ module Core
3
+ class CashDonation < Donation
4
+ belongs_to :currency
5
+
6
+ validates :amount, presence: true, numericality: { greater_than: 0 }
7
+
8
+ delegate(:code, to: :currency, prefix: true)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ module Cats
2
+ module Core
3
+ class CommodityDonation < Donation
4
+ belongs_to :plan, optional: true
5
+ belongs_to :commodity_category
6
+ belongs_to :unit, class_name: 'UnitOfMeasure'
7
+
8
+ validates :quantity, presence: true, numericality: { greater_than: 0 }
9
+
10
+ delegate(:reference_no, to: :plan, prefix: true, allow_nil: true)
11
+ delegate(:name, to: :commodity_category, prefix: true)
12
+ delegate(:abbreviation, to: :unit, prefix: true)
13
+ end
14
+ end
15
+ end
@@ -32,7 +32,7 @@ module Cats
32
32
 
33
33
  return if dispatchable.status == RhnRequest::APPROVED
34
34
 
35
- errors.add(:dispatchable, 'is already reserved.') if id.nil?
35
+ errors.add(:dispatchable, 'is already reserved.') if id.nil? && dispatchable.status == Dispatchable::RESERVED
36
36
  end
37
37
 
38
38
  def approve
@@ -1,28 +1,14 @@
1
1
  module Cats
2
2
  module Core
3
3
  class Donation < ApplicationRecord
4
- CASH = 'Cash'.freeze
5
- KIND = 'Kind'.freeze
6
- DONATION_TYPES = [CASH, KIND].freeze
4
+ self.abstract_class = true
7
5
 
8
6
  belongs_to :donor
9
- belongs_to :plan, optional: true
10
- belongs_to :currency, optional: true
11
- belongs_to :commodity_category, optional: true
12
- belongs_to :unit_of_measure, optional: true
13
7
 
14
- validates :reference_no, :amount, :donation_type, :donated_on, :agency, presence: true
8
+ validates :reference_no, :donated_on, presence: true
15
9
  validates :reference_no, uniqueness: true
16
- validates :donation_type, inclusion: { in: DONATION_TYPES }
17
- validates :currency, presence: true, if: -> { donation_type == CASH }
18
- validates :commodity_category, presence: true, if: -> { donation_type == KIND }
19
- validates :unit_of_measure, presence: true, if: -> { donation_type == KIND }
20
10
 
21
11
  delegate(:name, to: :donor, prefix: true)
22
- delegate(:reference_no, to: :plan, prefix: true, allow_nil: true)
23
- delegate(:name, to: :commodity_category, prefix: true, allow_nil: true)
24
- delegate(:code, to: :currency, prefix: true, allow_nil: true)
25
- delegate(:abbreviation, to: :unit_of_measure, prefix: true, allow_nil: true)
26
12
  end
27
13
  end
28
14
  end
@@ -3,9 +3,9 @@ module Cats
3
3
  class GiftCertificate < ApplicationRecord
4
4
  belongs_to :donation, optional: true
5
5
  belongs_to :commodity_category
6
- belongs_to :unit_of_measure
6
+ belongs_to :unit, class_name: 'UnitOfMeasure'
7
7
  belongs_to :currency
8
- belongs_to :destination_warehouse, class_name: 'Cats::Core::Location'
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
@@ -13,28 +13,8 @@ module Cats
13
13
 
14
14
  delegate(:name, to: :commodity_category, prefix: true)
15
15
  delegate(:name, to: :destination_warehouse, prefix: true)
16
- delegate(:abbreviation, to: :unit_of_measure, prefix: true)
16
+ delegate(:abbreviation, to: :unit, prefix: true)
17
17
  delegate(:code, to: :currency, prefix: true)
18
-
19
- before_validation :set_commodity_category
20
- after_create :update_donation
21
-
22
- def update_donation
23
- return unless donation
24
-
25
- return if donation.active
26
-
27
- donation.active = true
28
- donation.save!
29
- end
30
-
31
- def set_commodity_category
32
- return unless donation
33
-
34
- return if commodity_category == donation.commodity_category
35
-
36
- self.commodity_category = donation.commodity_category
37
- end
38
18
  end
39
19
  end
40
20
  end
@@ -0,0 +1,15 @@
1
+ module Cats
2
+ module Core
3
+ class Loan < ApplicationRecord
4
+ belongs_to :commodity_category
5
+ belongs_to :unit, class_name: 'UnitOfMeasure'
6
+
7
+ validates :reference_no, presence: true, uniqueness: true
8
+ validates :lender, :agreement_date, presence: true
9
+ validates :quantity, presence: true, numericality: { greater_than: 0 }
10
+
11
+ delegate(:name, to: :commodity_category, prefix: true)
12
+ delegate(:abbreviation, to: :unit, prefix: true)
13
+ end
14
+ end
15
+ end
@@ -2,10 +2,14 @@ module Cats
2
2
  module Core
3
3
  class Project < ApplicationRecord
4
4
  belongs_to :source, polymorphic: true
5
+ belongs_to :program
5
6
 
6
7
  validates :code, presence: true, uniqueness: true
7
8
  validates :year, :implementing_agency, presence: true
8
9
  validates :year, numericality: { greater_than: 2000 }
10
+
11
+ delegate(:code, to: :program, prefix: true)
12
+ delegate(:reference_no, to: :source, prefix: true)
9
13
  end
10
14
  end
11
15
  end
@@ -5,27 +5,19 @@ module Cats
5
5
  FOREIGN = 'Foreign'.freeze
6
6
  PURCHASE_TYPES = [LOCAL, FOREIGN].freeze
7
7
 
8
- belongs_to :donation
8
+ belongs_to :cash_donation
9
9
  belongs_to :commodity_category
10
+ belongs_to :currency
10
11
  belongs_to :unit, class_name: 'Cats::Core::UnitOfMeasure'
11
12
 
12
- validates :reference_no, :order_date, :supplier, :quantity, :purchase_type, presence: true
13
+ validates :reference_no, :order_date, :supplier, :purchase_type, presence: true
13
14
  validates :reference_no, uniqueness: true
14
15
  validates :purchase_type, inclusion: { in: PURCHASE_TYPES }
15
- validates :quantity, numericality: { greater_than: 0 }
16
+ validates :quantity, :price, presence: true, numericality: { greater_than: 0 }
16
17
 
17
18
  delegate(:name, to: :commodity_category, prefix: true)
18
19
  delegate(:name, to: :unit, prefix: true)
19
-
20
- after_create :update_donation
21
-
22
- def update_donation
23
- donation = self.donation
24
- return if donation.active
25
-
26
- donation.active = true
27
- donation.save!
28
- end
20
+ delegate(:code, to: :currency, prefix: true)
29
21
  end
30
22
  end
31
23
  end
@@ -3,11 +3,11 @@ module Cats
3
3
  class RhnRequest < ApplicationRecord
4
4
  include Dispatchable
5
5
 
6
- DRAFT = 'Draft'.freeze
7
- APPROVED = 'Approved'.freeze
8
- RESERVED = 'Reserved'.freeze
6
+ # DRAFT = 'Draft'.freeze
7
+ # APPROVED = 'Approved'.freeze
8
+ # RESERVED = 'Reserved'.freeze
9
9
  ALLOCATED = 'Allocated'.freeze
10
- STATUSES = [DRAFT, APPROVED, RESERVED, ALLOCATED].freeze
10
+ STATUSES << ALLOCATED
11
11
 
12
12
  belongs_to :commodity
13
13
 
@@ -3,12 +3,9 @@ module Cats
3
3
  class RoundPlan < ApplicationRecord
4
4
  include Dispatchable
5
5
 
6
- DRAFT = 'Draft'.freeze
7
- APPROVED = 'Approved'.freeze
8
- RESERVED = 'Reserved'.freeze
9
6
  NEEDS_APPROVED = 'Needs Approved'.freeze
10
7
 
11
- STATUSES = [DRAFT, APPROVED, RESERVED, NEEDS_APPROVED].freeze
8
+ STATUSES << NEEDS_APPROVED
12
9
 
13
10
  belongs_to :plan
14
11
  belongs_to :region, class_name: 'Cats::Core::Location'
@@ -0,0 +1,19 @@
1
+ module Cats
2
+ module Core
3
+ class Swap < ApplicationRecord
4
+ belongs_to :issued_commodity, class_name: 'CommodityCategory'
5
+ belongs_to :issued_unit, class_name: 'UnitOfMeasure'
6
+ belongs_to :received_commodity, class_name: 'CommodityCategory'
7
+ belongs_to :received_unit, class_name: 'UnitOfMeasure'
8
+
9
+ validates :reference_no, presence: true, uniqueness: true
10
+ validates :swapper, :agreement_date, :issued_quantity, :received_quantity, presence: true
11
+ validates :issued_quantity, :received_quantity, presence: true, numericality: { greater_than: 0 }
12
+
13
+ delegate(:name, to: :issued_commodity, prefix: true)
14
+ delegate(:name, to: :received_commodity, prefix: true)
15
+ delegate(:abbreviation, to: :issued_unit, prefix: true)
16
+ delegate(:abbreviation, to: :received_unit, prefix: true)
17
+ end
18
+ end
19
+ end
@@ -7,6 +7,14 @@ module Cats
7
7
  module Dispatchable
8
8
  extend ActiveSupport::Concern
9
9
 
10
+ DRAFT = 'Draft'.freeze
11
+ APPROVED = 'Approved'.freeze
12
+ RESERVED = 'Reserved'.freeze
13
+
14
+ # rubocop:disable Style/MutableConstant
15
+ STATUSES = [DRAFT, APPROVED, RESERVED]
16
+ # rubocop:enable Style/MutableConstant
17
+
10
18
  included do
11
19
  has_many :dispatch_plans, as: :dispatchable
12
20
  end
@@ -0,0 +1,8 @@
1
+ module Cats
2
+ module Core
3
+ class CashDonationSerializer < ActiveModel::Serializer
4
+ attributes :id, :reference_no, :description, :donated_on, :donor_id, :donor_name, :amount, :currency_id,
5
+ :currency_code
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,9 @@
1
+ module Cats
2
+ module Core
3
+ class CommodityDonationSerializer < ActiveModel::Serializer
4
+ attributes :id, :reference_no, :donated_on, :donor_id, :donor_name, :plan_id, :plan_reference_no,
5
+ :quantity, :unit_id, :unit_abbreviation, :description, :commodity_category_id,
6
+ :commodity_category_name, :shipping_reference
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ module Cats
2
+ module Core
3
+ class LoanSerializer < ActiveModel::Serializer
4
+ attributes :id, :reference_no, :lender, :agreement_date, :repayment_date, :commodity_category_id,
5
+ :commodity_category_name, :quantity, :unit_id, :unit_abbreviation
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,9 @@
1
+ module Cats
2
+ module Core
3
+ class PurchaseOrderSerializer < ActiveModel::Serializer
4
+ attributes :id, :reference_no, :order_date, :requisition_no, :supplier, :cash_donation_id, :purchase_type,
5
+ :commodity_category_id, :commodity_category_name, :quantity, :unit_id, :unit_name, :currency_id,
6
+ :currency_code, :price
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Cats
2
+ module Core
3
+ class SwapSerializer < ActiveModel::Serializer
4
+ attributes :id, :reference_no, :swapper, :agreement_date, :issued_commodity_id, :issued_commodity_name,
5
+ :issued_quantity, :received_commodity_id, :received_commodity_name, :received_quantity,
6
+ :issued_unit_id, :issued_unit_abbreviation, :received_unit_id, :received_unit_abbreviation
7
+ end
8
+ end
9
+ end
@@ -59,6 +59,85 @@ module Cats
59
59
  end
60
60
  end
61
61
  end
62
+
63
+ # This method generates dispatch plan for a round plan by aggregating the FDP level
64
+ # quantities into woreda level quantity per commodity.
65
+ #
66
+ # Parameters:
67
+ # id => The ID of the round plan for which dispatch plan is to be generated
68
+ #
69
+ def generate(id)
70
+ details = RoundPlanItemDetail.joins(
71
+ beneficiary_round_plan_item: { round_plan_item: :round_plan }
72
+ ).where(
73
+ beneficiary_round_plan_item: { cats_core_round_plan_items: { round_plan_id: id } }
74
+ ).includes(
75
+ beneficiary_round_plan_item: {
76
+ round_plan_item: %i[round_plan region zone woreda fdp]
77
+ },
78
+ round_ration: :commodity_category
79
+ )
80
+
81
+ items = details.each_with_object([]) do |detail, res|
82
+ res << {
83
+ reference_no: nil,
84
+ region: detail.beneficiary_round_plan_item.round_plan_item.region.name,
85
+ zone: detail.beneficiary_round_plan_item.round_plan_item.zone.name,
86
+ woreda: detail.beneficiary_round_plan_item.round_plan_item.woreda.name,
87
+ fdp: detail.beneficiary_round_plan_item.round_plan_item.fdp.name,
88
+ commodity_category: detail.round_ration.commodity_category.name,
89
+ unit_id: detail.round_ration.unit_of_measure_id,
90
+ unit: detail.round_ration.unit_of_measure.abbreviation,
91
+ quantity: detail.quantity,
92
+ source_id: nil,
93
+ destination_id: detail.beneficiary_round_plan_item.round_plan_item.fdp.id,
94
+ commodity_id: nil,
95
+ commodity_status: Cats::Core::Commodity::GOOD
96
+ }
97
+ end
98
+ {
99
+ reference_no: nil,
100
+ dispatchable_id: id,
101
+ dispatchable_type: 'Cats::Core::RoundPlan',
102
+ items: items
103
+ }
104
+ end
105
+
106
+ # This method creates dispatch and dispatch plan items once
107
+ # users fill out additional details such as source and destination
108
+ # for generated dispatch plan items.
109
+ #
110
+ # NOTE: Users still have to go through each plan item and set the
111
+ # reference_no. If the product team comes up with a reference_no
112
+ # generation scheme, then we may use that to avoid this.
113
+ #
114
+ def bulk_create(payload, user)
115
+ plan = Cats::Core::DispatchPlan.new(
116
+ reference_no: payload[:reference_no],
117
+ dispatchable_id: payload[:dispatchable_id],
118
+ dispatchable_type: payload[:dispatchable_type],
119
+ prepared_by: user
120
+ )
121
+ ActiveRecord::Base.transaction do
122
+ plan.save!
123
+
124
+ items = payload[:items].each_with_object([]) do |item, res|
125
+ res << {
126
+ reference_no: item[:reference_no],
127
+ source_id: item[:source_id],
128
+ destination_id: item[:destination_id],
129
+ dispatch_plan_id: plan.id,
130
+ quantity: item[:quantity],
131
+ unit_id: item[:unit_id],
132
+ commodity_id: item[:commodity_id],
133
+ commodity_status: item[:commodity_status],
134
+ status: Cats::Core::DispatchPlanItem::UNAUTHORIZED
135
+ }
136
+ end
137
+ Cats::Core::DispatchPlanItem.insert_all(items, record_timestamps: true)
138
+ end
139
+ plan
140
+ end
62
141
  end
63
142
  end
64
143
  end
data/config/routes.rb CHANGED
@@ -84,7 +84,18 @@ Cats::Core::Engine.routes.draw do
84
84
  post '/routes/bulk_create', controller: :routes, action: :bulk_create
85
85
  resources :routes, except: %i[destroy]
86
86
 
87
+ resources :commodity_donations, except: %i[destroy]
88
+ resources :purchase_orders, except: %i[index destroy]
89
+ resources :cash_donations, except: %i[destroy] do
90
+ member do
91
+ get 'purchase_orders', controller: :purchase_orders, action: :index
92
+ end
93
+ end
94
+ resources :swaps, except: %i[destory]
95
+ resources :loans, except: %i[destory]
96
+
87
97
  post '/dispatch_plans/filter', controller: :dispatch_plans, action: :filter
98
+ post '/dispatch_plans/bulk_create'
88
99
  resources :dispatch_plans do
89
100
  member do
90
101
  get 'items', controller: :dispatch_plan_items, action: :index
@@ -164,6 +175,7 @@ Cats::Core::Engine.routes.draw do
164
175
  post '/round_plans/filter'
165
176
  resources :round_plans, except: %i[index destroy] do
166
177
  member do
178
+ post 'generate_dispatch_plan', controller: :dispatch_plans, action: :generate
167
179
  post 'remove_items'
168
180
  post 'generate_round_needs'
169
181
  post 'approve'
@@ -0,0 +1,29 @@
1
+ class CreateCatsCoreCommodityDonations < ActiveRecord::Migration[6.1]
2
+ def change
3
+ create_table :cats_core_commodity_donations do |t|
4
+ t.string :reference_no, unique: true
5
+ t.string :description
6
+ t.string :shipping_reference
7
+ t.date :donated_on, null: false
8
+ t.references :donor,
9
+ null: false,
10
+ index: { name: 'donor_on_cd_indx' },
11
+ foreign_key: { to_table: :cats_core_donors }
12
+ t.references :commodity_category,
13
+ null: false,
14
+ index: { name: 'cc_on_cd_indx' },
15
+ foreign_key: { to_table: :cats_core_commodity_categories }
16
+ t.references :plan,
17
+ null: true,
18
+ index: { name: 'plan_on_cd_indx' },
19
+ foreign_key: { to_table: :cats_core_plans }
20
+ t.float :quantity, null: false
21
+ t.references :unit,
22
+ null: false,
23
+ index: { name: 'unit_on_cd_indx' },
24
+ foreign_key: { to_table: :cats_core_unit_of_measures }
25
+
26
+ t.timestamps
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,20 @@
1
+ class CreateCatsCoreCashDonations < ActiveRecord::Migration[7.0]
2
+ def change
3
+ create_table :cats_core_cash_donations do |t|
4
+ t.string :reference_no, unique: true
5
+ t.string :description
6
+ t.date :donated_on, null: false
7
+ t.references :donor,
8
+ null: false,
9
+ index: { name: 'donor_on_cad_indx' },
10
+ foreign_key: { to_table: :cats_core_donors }
11
+ t.float :amount, null: false
12
+ t.references :currency,
13
+ null: false,
14
+ index: { name: 'currency_on_cad_indx' },
15
+ foreign_key: { to_table: :cats_core_currencies }
16
+
17
+ t.timestamps
18
+ end
19
+ end
20
+ end
@@ -3,12 +3,6 @@ class CreateCatsCoreGiftCertificates < ActiveRecord::Migration[6.1]
3
3
  create_table :cats_core_gift_certificates do |t|
4
4
  t.string :reference_no, unique: true
5
5
  t.date :gift_date, null: false
6
-
7
- t.references :donation,
8
- null: true,
9
- index: { name: 'gc_on_donation_indx' },
10
- foreign_key: { to_table: :cats_core_donations }
11
-
12
6
  t.string :vessel
13
7
  t.string :port
14
8
  t.string :customs_declaration_no
@@ -20,9 +14,9 @@ class CreateCatsCoreGiftCertificates < ActiveRecord::Migration[6.1]
20
14
  null: false,
21
15
  index: { name: 'gc_on_cc_indx' },
22
16
  foreign_key: { to_table: :cats_core_commodity_categories }
23
- t.references :unit_of_measure,
17
+ t.references :unit,
24
18
  null: false,
25
- index: { name: 'uom_on_gc_indx' },
19
+ index: { name: 'unit_on_gc_indx' },
26
20
  foreign_key: { to_table: :cats_core_unit_of_measures }
27
21
  t.references :destination_warehouse,
28
22
  null: false,
@@ -7,14 +7,18 @@ class CreateCatsCorePurchaseOrders < ActiveRecord::Migration[6.1]
7
7
  t.string :supplier, null: false
8
8
  t.float :quantity, null: false
9
9
  t.string :purchase_type, null: false
10
-
11
- t.references :donation,
10
+ t.float :price, null: false
11
+ t.references :currency,
12
+ null: false,
13
+ index: { name: 'currency_on_po_indx' },
14
+ foreign_key: { to_table: :cats_core_currencies }
15
+ t.references :cash_donation,
12
16
  null: false,
13
- index: { name: 'po_on_donation_indx' },
14
- foreign_key: { to_table: :cats_core_donations }
17
+ index: { name: 'cd_on_po_indx' },
18
+ foreign_key: { to_table: :cats_core_cash_donations }
15
19
  t.references :commodity_category,
16
20
  null: false,
17
- index: { name: 'po_on_cc_indx' },
21
+ index: { name: 'cc_on_po_indx' },
18
22
  foreign_key: { to_table: :cats_core_commodity_categories }
19
23
  t.references :unit,
20
24
  null: false,
@@ -4,6 +4,10 @@ class CreateCatsCoreProjects < ActiveRecord::Migration[7.0]
4
4
  t.string :code, unique: true
5
5
  t.string :description
6
6
  t.references :source, polymorphic: true
7
+ t.references :program,
8
+ null: false,
9
+ index: { name: 'program_on_projects_indx' },
10
+ foreign_key: { to_table: :cats_core_programs }
7
11
  t.integer :year, null: false
8
12
  t.string :implementing_agency, null: false
9
13
 
@@ -0,0 +1,21 @@
1
+ class CreateCatsCoreLoans < ActiveRecord::Migration[7.0]
2
+ def change
3
+ create_table :cats_core_loans do |t|
4
+ t.string :reference_no, unique: true
5
+ t.string :lender, null: false
6
+ t.date :agreement_date, null: false
7
+ t.date :repayment_date
8
+ t.references :commodity_category,
9
+ null: false,
10
+ index: { name: 'cc_on_loan_indx' },
11
+ foreign_key: { to_table: :cats_core_commodity_categories }
12
+ t.float :quantity, null: false
13
+ t.references :unit,
14
+ null: false,
15
+ index: { name: 'unit_on_loan_indx' },
16
+ foreign_key: { to_table: :cats_core_unit_of_measures }
17
+
18
+ t.timestamps
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,29 @@
1
+ class CreateCatsCoreSwaps < ActiveRecord::Migration[7.0]
2
+ def change
3
+ create_table :cats_core_swaps do |t|
4
+ t.string :reference_no, unique: true
5
+ t.string :swapper, null: false
6
+ t.date :agreement_date, null: false
7
+ t.float :issued_quantity, null: false
8
+ t.float :received_quantity, null: false
9
+ t.references :issued_commodity,
10
+ null: false,
11
+ index: { name: 'ic_on_swap_indx' },
12
+ foreign_key: { to_table: :cats_core_commodity_categories }
13
+ t.references :received_commodity,
14
+ null: false,
15
+ index: { name: 'rc_on_swap_indx' },
16
+ foreign_key: { to_table: :cats_core_commodity_categories }
17
+ t.references :issued_unit,
18
+ null: false,
19
+ index: { name: 'iu_on_swap_indx' },
20
+ foreign_key: { to_table: :cats_core_unit_of_measures }
21
+ t.references :received_unit,
22
+ null: false,
23
+ index: { name: 'ru_on_swap_indx' },
24
+ foreign_key: { to_table: :cats_core_unit_of_measures }
25
+
26
+ t.timestamps
27
+ end
28
+ end
29
+ end
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = '1.4.39'.freeze
3
+ VERSION = '1.4.42'.freeze
4
4
  end
5
5
  end
@@ -0,0 +1,10 @@
1
+ FactoryBot.define do
2
+ factory :cash_donation, class: 'Cats::Core::CashDonation' do
3
+ reference_no { FFaker::Name.name }
4
+ description { FFaker::Name.name }
5
+ donated_on { Date.today.prev_week }
6
+ donor
7
+ amount { 10_000 }
8
+ currency
9
+ end
10
+ end
@@ -1,17 +1,13 @@
1
1
  FactoryBot.define do
2
- factory :donation, class: 'Cats::Core::Donation' do
2
+ factory :commodity_donation, class: 'Cats::Core::CommodityDonation' do
3
3
  reference_no { FFaker::Name.name }
4
4
  description { FFaker::Name.name }
5
- donation_type { Cats::Core::Donation::KIND }
6
5
  shipping_reference { FFaker::Name.name }
7
6
  donated_on { Date.today }
8
- agency { 'WFP' }
9
7
  donor
10
8
  plan
11
- amount { 100 }
12
- currency { nil }
9
+ quantity { 100 }
13
10
  commodity_category
14
- unit_of_measure
15
- active { false }
11
+ unit factory: :unit_of_measure
16
12
  end
17
13
  end
@@ -2,10 +2,6 @@ FactoryBot.define do
2
2
  factory :gift_certificate, class: 'Cats::Core::GiftCertificate' do
3
3
  reference_no { FFaker::Name.name }
4
4
  gift_date { Date.today - 1.month }
5
- donation
6
- commodity_category { donation.commodity_category }
7
- unit_of_measure
8
- destination_warehouse factory: :warehouse
9
5
  vessel { FFaker::Name.name }
10
6
  port { FFaker::Name.name }
11
7
  customs_declaration_no { FFaker::Name.name }
@@ -13,8 +9,11 @@ FactoryBot.define do
13
9
  expiry_date { Date.today + 6.month }
14
10
  bill_of_lading_no { FFaker::Name.name }
15
11
  quantity { 1.5 }
16
- estimated_price { 1.5 }
17
- estimated_tax { 1.5 }
12
+ commodity_category
13
+ unit factory: :unit_of_measure
14
+ destination_warehouse factory: :warehouse
15
+ estimated_price { 500 }
16
+ estimated_tax { 200 }
18
17
  currency
19
18
  registration_no { FFaker::Name.name }
20
19
  requested_by { FFaker::Name.name }
@@ -0,0 +1,11 @@
1
+ FactoryBot.define do
2
+ factory :loan, class: 'Cats::Core::Loan' do
3
+ reference_no { FFaker::Name.name }
4
+ lender { FFaker::Name.name }
5
+ agreement_date { Date.today }
6
+ repayment_date { agreement_date.next_month }
7
+ commodity_category
8
+ quantity { 100 }
9
+ unit factory: :unit_of_measure
10
+ end
11
+ end
@@ -2,7 +2,8 @@ FactoryBot.define do
2
2
  factory :project, class: 'Cats::Core::Project' do
3
3
  code { FFaker::Name.name }
4
4
  description { FFaker::Name.name }
5
- source factory: :gift_certificate
5
+ source factory: :commodity_donation
6
+ program
6
7
  year { 2022 }
7
8
  implementing_agency { FFaker::Name.name }
8
9
  end
@@ -6,7 +6,9 @@ FactoryBot.define do
6
6
  supplier { FFaker::Name.name }
7
7
  quantity { 100 }
8
8
  purchase_type { Cats::Core::PurchaseOrder::LOCAL }
9
- donation
9
+ price { 1_000 }
10
+ currency
11
+ cash_donation
10
12
  commodity_category
11
13
  unit factory: :unit_of_measure
12
14
  end
@@ -0,0 +1,13 @@
1
+ FactoryBot.define do
2
+ factory :swap, class: 'Cats::Core::Swap' do
3
+ reference_no { FFaker::Name.name }
4
+ swapper { FFaker::Name.name }
5
+ agreement_date { Date.yesterday }
6
+ issued_commodity factory: :commodity_category
7
+ issued_quantity { 100 }
8
+ issued_unit factory: :unit_of_measure
9
+ received_commodity factory: :commodity_category
10
+ received_quantity { 150 }
11
+ received_unit factory: :unit_of_measure
12
+ end
13
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cats_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.39
4
+ version: 1.4.42
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henock L.
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-09 00:00:00.000000000 Z
11
+ date: 2022-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers
@@ -232,18 +232,22 @@ files:
232
232
  - Rakefile
233
233
  - app/controllers/cats/core/access_controller.rb
234
234
  - app/controllers/cats/core/application_controller.rb
235
+ - app/controllers/cats/core/cash_donations_controller.rb
235
236
  - app/controllers/cats/core/commodities_controller.rb
236
237
  - app/controllers/cats/core/commodity_categories_controller.rb
238
+ - app/controllers/cats/core/commodity_donations_controller.rb
237
239
  - app/controllers/cats/core/currencies_controller.rb
238
240
  - app/controllers/cats/core/dispatch_authorizations_controller.rb
239
241
  - app/controllers/cats/core/dispatch_plan_items_controller.rb
240
242
  - app/controllers/cats/core/dispatch_plans_controller.rb
241
243
  - app/controllers/cats/core/dispatch_transactions_controller.rb
242
244
  - app/controllers/cats/core/dispatches_controller.rb
245
+ - app/controllers/cats/core/loans_controller.rb
243
246
  - app/controllers/cats/core/locations_controller.rb
244
247
  - app/controllers/cats/core/lost_commodities_controller.rb
245
248
  - app/controllers/cats/core/menus_controller.rb
246
249
  - app/controllers/cats/core/notifications_controller.rb
250
+ - app/controllers/cats/core/purchase_orders_controller.rb
247
251
  - app/controllers/cats/core/receipt_authorizations_controller.rb
248
252
  - app/controllers/cats/core/receipt_transactions_controller.rb
249
253
  - app/controllers/cats/core/receipts_controller.rb
@@ -253,6 +257,7 @@ files:
253
257
  - app/controllers/cats/core/spaces_controller.rb
254
258
  - app/controllers/cats/core/stacks_controller.rb
255
259
  - app/controllers/cats/core/stores_controller.rb
260
+ - app/controllers/cats/core/swaps_controller.rb
256
261
  - app/controllers/cats/core/transporters_controller.rb
257
262
  - app/controllers/cats/core/unit_conversions_controller.rb
258
263
  - app/controllers/cats/core/unit_of_measures_controller.rb
@@ -267,8 +272,10 @@ files:
267
272
  - app/models/cats/core/beneficiary_category.rb
268
273
  - app/models/cats/core/beneficiary_plan_item.rb
269
274
  - app/models/cats/core/beneficiary_round_plan_item.rb
275
+ - app/models/cats/core/cash_donation.rb
270
276
  - app/models/cats/core/commodity.rb
271
277
  - app/models/cats/core/commodity_category.rb
278
+ - app/models/cats/core/commodity_donation.rb
272
279
  - app/models/cats/core/commodity_substitution.rb
273
280
  - app/models/cats/core/contract_item.rb
274
281
  - app/models/cats/core/currency.rb
@@ -281,6 +288,7 @@ files:
281
288
  - app/models/cats/core/donor.rb
282
289
  - app/models/cats/core/gift_certificate.rb
283
290
  - app/models/cats/core/hub_authorization.rb
291
+ - app/models/cats/core/loan.rb
284
292
  - app/models/cats/core/location.rb
285
293
  - app/models/cats/core/lost_commodity.rb
286
294
  - app/models/cats/core/menu.rb
@@ -312,6 +320,7 @@ files:
312
320
  - app/models/cats/core/stacking_rule.rb
313
321
  - app/models/cats/core/store.rb
314
322
  - app/models/cats/core/supplier.rb
323
+ - app/models/cats/core/swap.rb
315
324
  - app/models/cats/core/tenderer.rb
316
325
  - app/models/cats/core/transaction.rb
317
326
  - app/models/cats/core/transport_bid.rb
@@ -333,7 +342,9 @@ files:
333
342
  - app/notifications/cats/core/allocation_notification.rb
334
343
  - app/notifications/cats/core/dispatch_notification.rb
335
344
  - app/notifications/cats/core/simple_notification.rb
345
+ - app/serializers/cats/core/cash_donation_serializer.rb
336
346
  - app/serializers/cats/core/commodity_category_serializer.rb
347
+ - app/serializers/cats/core/commodity_donation_serializer.rb
337
348
  - app/serializers/cats/core/commodity_serializer.rb
338
349
  - app/serializers/cats/core/currency_serializer.rb
339
350
  - app/serializers/cats/core/dispatch_authorization_serializer.rb
@@ -341,8 +352,10 @@ files:
341
352
  - app/serializers/cats/core/dispatch_plan_serializer.rb
342
353
  - app/serializers/cats/core/dispatch_serializer.rb
343
354
  - app/serializers/cats/core/dispatch_transaction_serializer.rb
355
+ - app/serializers/cats/core/loan_serializer.rb
344
356
  - app/serializers/cats/core/location_serializer.rb
345
357
  - app/serializers/cats/core/lost_commodity_serializer.rb
358
+ - app/serializers/cats/core/purchase_order_serializer.rb
346
359
  - app/serializers/cats/core/receipt_authorization_serializer.rb
347
360
  - app/serializers/cats/core/receipt_serializer.rb
348
361
  - app/serializers/cats/core/receipt_transaction_serializer.rb
@@ -352,6 +365,7 @@ files:
352
365
  - app/serializers/cats/core/route_serializer.rb
353
366
  - app/serializers/cats/core/stack_serializer.rb
354
367
  - app/serializers/cats/core/store_serializer.rb
368
+ - app/serializers/cats/core/swap_serializer.rb
355
369
  - app/serializers/cats/core/transporter_serializer.rb
356
370
  - app/serializers/cats/core/unit_conversion_serializer.rb
357
371
  - app/serializers/cats/core/unit_of_measure_serializer.rb
@@ -386,7 +400,8 @@ files:
386
400
  - db/migrate/20210717032270_create_cats_core_rations.rb
387
401
  - db/migrate/20210717032290_create_cats_core_beneficiary_plan_items.rb
388
402
  - db/migrate/20210717032295_create_cats_core_plan_item_details.rb
389
- - db/migrate/20210717032330_create_cats_core_donations.rb
403
+ - db/migrate/20210717032330_create_cats_core_commodity_donations.rb
404
+ - db/migrate/20210717032408_create_cats_core_cash_donations.rb
390
405
  - db/migrate/20210717032602_create_cats_core_gift_certificates.rb
391
406
  - db/migrate/20210717032855_create_cats_core_purchase_orders.rb
392
407
  - db/migrate/20210717032927_create_cats_core_projects.rb
@@ -434,6 +449,8 @@ files:
434
449
  - db/migrate/20220506082329_create_cats_core_transport_orders.rb
435
450
  - db/migrate/20220506083042_create_cats_core_transport_order_items.rb
436
451
  - db/migrate/20220511082354_create_cats_core_beneficiaries.rb
452
+ - db/migrate/20220626063501_create_cats_core_loans.rb
453
+ - db/migrate/20220626063757_create_cats_core_swaps.rb
437
454
  - lib/cats/core.rb
438
455
  - lib/cats/core/engine.rb
439
456
  - lib/cats/core/version.rb
@@ -444,8 +461,10 @@ files:
444
461
  - spec/factories/cats/core/beneficiary_categories.rb
445
462
  - spec/factories/cats/core/beneficiary_plan_items.rb
446
463
  - spec/factories/cats/core/beneficiary_round_plan_items.rb
464
+ - spec/factories/cats/core/cash_donations.rb
447
465
  - spec/factories/cats/core/commodities.rb
448
466
  - spec/factories/cats/core/commodity_categories.rb
467
+ - spec/factories/cats/core/commodity_donations.rb
449
468
  - spec/factories/cats/core/commodity_substitutions.rb
450
469
  - spec/factories/cats/core/contract_items.rb
451
470
  - spec/factories/cats/core/currencies.rb
@@ -454,10 +473,10 @@ files:
454
473
  - spec/factories/cats/core/dispatch_plans.rb
455
474
  - spec/factories/cats/core/dispatch_transactions.rb
456
475
  - spec/factories/cats/core/dispatches.rb
457
- - spec/factories/cats/core/donations.rb
458
476
  - spec/factories/cats/core/donors.rb
459
477
  - spec/factories/cats/core/gift_certificates.rb
460
478
  - spec/factories/cats/core/hub_authorizations.rb
479
+ - spec/factories/cats/core/loans.rb
461
480
  - spec/factories/cats/core/locations.rb
462
481
  - spec/factories/cats/core/lost_commodities.rb
463
482
  - spec/factories/cats/core/menu_items.rb
@@ -489,6 +508,7 @@ files:
489
508
  - spec/factories/cats/core/stacks.rb
490
509
  - spec/factories/cats/core/stores.rb
491
510
  - spec/factories/cats/core/suppliers.rb
511
+ - spec/factories/cats/core/swaps.rb
492
512
  - spec/factories/cats/core/tenderers.rb
493
513
  - spec/factories/cats/core/transport_bid_items.rb
494
514
  - spec/factories/cats/core/transport_bids.rb
@@ -513,7 +533,7 @@ metadata:
513
533
  homepage_uri: http://cats.ndrmcapps.org
514
534
  source_code_uri: https://github.com/ndrmc/cats_core
515
535
  changelog_uri: https://github.com/ndrmc/cats_core/CHANGELOG.md
516
- post_install_message:
536
+ post_install_message:
517
537
  rdoc_options: []
518
538
  require_paths:
519
539
  - lib
@@ -529,7 +549,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
529
549
  version: '0'
530
550
  requirements: []
531
551
  rubygems_version: 3.3.7
532
- signing_key:
552
+ signing_key:
533
553
  specification_version: 4
534
554
  summary: Core module for CATS applications
535
555
  test_files: []
@@ -1,36 +0,0 @@
1
- class CreateCatsCoreDonations < ActiveRecord::Migration[6.1]
2
- def change
3
- create_table :cats_core_donations do |t|
4
- t.string :reference_no, unique: true
5
- t.string :description
6
- t.string :donation_type, null: false
7
- t.string :shipping_reference
8
- t.date :donated_on, null: false
9
- t.string :agency, null: false
10
- t.references :donor,
11
- null: false,
12
- index: { name: 'donor_on_donation_indx' },
13
- foreign_key: { to_table: :cats_core_donors }
14
- t.references :plan,
15
- null: true,
16
- index: { name: 'plan_on_donation_indx' },
17
- foreign_key: { to_table: :cats_core_plans }
18
- t.float :amount, null: false
19
- t.references :currency,
20
- null: true,
21
- index: { name: 'currency_on_donation_indx' },
22
- foreign_key: { to_table: :cats_core_currencies }
23
- t.references :commodity_category,
24
- null: true,
25
- index: { name: 'cc_on_donation_indx' },
26
- foreign_key: { to_table: :cats_core_commodity_categories }
27
- t.references :unit_of_measure,
28
- null: true,
29
- index: { name: 'uom_on_donation_indx' },
30
- foreign_key: { to_table: :cats_core_unit_of_measures }
31
- t.boolean :active, null: false, default: false
32
-
33
- t.timestamps
34
- end
35
- end
36
- end