cats_core 1.4.31 → 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: ee7760669a69dc6d1df8d3fe4cd79365ac759ab1ac8197e8d4e5020be437df17
4
- data.tar.gz: 780bfaad187ab3c971cc1d073ff50e46702b2eaa46889fe3b2ea372f489751e4
3
+ metadata.gz: 44499bfd42e79fe95a119690cd54c9adbe2e43a3307f80ae97c5f18f33676818
4
+ data.tar.gz: 8ff508a01a4da75b991c0f1e4da6f4b3cfe15760a62fee0bcaeee4ea37f31e8b
5
5
  SHA512:
6
- metadata.gz: e02a405acb7159588c446fdfc5cfd396d539167fef0a7d41df8f2b8ced64894eb2a02f43e1d2e23fd7d84432c50b0d5cda0ab69c8cd051fe784ee8215ddd8364
7
- data.tar.gz: ad68bf4257f469b9c4d5b5a2713d9dc13b908b02d0cfe7430e651332acea306868802250514679879ea432beb84f95c4148fb06b56c69d3ed0db954a42a2e0d2
6
+ metadata.gz: 226ca5049ebb2542a12558e405548a8e72dcdd141085fc1627f08c7e531c13322d5ec4d652ee3df1081d82ff4a8f5cdb7ba01b18286e922189bf10aca675351c
7
+ data.tar.gz: 1558e359924f5260e962096083c98343d590beab1747d6b07ee0fdde47a0b14eb39e86b6a114569371694757fda494c63018f16c3d3f9c5fe12e523aa5462557
@@ -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
@@ -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.31'.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.31
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-31 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