cats_core 1.5.27 → 1.5.29

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2865fcf1ffc5a821dd2011d92cb64aa062ff61441c82c1c510af16035827f082
4
- data.tar.gz: 8e5c5bc4826e22b2e7cdf6aa4cd2b29466085e7a4ce296121b074f59a71adc37
3
+ metadata.gz: 3871baf3450e7366757ebaa26bbf157b8bed3d9445f8cedd32a384be3c085a75
4
+ data.tar.gz: bade4250d1176e8ebc8bc99136dafcbab78761b8d2d8dab93d004f3eabbc49d4
5
5
  SHA512:
6
- metadata.gz: a6c116447db30f695bad8135801888cd90878bc53e84e284bf6f648e4ac56e469ea9f8abaea4c8120ce04220d7e8b83a8cb8fdd529a37b0b3308c70f48ff622f
7
- data.tar.gz: 5393dbaab893533aa60034deab2ce0e3827dad922f70f254ebad50c7f411e77dca0bad8e9daf3441b15ed2bf4f0d92c61e79de784eabb94bfd76244b6cfd92f0
6
+ metadata.gz: 87458b788af5a370a0fdc04ef9214ae4b2abefdb5c4a94e472bbccc71281c9d464a00fa5f6046a722946aaf9a30cbacbe5fe370ac3a236e88ae6705fe7a3fc89
7
+ data.tar.gz: 3e618ea3300eb3b742668ccd3e694672545d9bef499a4bd46b4221505cc6fb396c0bee19dda5d0f65788fc50e70803cb167337f828013e55331b946fcea6b185
@@ -14,6 +14,21 @@ module Cats
14
14
  render json: {success: true, data: serialize(plans)}
15
15
  end
16
16
 
17
+ def plans_for_location
18
+ if params[:location_type] == "source"
19
+ plans = DispatchPlan.includes([:dispatchable]).joins(:dispatch_plan_items)
20
+ .where(status: Cats::Core::DispatchPlan::APPROVED,
21
+ upstream: false,
22
+ dispatch_plan_items: {source_id: params[:location_id]}).uniq
23
+ elsif params[:location_type] == "destination"
24
+ plans = DispatchPlan.includes([:dispatchable]).joins(:dispatch_plan_items)
25
+ .where(status: Cats::Core::DispatchPlan::APPROVED,
26
+ upstream: false,
27
+ dispatch_plan_items: {destination_id: params[:location_id]}).uniq
28
+ end
29
+ render json: {success: true, data: serialize(plans)}
30
+ end
31
+
17
32
  def filter
18
33
  query = DispatchPlan.ransack(params[:q])
19
34
  render json: {success: true, data: serialize(query.result)}
@@ -61,7 +76,7 @@ module Cats
61
76
  :dispatchable_type,
62
77
  items: %i[
63
78
  reference_no region zone woreda fdp commodity_category unit_id unit quantity source_id destination_id
64
- commodity_id commodity_status
79
+ commodity_id commodity_status beneficiaries
65
80
  ]
66
81
  )
67
82
  end
@@ -104,6 +104,7 @@ module Cats
104
104
  %w[
105
105
  commodity_id
106
106
  commodity_status
107
+ reference_no
107
108
  destination_id
108
109
  dispatch_plan_id
109
110
  quantity
@@ -7,6 +7,7 @@ module Cats
7
7
  belongs_to :destination, class_name: "Cats::Core::Stack"
8
8
 
9
9
  validates :transaction_date, presence: true
10
+ validates :receipt_number, uniqueness: true
10
11
  validates :quantity, presence: true, numericality: {greater_than: 0}
11
12
  validates :receipt_number, presence: true
12
13
  validate :validate_receipt, :validate_quantity
@@ -9,7 +9,7 @@ module Cats
9
9
  delegate(:code, to: :destination, prefix: true)
10
10
  delegate(:abbreviation, to: :unit, prefix: true)
11
11
 
12
- validate :validate_commodity
12
+ validate :validate_commodity, :validate_quantity
13
13
 
14
14
  def validate_commodity
15
15
  return unless source && destination
@@ -19,14 +19,30 @@ module Cats
19
19
  errors.add(:commodity, "batch number should be the same.")
20
20
  end
21
21
 
22
+ def validate_quantity
23
+ return unless quantity.present? && source.present?
24
+
25
+ dispatched = StackTransaction.where(source: source, status: DRAFT)
26
+ total_dispatched = dispatched.reduce(0) do |_sum, rec|
27
+ UnitConversion.convert(source.unit, Cats::Core::UnitOfMeasure.find(rec.unit_id), rec.quantity)
28
+ end
29
+ available = source.quantity - total_dispatched
30
+ available += UnitConversion.convert(source.unit, unit, quantity_was) if quantity_was
31
+
32
+ converted_quantity = UnitConversion.convert(source.unit, Cats::Core::UnitOfMeasure.find(unit_id), quantity)
33
+
34
+ errors.add(:quantity, "total is higher than source quantity (Max = #{available}).") if converted_quantity > available
35
+ end
36
+
22
37
  def commit
23
38
  StackTransaction.transaction do
39
+ self.status = COMMITTED
40
+ save!
24
41
  source.quantity -= UnitConversion.convert(unit, source.unit, quantity)
25
42
  source.save!
26
43
  destination.quantity += UnitConversion.convert(unit, destination.unit, quantity)
44
+ destination.stack_status = Stack::ALLOCATED if destination.stack_status == Stack::RESERVED
27
45
  destination.save!
28
- self.status = COMMITTED
29
- save!
30
46
  end
31
47
  end
32
48
  end
@@ -8,6 +8,7 @@ module Cats
8
8
  def message
9
9
  authorization = params[:receipt_authorization]
10
10
  dispatch = authorization.dispatch
11
+ ref_no = dispatch.dispatch_plan_item.dispatch_plan.upstream ? dispatch.dispatch_transactions[0].reference_no : dispatch.reference_no
11
12
  commodity = dispatch.dispatch_plan_item.commodity
12
13
  title = "Receipt Authorization Notification - #{commodity.name}"
13
14
  date = Date.today
@@ -15,7 +16,7 @@ module Cats
15
16
  body = <<~BODY
16
17
  Commodity with the following details has been dispatched to you:
17
18
  Authorization no. = #{dispatch.dispatch_plan_item.reference_no}
18
- Dispatch Ref. = #{dispatch.reference_no}
19
+ Dispatch Ref. = #{ref_no}
19
20
  Batch No. = #{commodity.batch_no}
20
21
  Commodity = #{commodity.name}
21
22
  Quantity = #{authorization.quantity}
@@ -4,7 +4,7 @@ module Cats
4
4
  attributes :id, :reference_no, :dispatch_plan_id, :plan_reference_no, :source_id, :source_name, :destination_id,
5
5
  :destination_name, :quantity, :source_location_type, :destination_location_type, :commodity_status,
6
6
  :status, :commodity_id, :commodity_name, :commodity_batch_no, :unit_abbreviation,
7
- :commodity_shipping_reference, :unit_id, :woreda, :zone, :region
7
+ :commodity_shipping_reference, :unit_id, :woreda, :zone, :region, :beneficiaries
8
8
  end
9
9
  end
10
10
  end
@@ -87,6 +87,7 @@ module Cats
87
87
  woreda: detail.beneficiary_round_plan_item.round_plan_item.woreda.name,
88
88
  fdp: detail.beneficiary_round_plan_item.round_plan_item.fdp.name,
89
89
  commodity_category: detail.round_ration.commodity_category.name,
90
+ beneficiaries: detail.beneficiary_round_plan_item.beneficiaries,
90
91
  unit_id: detail.unit_id,
91
92
  unit: detail.unit.abbreviation,
92
93
  quantity: detail.quantity,
@@ -132,6 +133,7 @@ module Cats
132
133
  unit_id: item[:unit_id],
133
134
  commodity_id: item[:commodity_id],
134
135
  commodity_status: item[:commodity_status],
136
+ beneficiaries: item[:beneficiaries],
135
137
  status: Cats::Core::DispatchPlanItem::UNAUTHORIZED
136
138
  }
137
139
  end
data/config/routes.rb CHANGED
@@ -100,6 +100,8 @@ Cats::Core::Engine.routes.draw do
100
100
  resources :loans, except: %i[destory]
101
101
 
102
102
  post "/dispatch_plans/filter", controller: :dispatch_plans, action: :filter
103
+ post "/dispatch_plans/filter_by_location", controller: :dispatch_plans,
104
+ action: :plans_for_location, as: :filter_plan_by_location
103
105
  post "/dispatch_plans/bulk_create"
104
106
  resources :dispatch_plans do
105
107
  member do
@@ -0,0 +1,5 @@
1
+ class AddBeneficiariesToCatsCoreDispatchPlanItems < ActiveRecord::Migration[7.0]
2
+ def change
3
+ add_column :cats_core_dispatch_plan_items, :beneficiaries, :integer
4
+ end
5
+ end
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = "1.5.27".freeze
3
+ VERSION = "1.5.29".freeze
4
4
  end
5
5
  end
@@ -1,14 +1,17 @@
1
1
  FactoryBot.define do
2
2
  factory :stack_transaction, class: "Cats::Core::StackTransaction" do
3
3
  transient do
4
- unit_of_measure { create(:unit_of_measure) }
5
- commodity { create(:commodity, unit: unit_of_measure) }
4
+ unit_of_measure_1 { create(:unit_of_measure) }
5
+ unit_of_measure_2 { create(:unit_of_measure) }
6
+ commodity { create(:commodity, unit: unit_of_measure_1) }
7
+ unit_conversion_1 { create(:unit_conversion, from: unit_of_measure_1, to: unit_of_measure_2) }
8
+ unit_conversion_2 { create(:unit_conversion, from: unit_of_measure_2, to: unit_of_measure_1) }
6
9
  end
7
- source { association :stack, commodity: commodity }
8
- destination { association :stack, commodity: commodity }
10
+ source { association :stack, commodity: commodity, unit: unit_of_measure_1 }
11
+ destination { association :stack, commodity: commodity, unit: unit_of_measure_2 }
9
12
  transaction_date { Date.today }
10
13
  quantity { 25 }
11
- unit { unit_of_measure }
14
+ unit { unit_of_measure_1 }
12
15
  status { Cats::Core::Transaction::DRAFT }
13
16
  end
14
17
  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.5.27
4
+ version: 1.5.29
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henock L.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-30 00:00:00.000000000 Z
11
+ date: 2024-01-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers
@@ -531,6 +531,7 @@ files:
531
531
  - db/migrate/20221024081141_add_reference_no_to_cats_core_dispatch_transactions.rb
532
532
  - db/migrate/20230102064317_add_receipt_number_to_cats_core_receipt_transactions.rb
533
533
  - db/migrate/20231129071520_create_cats_core_inventory_adjustments.rb
534
+ - db/migrate/20231227114358_add_beneficiaries_to_cats_core_dispatch_plan_items.rb
534
535
  - lib/cats/core.rb
535
536
  - lib/cats/core/engine.rb
536
537
  - lib/cats/core/version.rb