cats_core 1.5.28 → 1.5.30
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/cats/core/dispatch_plans_controller.rb +1 -1
- data/app/models/cats/core/dispatch_plan_item.rb +1 -0
- data/app/models/cats/core/receipt_transaction.rb +1 -0
- data/app/models/cats/core/stack_transaction.rb +19 -3
- data/app/models/cats/core/transport_contract.rb +5 -0
- data/app/models/cats/core/transport_order.rb +6 -1
- data/app/models/cats/core/transport_order_item.rb +11 -2
- data/app/notifications/cats/core/receipt_authorization_notification.rb +2 -1
- data/app/serializers/cats/core/dispatch_plan_item_serializer.rb +1 -1
- data/app/services/cats/core/dispatch_plan_service.rb +2 -0
- data/db/migrate/20231227114358_add_beneficiaries_to_cats_core_dispatch_plan_items.rb +5 -0
- data/db/migrate/20240125051557_add_status_unit_and_quantity_to_transport_order_item.rb +18 -0
- data/db/migrate/20240125051632_add_status_to_transport_order.rb +6 -0
- data/db/migrate/20240125051644_add_status_to_contract.rb +5 -0
- data/lib/cats/core/version.rb +1 -1
- data/spec/factories/cats/core/stack_transactions.rb +8 -5
- data/spec/factories/cats/core/transport_contracts.rb +1 -0
- data/spec/factories/cats/core/transport_order_items.rb +4 -0
- data/spec/factories/cats/core/transport_orders.rb +2 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03b358ca3dc8a8908dc00309ca843ab82e9703f9224c5d726cf1762034bf76ed
|
4
|
+
data.tar.gz: 3e0da8d5c95a1bd32c90f76d78bd17bd3b70e2c5466916945b96d6292c3ae3f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb22c2473633590d0c8f760b2a8dd178d19646e6ff9193b79f7536c0bbe9e3f2c16e3a860b9de66938d13279a1bcd0a3855b9593ff48ac5662ce10c9bc071c6c
|
7
|
+
data.tar.gz: 73fe0f22b150696c145d28eb4343145f033643ec7259f6865f6b725e2c052880e1905c28b78ea860858da58bb5d0753b96a16fa358e9a7cd2319b3376de27f4f
|
@@ -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
|
@@ -1,12 +1,17 @@
|
|
1
1
|
module Cats
|
2
2
|
module Core
|
3
3
|
class TransportContract < ApplicationRecord
|
4
|
+
ACTIVE = "Active".freeze
|
5
|
+
CANCELLED = "Cancelled".freeze
|
6
|
+
CONTRACT_STATUSES = [ACTIVE, CANCELLED].freeze
|
7
|
+
|
4
8
|
belongs_to :transporter
|
5
9
|
belongs_to :transport_bid
|
6
10
|
has_many :contract_items
|
7
11
|
|
8
12
|
validates :contract_no, presence: true, uniqueness: true
|
9
13
|
validates :contract_date, :expires_on, presence: true
|
14
|
+
validates :status, presence: true, inclusion: {in: CONTRACT_STATUSES}
|
10
15
|
|
11
16
|
delegate(:name, to: :transporter, prefix: true)
|
12
17
|
delegate(:reference_no, to: :transport_bid, prefix: :bid)
|
@@ -5,6 +5,10 @@ module Cats
|
|
5
5
|
APPROVED = "Approved".freeze
|
6
6
|
STATUSES = [DRAFT, APPROVED].freeze
|
7
7
|
|
8
|
+
ACTIVE = "Active".freeze
|
9
|
+
CANCELLED = "Cancelled".freeze
|
10
|
+
ORDER_STATUSES = [ACTIVE, CANCELLED].freeze
|
11
|
+
|
8
12
|
belongs_to :transport_requisition
|
9
13
|
belongs_to :prepared_by, class_name: "Cats::Core::User"
|
10
14
|
belongs_to :approved_by, class_name: "Cats::Core::User", optional: true
|
@@ -12,7 +16,8 @@ module Cats
|
|
12
16
|
has_many :transport_order_items
|
13
17
|
|
14
18
|
validates :status, presence: true, inclusion: {in: STATUSES}
|
15
|
-
validates :
|
19
|
+
validates :order_status, presence: true, inclusion: {in: ORDER_STATUSES}
|
20
|
+
validates :order_date, :order_no, presence: true
|
16
21
|
validate :validate_against_requisition, :validate_status
|
17
22
|
|
18
23
|
delegate(:full_name, to: :prepared_by, prefix: true)
|
@@ -1,18 +1,27 @@
|
|
1
1
|
module Cats
|
2
2
|
module Core
|
3
3
|
class TransportOrderItem < ApplicationRecord
|
4
|
+
ACTIVE = "Active".freeze
|
5
|
+
CANCELLED = "Cancelled".freeze
|
6
|
+
|
7
|
+
ORDER_ITEM_STATUSES = [ACTIVE, CANCELLED].freeze
|
4
8
|
belongs_to :transport_order
|
5
9
|
belongs_to :transporter
|
6
10
|
belongs_to :transport_requisition_item
|
7
11
|
belongs_to :transport_contract, optional: true
|
12
|
+
belongs_to :unit, class_name: "Cats::Core::UnitOfMeasure"
|
13
|
+
belongs_to :route
|
8
14
|
|
9
|
-
validates :valid_for, presence: true
|
15
|
+
validates :valid_for, :quantity, presence: true
|
10
16
|
validates :valid_for, numericality: {greater_than: 0}
|
17
|
+
validates :status, presence: true, inclusion: {in: ORDER_ITEM_STATUSES}
|
11
18
|
validates :transport_requisition_item_id, uniqueness: true
|
12
19
|
validate :validate_requisition
|
13
20
|
|
14
21
|
delegate(:name, to: :transporter, prefix: true)
|
15
|
-
delegate(:
|
22
|
+
delegate(:name, to: :route, prefix: true)
|
23
|
+
delegate(:abbreviation, to: :unit, prefix: true)
|
24
|
+
delegate(:contract_no, to: :transport_contract, prefix: false, allow_nil: true)
|
16
25
|
|
17
26
|
def validate_requisition
|
18
27
|
return unless transport_requisition_item
|
@@ -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. = #{
|
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
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class AddStatusUnitAndQuantityToTransportOrderItem < ActiveRecord::Migration[7.0]
|
2
|
+
def change
|
3
|
+
add_column :cats_core_transport_order_items, :unit_id, :integer
|
4
|
+
add_foreign_key :cats_core_transport_order_items,
|
5
|
+
:cats_core_unit_of_measures,
|
6
|
+
column: :unit_id, null: false,
|
7
|
+
index: {name: "unit_on_toi_indx"}
|
8
|
+
add_column :cats_core_transport_order_items, :route_id, :integer
|
9
|
+
add_foreign_key :cats_core_transport_order_items,
|
10
|
+
:cats_core_routes,
|
11
|
+
column: :route_id, null: false,
|
12
|
+
index: {name: "route_on_toi_indx"}
|
13
|
+
add_column :cats_core_transport_order_items, :quantity, :float, null: false
|
14
|
+
add_column :cats_core_transport_order_items, :status, :string, null: false
|
15
|
+
remove_index :cats_core_transport_order_items, :transport_requisition_item_id,
|
16
|
+
name: "tri_on_toi_uniq_indx"
|
17
|
+
end
|
18
|
+
end
|
data/lib/cats/core/version.rb
CHANGED
@@ -1,14 +1,17 @@
|
|
1
1
|
FactoryBot.define do
|
2
2
|
factory :stack_transaction, class: "Cats::Core::StackTransaction" do
|
3
3
|
transient do
|
4
|
-
|
5
|
-
|
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 {
|
14
|
+
unit { unit_of_measure_1 }
|
12
15
|
status { Cats::Core::Transaction::DRAFT }
|
13
16
|
end
|
14
17
|
end
|
@@ -5,5 +5,9 @@ FactoryBot.define do
|
|
5
5
|
transport_contract
|
6
6
|
transport_requisition_item { transport_order.transport_requisition.transport_requisition_items.first }
|
7
7
|
valid_for { 10 }
|
8
|
+
quantity { 12 }
|
9
|
+
status { Cats::Core::TransportOrderItem::ACTIVE }
|
10
|
+
unit factory: :unit_of_measure
|
11
|
+
route
|
8
12
|
end
|
9
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.5.
|
4
|
+
version: 1.5.30
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henock L.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_model_serializers
|
@@ -531,6 +531,10 @@ 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
|
535
|
+
- db/migrate/20240125051557_add_status_unit_and_quantity_to_transport_order_item.rb
|
536
|
+
- db/migrate/20240125051632_add_status_to_transport_order.rb
|
537
|
+
- db/migrate/20240125051644_add_status_to_contract.rb
|
534
538
|
- lib/cats/core.rb
|
535
539
|
- lib/cats/core/engine.rb
|
536
540
|
- lib/cats/core/version.rb
|