cats_core 1.5.26 → 1.5.28

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: 1c8be1ba8f56a842d768b82e55d12671dac81db7ca6d7c720bec9fd6743f96fd
4
- data.tar.gz: 58d6e641497d4419d813b8bde9937215143038cfb9cf1d4a54cdf53e89f0a438
3
+ metadata.gz: 9f4c5959fbfc273f8809d25ec667efe26c657ecaf5ffee395db78d7a5082344d
4
+ data.tar.gz: f9e7f7f16def88dbd3f228dece31bdfce72b1d546899a93671a345994aaf23b2
5
5
  SHA512:
6
- metadata.gz: d74325e8d1a2ec67aac8c40098fb71ca67336b4d115847cecabec7d577c1394c75689cadbed0c832697806a011e369d8368aefcf4ec49db39b133823c6503ac7
7
- data.tar.gz: e10a0b3750fdba8f67a2404b9d579739f00b198042798610313a5ddd20a27c7743c5d4b3b99826acf988f91c68133603415c40749e7f79eafeae1759cfda56dd
6
+ metadata.gz: a965719b330ddaca566572abe5c8a5aec87214f53cfd465c2199477a7e9d5d1b7d43cd07748e2ad0f27a0a6eebc9642d864fccd5fa91dfeb2571137494fe0749
7
+ data.tar.gz: 0c2d16529bdee5a560c756e3feeb0b37924bfe531e17771b721ee242024938ed0ca0d52f28bf09899c45a198b5c16ad058e1bd17eaec6747367246f6aaaf63db
@@ -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)}
@@ -51,7 +66,7 @@ module Cats
51
66
  private
52
67
 
53
68
  def model_params
54
- params.require(:payload).permit(:reference_no, :dispatchable_id, :dispatchable_type)
69
+ params.require(:payload).permit(:reference_no, :dispatchable_id, :dispatchable_type, :status)
55
70
  end
56
71
 
57
72
  def bulk_create_params
@@ -91,7 +91,7 @@ module Cats
91
91
 
92
92
  def model_params
93
93
  params.require(:payload).permit(:reference_no, :dispatch_plan_item_id, :transporter_id, :plate_no, :unit_id,
94
- :driver_name, :driver_phone, :remark)
94
+ :driver_name, :driver_phone, :remark, :dispatch_status)
95
95
  end
96
96
 
97
97
  def start_with_pin_params
@@ -0,0 +1,24 @@
1
+ module Cats
2
+ module Core
3
+ class InventoryAdjustmentsController < ApplicationController
4
+ include Common
5
+
6
+ def filter
7
+ query = InventoryAdjustment.ransack(params[:q])
8
+ render json: {success: true, data: serialize(query.result)}
9
+ end
10
+
11
+ def commit
12
+ adjustment = InventoryAdjustment.find(params[:id])
13
+ adjustment.commit
14
+ render json: {success: true, data: serialize(adjustment)}
15
+ end
16
+
17
+ private
18
+
19
+ def model_params
20
+ params.require(:payload).permit(:stack_id, :reference_no, :reason_for_adjustment, :adjustment_date, :quantity, :unit_id)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -5,14 +5,13 @@ module Cats
5
5
 
6
6
  def index
7
7
  super do
8
- StackTransaction.joins(source: :store)
9
- .includes(:unit)
8
+ StackTransaction.includes(:unit, :destination, source: :store)
10
9
  .where(cats_core_stacks: {cats_core_stores: {warehouse_id: params[:id]}})
11
10
  end
12
11
  end
13
12
 
14
13
  def filter
15
- query = StackTransaction.ransack(params[:q])
14
+ query = StackTransaction.includes(:source, :destination, :unit).ransack(params[:q])
16
15
  render json: {success: true, data: serialize(query.result)}
17
16
  end
18
17
 
@@ -30,6 +30,18 @@ module Cats
30
30
  delegate(:abbreviation, to: :unit, prefix: true)
31
31
  delegate(:shipping_reference, to: :commodity, prefix: true)
32
32
 
33
+ def woreda
34
+ destination.location_type == "Fdp" ? destination.parent.name : ""
35
+ end
36
+
37
+ def zone
38
+ destination.location_type == "Fdp" ? destination.parent.parent.name : ""
39
+ end
40
+
41
+ def region
42
+ destination.location_type == "Fdp" ? destination.parent.parent.parent.name : ""
43
+ end
44
+
33
45
  # Authorize a dispatch plan item if it contains authorization entries
34
46
  # under it. A dispatch plan item can be authorized by source hub, or
35
47
  # source and destination hub. Hence the status can be `SOURCE_AUTHORIZED`,
@@ -5,6 +5,7 @@ module Cats
5
5
 
6
6
  belongs_to :source, class_name: "Cats::Core::Stack"
7
7
  belongs_to :dispatch_authorization
8
+ validates :reference_no, presence: true, uniqueness: true
8
9
 
9
10
  validates :source_id, uniqueness: {scope: :dispatch_authorization_id}
10
11
  validate :validate_dispatch
@@ -0,0 +1,30 @@
1
+ module Cats
2
+ module Core
3
+ class InventoryAdjustment < ApplicationRecord
4
+ # adjustment statuses
5
+ DRAFT = "Draft".freeze
6
+ COMMITTED = "Committed".freeze
7
+ STATUSES = [DRAFT, COMMITTED].freeze
8
+
9
+ belongs_to :stack
10
+ belongs_to :unit, class_name: "UnitOfMeasure"
11
+
12
+ validates :reference_no, presence: true, uniqueness: true
13
+ validates :quantity, :reason_for_adjustment, :adjustment_date, presence: true
14
+ validates :status, inclusion: {in: STATUSES}
15
+
16
+ delegate(:abbreviation, to: :unit, prefix: true)
17
+ delegate(:code, to: :stack, prefix: true)
18
+
19
+ def commit
20
+ adjusted_quantity = UnitConversion.convert(stack.unit, Cats::Core::UnitOfMeasure.find(unit_id), quantity)
21
+
22
+ stack.quantity += adjusted_quantity
23
+ stack.save
24
+
25
+ self.status = COMMITTED
26
+ save
27
+ end
28
+ end
29
+ end
30
+ end
@@ -9,7 +9,7 @@ module Cats
9
9
  validates :commodity_status, presence: true, inclusion: {in: Commodity::COMMODITY_STATUSES}
10
10
  validates :commodity_grade, inclusion: {in: Commodity::COMMODITY_GRADES}, allow_nil: true
11
11
  validates :quantity, presence: true, numericality: {greater_than: 0}
12
- # validates :reference_no, presence: true
12
+ validates :reference_no, presence: true, uniqueness: true
13
13
  validate :validate_quantity
14
14
 
15
15
  delegate(:abbreviation, to: :unit, prefix: true)
@@ -5,18 +5,11 @@ module Cats
5
5
  belongs_to :destination, class_name: "Cats::Core::Stack"
6
6
  belongs_to :unit, class_name: "Cats::Core::UnitOfMeasure"
7
7
 
8
- validate :validate_commodity
9
-
10
- def validate_quantity
11
- return unless quantity.present? && source.present?
12
-
13
- dispatched = StackTransaction.where(source: source, status: DRAFT).sum(:quantity)
8
+ delegate(:code, to: :source, prefix: true)
9
+ delegate(:code, to: :destination, prefix: true)
10
+ delegate(:abbreviation, to: :unit, prefix: true)
14
11
 
15
- available = source.quantity - dispatched
16
- available += quantity_was if quantity_was
17
-
18
- errors.add(:quantity, "total is higher than source quantity (Max = #{available}).") if quantity > available
19
- end
12
+ validate :validate_commodity
20
13
 
21
14
  def validate_commodity
22
15
  return unless source && destination
@@ -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
7
+ :commodity_shipping_reference, :unit_id, :woreda, :zone, :region
8
8
  end
9
9
  end
10
10
  end
@@ -0,0 +1,8 @@
1
+ module Cats
2
+ module Core
3
+ class InventoryAdjustmentSerializer < ActiveModel::Serializer
4
+ attributes :id, :unit_id, :unit_abbreviation, :reference_no, :quantity, :reason_for_adjustment,
5
+ :adjustment_date, :status, :stack_id, :stack_code
6
+ end
7
+ end
8
+ end
@@ -1,7 +1,8 @@
1
1
  module Cats
2
2
  module Core
3
3
  class StackTransactionSerializer < ActiveModel::Serializer
4
- attributes :id, :source_id, :destination_id, :quantity, :transaction_date, :status, :unit_id, :unit_abbreviation
4
+ attributes :id, :source_id, :source_code, :destination_id, :destination_code, :unit_id,
5
+ :unit_abbreviation, :transaction_date, :quantity, :status
5
6
  end
6
7
  end
7
8
  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
@@ -195,7 +197,7 @@ Cats::Core::Engine.routes.draw do
195
197
  resources :receipt_transactions, except: %i[index new edit destroy]
196
198
  resources :stack_transactions, except: %i[index new edit destroy] do
197
199
  member do
198
- post "commit"
200
+ post "commit", controller: :stack_transactions, action: :commit
199
201
  end
200
202
  end
201
203
  resources :lost_commodities, except: %i[index destroy]
@@ -233,4 +235,12 @@ Cats::Core::Engine.routes.draw do
233
235
  end
234
236
  end
235
237
  post "/stores/filter", controller: :stores, action: :filter
238
+ post 'stack_transactions/filter', controller: :stack_transactions, action: :filter
239
+ resources :stack_transactions, only: %i[index create update]
240
+ post 'inventory_adjustments/filter', controller: :inventory_adjustments, action: :filter
241
+ resources :inventory_adjustments, only: %i[index create update] do
242
+ member do
243
+ post "commit", controller: :inventory_adjustments, action: :commit
244
+ end
245
+ end
236
246
  end
@@ -0,0 +1,21 @@
1
+ class CreateCatsCoreInventoryAdjustments < ActiveRecord::Migration[7.0]
2
+ def change
3
+ create_table :cats_core_inventory_adjustments do |t|
4
+ t.string :reference_no
5
+ t.float :quantity
6
+ t.string :reason_for_adjustment
7
+ t.date :adjustment_date, null: false
8
+ t.string :status, null: false, default: "Draft"
9
+ t.references :unit,
10
+ null: false,
11
+ index: {name: "unit_on_inventory_indx"},
12
+ foreign_key: {to_table: :cats_core_unit_of_measures}
13
+ t.references :stack,
14
+ null: false,
15
+ index: {name: "stack_on_inventory_indx"},
16
+ foreign_key: {to_table: :cats_core_stacks}
17
+
18
+ t.timestamps
19
+ end
20
+ end
21
+ end
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = "1.5.26".freeze
3
+ VERSION = "1.5.28".freeze
4
4
  end
5
5
  end
@@ -0,0 +1,11 @@
1
+ FactoryBot.define do
2
+ factory :inventory_adjustment, class: "Cats::Core::InventoryAdjustment" do
3
+ reference_no { FFaker::Name.name }
4
+ quantity { 1.5 }
5
+ adjustment_date { Date.today }
6
+ status { Cats::Core::Transaction::DRAFT }
7
+ reason_for_adjustment { FFaker::Name.name }
8
+ unit factory: :unit_of_measure
9
+ stack
10
+ end
11
+ 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.26
4
+ version: 1.5.28
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-24 00:00:00.000000000 Z
11
+ date: 2023-12-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers
@@ -298,6 +298,7 @@ files:
298
298
  - app/controllers/cats/core/dispatch_plans_controller.rb
299
299
  - app/controllers/cats/core/dispatch_transactions_controller.rb
300
300
  - app/controllers/cats/core/dispatches_controller.rb
301
+ - app/controllers/cats/core/inventory_adjustments_controller.rb
301
302
  - app/controllers/cats/core/loans_controller.rb
302
303
  - app/controllers/cats/core/locations_controller.rb
303
304
  - app/controllers/cats/core/lost_commodities_controller.rb
@@ -347,6 +348,7 @@ files:
347
348
  - app/models/cats/core/donor.rb
348
349
  - app/models/cats/core/gift_certificate.rb
349
350
  - app/models/cats/core/hub_authorization.rb
351
+ - app/models/cats/core/inventory_adjustment.rb
350
352
  - app/models/cats/core/loan.rb
351
353
  - app/models/cats/core/location.rb
352
354
  - app/models/cats/core/lost_commodity.rb
@@ -415,6 +417,7 @@ files:
415
417
  - app/serializers/cats/core/dispatch_plan_serializer.rb
416
418
  - app/serializers/cats/core/dispatch_serializer.rb
417
419
  - app/serializers/cats/core/dispatch_transaction_serializer.rb
420
+ - app/serializers/cats/core/inventory_adjustment_serializer.rb
418
421
  - app/serializers/cats/core/loan_serializer.rb
419
422
  - app/serializers/cats/core/location_serializer.rb
420
423
  - app/serializers/cats/core/lost_commodity_serializer.rb
@@ -527,6 +530,7 @@ files:
527
530
  - db/migrate/20221024081134_add_reference_no_to_cats_core_receipts.rb
528
531
  - db/migrate/20221024081141_add_reference_no_to_cats_core_dispatch_transactions.rb
529
532
  - db/migrate/20230102064317_add_receipt_number_to_cats_core_receipt_transactions.rb
533
+ - db/migrate/20231129071520_create_cats_core_inventory_adjustments.rb
530
534
  - lib/cats/core.rb
531
535
  - lib/cats/core/engine.rb
532
536
  - lib/cats/core/version.rb
@@ -553,6 +557,7 @@ files:
553
557
  - spec/factories/cats/core/donors.rb
554
558
  - spec/factories/cats/core/gift_certificates.rb
555
559
  - spec/factories/cats/core/hub_authorizations.rb
560
+ - spec/factories/cats/core/inventory_adjustments.rb
556
561
  - spec/factories/cats/core/loans.rb
557
562
  - spec/factories/cats/core/locations.rb
558
563
  - spec/factories/cats/core/lost_commodities.rb