cats_core 1.5.25 → 1.5.27

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: 78f6d9a4f2c81fd8ba524a604d6e8bf4fc8429807bce72b8af05e93b1496c321
4
- data.tar.gz: ba5e35b1b7b4e6b84ca9fe72ed81a756ae42e5d8b7584b61048586c53cc29d21
3
+ metadata.gz: 2865fcf1ffc5a821dd2011d92cb64aa062ff61441c82c1c510af16035827f082
4
+ data.tar.gz: 8e5c5bc4826e22b2e7cdf6aa4cd2b29466085e7a4ce296121b074f59a71adc37
5
5
  SHA512:
6
- metadata.gz: 91d369fba469a5457a771c39ebafe8253f8f249609ffeaf4f0c1a953e5a29ec6b7411bfca0b66cb406a2471298b549669a5a8f424f5fbd082121bd199a98d03d
7
- data.tar.gz: 9bee3cbd46f8255981c1bf9dd338f82783edc82b90f885a4a12d09d983a0aaa38069a9aed56dbc49f162c68559dc45d30e421d8237e2227dcf57ab56d38fdcdd
6
+ metadata.gz: a6c116447db30f695bad8135801888cd90878bc53e84e284bf6f648e4ac56e469ea9f8abaea4c8120ce04220d7e8b83a8cb8fdd529a37b0b3308c70f48ff622f
7
+ data.tar.gz: 5393dbaab893533aa60034deab2ce0e3827dad922f70f254ebad50c7f411e77dca0bad8e9daf3441b15ed2bf4f0d92c61e79de784eabb94bfd76244b6cfd92f0
@@ -51,7 +51,7 @@ module Cats
51
51
  private
52
52
 
53
53
  def model_params
54
- params.require(:payload).permit(:reference_no, :dispatchable_id, :dispatchable_type)
54
+ params.require(:payload).permit(:reference_no, :dispatchable_id, :dispatchable_type, :status)
55
55
  end
56
56
 
57
57
  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
@@ -195,7 +195,7 @@ Cats::Core::Engine.routes.draw do
195
195
  resources :receipt_transactions, except: %i[index new edit destroy]
196
196
  resources :stack_transactions, except: %i[index new edit destroy] do
197
197
  member do
198
- post "commit"
198
+ post "commit", controller: :stack_transactions, action: :commit
199
199
  end
200
200
  end
201
201
  resources :lost_commodities, except: %i[index destroy]
@@ -233,4 +233,12 @@ Cats::Core::Engine.routes.draw do
233
233
  end
234
234
  end
235
235
  post "/stores/filter", controller: :stores, action: :filter
236
+ post 'stack_transactions/filter', controller: :stack_transactions, action: :filter
237
+ resources :stack_transactions, only: %i[index create update]
238
+ post 'inventory_adjustments/filter', controller: :inventory_adjustments, action: :filter
239
+ resources :inventory_adjustments, only: %i[index create update] do
240
+ member do
241
+ post "commit", controller: :inventory_adjustments, action: :commit
242
+ end
243
+ end
236
244
  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.25".freeze
3
+ VERSION = "1.5.27".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.25
4
+ version: 1.5.27
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-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '2.7'
61
+ version: 2.3.0
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '2.7'
68
+ version: 2.3.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: noticed
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -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