cats_core 1.4.29 → 1.4.32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/cats/core/dispatch.rb +5 -0
- data/app/models/cats/core/plan.rb +2 -0
- data/app/models/cats/core/round_plan.rb +1 -0
- data/app/serializers/cats/core/receipt_authorization_serializer.rb +2 -1
- data/app/serializers/cats/core/round_plan_serializer.rb +2 -1
- data/app/services/cats/core/authorization_service.rb +1 -0
- data/app/services/cats/core/round_plan_service.rb +36 -5
- data/db/migrate/20220107125025_create_cats_core_round_plan_items.rb +1 -1
- data/lib/cats/core/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44499bfd42e79fe95a119690cd54c9adbe2e43a3307f80ae97c5f18f33676818
|
4
|
+
data.tar.gz: 8ff508a01a4da75b991c0f1e4da6f4b3cfe15760a62fee0bcaeee4ea37f31e8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 226ca5049ebb2542a12558e405548a8e72dcdd141085fc1627f08c7e531c13322d5ec4d652ee3df1081d82ff4a8f5cdb7ba01b18286e922189bf10aca675351c
|
7
|
+
data.tar.gz: 1558e359924f5260e962096083c98343d590beab1747d6b07ee0fdde47a0b14eb39e86b6a114569371694757fda494c63018f16c3d3f9c5fe12e523aa5462557
|
@@ -80,6 +80,11 @@ module Cats
|
|
80
80
|
end
|
81
81
|
|
82
82
|
def stack
|
83
|
+
# check if all receipt transactions have been committed and change status
|
84
|
+
# of dispatch to stacked.
|
85
|
+
statuses = receipt_transactions.map(&:status).uniq
|
86
|
+
return unless statuses.length == 1 && statuses[0] == Transaction::COMMITTED
|
87
|
+
|
83
88
|
self.dispatch_status = STACKED
|
84
89
|
save!
|
85
90
|
end
|
@@ -20,6 +20,8 @@ module Cats
|
|
20
20
|
has_many :beneficiary_plan_items, through: :plan_items
|
21
21
|
has_many :plan_item_details, through: :beneficiary_plan_items
|
22
22
|
|
23
|
+
delegate(:code, to: :program, prefix: true)
|
24
|
+
|
23
25
|
validates :reference_no, :year, :status, presence: true
|
24
26
|
validates :total_days, :rounds, presence: true, numericality: { greater_than: 0 }
|
25
27
|
validates :season, presence: true, inclusion: { in: SEASONS }
|
@@ -2,7 +2,8 @@ module Cats
|
|
2
2
|
module Core
|
3
3
|
class ReceiptAuthorizationSerializer < ActiveModel::Serializer
|
4
4
|
attributes :id, :dispatch_id, :dispatch_reference_no, :store_id, :store_name, :quantity, :received_quantity,
|
5
|
-
:remark, :status, :authorized_by_id, :authorizer_full_name, :auth_details
|
5
|
+
:remark, :status, :authorized_by_id, :authorizer_full_name, :auth_details, :plate_no, :driver_name,
|
6
|
+
:dispatch_status
|
6
7
|
end
|
7
8
|
end
|
8
9
|
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
module Cats
|
2
2
|
module Core
|
3
3
|
class RoundPlanSerializer < ActiveModel::Serializer
|
4
|
-
attributes :id, :reference_no, :status, :plan_id, :plan_reference_no, :region_id, :region_name, :rounds
|
4
|
+
attributes :id, :reference_no, :status, :plan_id, :plan_reference_no, :region_id, :region_name, :rounds,
|
5
|
+
:program_code
|
5
6
|
end
|
6
7
|
end
|
7
8
|
end
|
@@ -87,8 +87,18 @@ module Cats
|
|
87
87
|
round_plan
|
88
88
|
end
|
89
89
|
|
90
|
+
# This method deletes beneficiary round plan items based on the selection of the
|
91
|
+
# user in a given round.
|
92
|
+
#
|
93
|
+
# Params:
|
94
|
+
# plan_id => The id of the round plan.
|
95
|
+
# ids => A list of beneficiary round plan item ids to delete.
|
96
|
+
#
|
97
|
+
# When deleting the selected beneficiary round plan items, if the corresponding
|
98
|
+
# round plan item becomes empty, then it too should be deleted.
|
99
|
+
#
|
90
100
|
def remove_items(plan_id, ids)
|
91
|
-
raise(StandardError, 'No plan items specified.') if ids.count.zero?
|
101
|
+
raise(StandardError, 'No beneficiary plan items specified.') if ids.count.zero?
|
92
102
|
|
93
103
|
begin
|
94
104
|
plan = Cats::Core::RoundPlan.find(plan_id)
|
@@ -96,12 +106,33 @@ module Cats
|
|
96
106
|
raise(StandardError, 'Round plan not found.') unless plan
|
97
107
|
end
|
98
108
|
|
99
|
-
plans = Cats::Core::RoundPlan.includes(:
|
100
|
-
|
109
|
+
plans = Cats::Core::RoundPlan.includes(:beneficiary_round_plan_items)
|
110
|
+
.where(beneficiary_round_plan_items: { id: ids })
|
111
|
+
raise(StandardError, 'Round plan items should be from the same plan.') if plans.count > 1
|
101
112
|
|
102
|
-
|
113
|
+
unless plans.count.positive? && plan_id == plans[0].id
|
114
|
+
raise(StandardError, 'Round plan items are not from the given round plan.')
|
115
|
+
end
|
116
|
+
|
117
|
+
to_delete = Cats::Core::BeneficiaryRoundPlanItem.where(id: ids)
|
118
|
+
keys = to_delete.map(&:round_plan_item_id).uniq
|
119
|
+
|
120
|
+
item_counts = Cats::Core::BeneficiaryRoundPlanItem.where(round_plan_item_id: keys)
|
121
|
+
.group(:round_plan_item_id).count
|
122
|
+
|
123
|
+
delete_hash = {}
|
124
|
+
keys.each { |k| delete_hash[k] = [] }
|
125
|
+
to_delete.each { |td| delete_hash[td.round_plan_item_id] << td.id }
|
126
|
+
|
127
|
+
parent_ids = []
|
128
|
+
child_ids = []
|
129
|
+
delete_hash.each_key do |key|
|
130
|
+
child_ids += delete_hash[key]
|
131
|
+
parent_ids << key if delete_hash[key].count == item_counts[key]
|
132
|
+
end
|
103
133
|
|
104
|
-
Cats::Core::
|
134
|
+
Cats::Core::BeneficiaryRoundPlanItem.delete_by(id: child_ids) if child_ids.count.positive?
|
135
|
+
Cats::Core::RoundPlanItem.delete_by(id: parent_ids) if parent_ids.count.positive?
|
105
136
|
plan
|
106
137
|
end
|
107
138
|
|
@@ -4,7 +4,7 @@ class CreateCatsCoreRoundPlanItems < ActiveRecord::Migration[6.1]
|
|
4
4
|
t.references :round_plan,
|
5
5
|
null: false,
|
6
6
|
index: { name: 'mp_on_mpi_indx' },
|
7
|
-
foreign_key: { to_table: :cats_core_round_plans }
|
7
|
+
foreign_key: { to_table: :cats_core_round_plans, on_delete: :cascade }
|
8
8
|
t.references :region,
|
9
9
|
null: false,
|
10
10
|
index: { name: 'region_on_round_plan_items_indx' },
|
data/lib/cats/core/version.rb
CHANGED
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.
|
4
|
+
version: 1.4.32
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henock L.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-06-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_model_serializers
|