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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cf68527d50707b488472a3aaa759722ce59d59ed171f75cb018a3bfe19421179
4
- data.tar.gz: 2183b2b605d8b73ee8c29c4a8cf6ca6438a72ad2569342fb8da615da9ebd05e7
3
+ metadata.gz: 44499bfd42e79fe95a119690cd54c9adbe2e43a3307f80ae97c5f18f33676818
4
+ data.tar.gz: 8ff508a01a4da75b991c0f1e4da6f4b3cfe15760a62fee0bcaeee4ea37f31e8b
5
5
  SHA512:
6
- metadata.gz: b15751ad2c5557da8aaed254e538ccf0d7bab769b3af085ce3a46c5e0bdbc975c09e8217f1694275976207d5b99d3455d8587bb419a49b85d7153d8718e4924b
7
- data.tar.gz: c4b5d706eb93c2c12e3d5517daec41360c4557e47edc1c6d25cac94bc090dbdba8e24082d5806db026c17f0e41da2f44696be45d61c21049bbf37762875e35af
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 }
@@ -26,6 +26,7 @@ module Cats
26
26
 
27
27
  delegate(:reference_no, to: :plan, prefix: true)
28
28
  delegate(:name, to: :region, prefix: true)
29
+ delegate(:program_code, to: :plan)
29
30
 
30
31
  def request_reference
31
32
  reference_no
@@ -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
@@ -39,6 +39,7 @@ module Cats
39
39
  end
40
40
 
41
41
  authorization.transactions.each(&:commit)
42
+
42
43
  authorization.dispatch.stack
43
44
  authorization
44
45
  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(:round_plan_items).where(round_plan_items: { id: ids })
100
- raise(StandardError, 'Plan items should be from the same plan.') if plans.count > 1
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
- raise(StandardError, 'Items are not from the given round plan.') unless plan_id == plans[0].id
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::RoundPlanItem.delete_by(id: ids)
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' },
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = '1.4.29'.freeze
3
+ VERSION = '1.4.32'.freeze
4
4
  end
5
5
  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.29
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-05-30 00:00:00.000000000 Z
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