cats_core 1.5.3 → 1.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/cats/core/commodities_controller.rb +2 -2
  3. data/app/controllers/cats/core/dispatch_authorizations_controller.rb +2 -2
  4. data/app/controllers/cats/core/dispatch_transactions_controller.rb +1 -1
  5. data/app/controllers/cats/core/lost_commodities_controller.rb +1 -1
  6. data/app/controllers/cats/core/receipt_authorizations_controller.rb +2 -2
  7. data/app/controllers/cats/core/receipt_transactions_controller.rb +1 -1
  8. data/app/controllers/cats/core/receipts_controller.rb +1 -1
  9. data/app/controllers/cats/core/stacks_controller.rb +2 -2
  10. data/app/models/cats/core/authorization.rb +4 -9
  11. data/app/models/cats/core/commodity.rb +1 -0
  12. data/app/models/cats/core/dispatch.rb +0 -6
  13. data/app/models/cats/core/dispatch_plan.rb +3 -1
  14. data/app/models/cats/core/dispatch_transaction.rb +1 -1
  15. data/app/models/cats/core/hub_authorization.rb +2 -1
  16. data/app/models/cats/core/lost_commodity.rb +3 -1
  17. data/app/models/cats/core/receipt.rb +3 -1
  18. data/app/models/cats/core/receipt_transaction.rb +1 -1
  19. data/app/models/cats/core/rhn_request.rb +2 -1
  20. data/app/models/cats/core/stack.rb +1 -0
  21. data/app/models/cats/core/transaction.rb +2 -0
  22. data/app/serializers/cats/core/commodity_serializer.rb +1 -1
  23. data/app/serializers/cats/core/dispatch_authorization_serializer.rb +2 -1
  24. data/app/serializers/cats/core/dispatch_plan_item_serializer.rb +1 -1
  25. data/app/serializers/cats/core/dispatch_transaction_serializer.rb +2 -1
  26. data/app/serializers/cats/core/lost_commodity_serializer.rb +1 -1
  27. data/app/serializers/cats/core/receipt_authorization_serializer.rb +1 -1
  28. data/app/serializers/cats/core/receipt_serializer.rb +2 -1
  29. data/app/serializers/cats/core/receipt_transaction_serializer.rb +1 -1
  30. data/app/serializers/cats/core/stack_serializer.rb +1 -1
  31. data/app/utils/cats/core/util.rb +6 -0
  32. data/lib/cats/core/version.rb +1 -1
  33. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4b08867f616a2f760492e1a866ff5b0145babdb3099162319edd14b037bc4c10
4
- data.tar.gz: 0b5237c0cd384b3b87b38b377bc87499d26e24fbd8fa1e31b48896730d313ce9
3
+ metadata.gz: e9a6ea1b862a6804a3e215898c7aac9966ffedbdf7aa3c8d9661f9356c4b8a24
4
+ data.tar.gz: f08e17d946b62d02d148cffbe97ab52c9b1f113245d4dffca6f5d67256ec7ea0
5
5
  SHA512:
6
- metadata.gz: 8764be6cd42ce15582359de5543f801b8b8d6f7974b15cbec6dc2bea649dba0ad698a9e44cbe60a4925ab5f8239c270cc9e4b6d01f9670e80417f214b77b68b0
7
- data.tar.gz: 923adf41d9972d43697e7862697fc07ac9b76eab2706ea6c954612aa5467b86f24ddf515f3c5f54e4ec6e7495dba9c3286c05a1db5532fc952f7ccb183dd1fbb
6
+ metadata.gz: ea2045f6a7a7954a4157952747c932e096f5df6e8ab2a56e888ca1f656a85eb7bd08a572ad0f15a05b53b0defc51354c27755be960c69c4c0ec49b232ad9b5db
7
+ data.tar.gz: d91d382689b7abab6221e64457123334bc93bc0357ffdf6eb28e71466d46183ba3aeab2b0d01b24abb0184a7b01b06ae5d0e2331220b710b3a193ac751061ad6
@@ -5,7 +5,7 @@ module Cats
5
5
 
6
6
  def index
7
7
  super do
8
- Commodity.all.includes({ project: { source: :commodity_category } }, :unit_of_measure)
8
+ Commodity.all.includes({ project: { source: :commodity_category } }, :unit_of_measure, :package_unit)
9
9
  end
10
10
  end
11
11
 
@@ -18,7 +18,7 @@ module Cats
18
18
  end
19
19
 
20
20
  def filter
21
- query = Commodity.includes(:project, :unit_of_measure).ransack(params[:q])
21
+ query = Commodity.includes(:project, :unit_of_measure, :package_unit).ransack(params[:q])
22
22
  render json: { success: true, data: serialize(query.result) }
23
23
  end
24
24
 
@@ -5,7 +5,7 @@ module Cats
5
5
 
6
6
  def index
7
7
  super do
8
- DispatchAuthorization.includes(:dispatch, :store, :authorized_by).where(dispatch_id: params[:id])
8
+ DispatchAuthorization.includes(:dispatch, :store, :authorized_by, :unit).where(dispatch_id: params[:id])
9
9
  end
10
10
  end
11
11
 
@@ -21,7 +21,7 @@ module Cats
21
21
  storekeeper = User.find(params[:id])
22
22
  stores = storekeeper.stores
23
23
  authorizations = DispatchAuthorization.joins(:dispatch)
24
- .includes(:dispatch, :store, :authorized_by)
24
+ .includes(:dispatch, :store, :authorized_by, :unit)
25
25
  .where(store: stores, dispatch: { dispatch_status: Dispatch::APPROVED })
26
26
  render json: { success: true, data: serialize(authorizations) }
27
27
  end
@@ -5,7 +5,7 @@ module Cats
5
5
 
6
6
  def index
7
7
  super do
8
- DispatchTransaction.includes(:source).where(dispatch_authorization_id: params[:id])
8
+ DispatchTransaction.includes(:source, :unit).where(dispatch_authorization_id: params[:id])
9
9
  end
10
10
  end
11
11
 
@@ -5,7 +5,7 @@ module Cats
5
5
 
6
6
  def index
7
7
  super do
8
- LostCommodity.where(receipt_authorization_id: params[:id])
8
+ LostCommodity.includes(:unit).where(receipt_authorization_id: params[:id])
9
9
  end
10
10
  end
11
11
 
@@ -7,7 +7,7 @@ module Cats
7
7
 
8
8
  def index
9
9
  super do
10
- ReceiptAuthorization.includes(:dispatch, :store, :authorized_by).where(dispatch_id: params[:id])
10
+ ReceiptAuthorization.includes(:dispatch, :store, :authorized_by, :unit).where(dispatch_id: params[:id])
11
11
  end
12
12
  end
13
13
 
@@ -40,7 +40,7 @@ module Cats
40
40
  storekeeper = User.find(params[:id])
41
41
  status = params[:status]
42
42
  stores = storekeeper.stores
43
- authorizations = ReceiptAuthorization.includes(:dispatch, :store, :authorized_by)
43
+ authorizations = ReceiptAuthorization.includes(:dispatch, :store, :authorized_by, :unit)
44
44
  .where(store: stores, status: status)
45
45
  render json: { success: true, data: serialize(authorizations) }
46
46
  end
@@ -5,7 +5,7 @@ module Cats
5
5
 
6
6
  def index
7
7
  super do
8
- ReceiptTransaction.includes(:destination, { receipt_authorization: :dispatch })
8
+ ReceiptTransaction.includes(:destination, { receipt_authorization: :dispatch }, :unit)
9
9
  .where(receipt_authorization_id: params[:id])
10
10
  end
11
11
  end
@@ -5,7 +5,7 @@ module Cats
5
5
 
6
6
  def index
7
7
  super do
8
- Receipt.where(receipt_authorization_id: params[:id])
8
+ Receipt.includes(:unit).where(receipt_authorization_id: params[:id])
9
9
  end
10
10
  end
11
11
 
@@ -5,12 +5,12 @@ module Cats
5
5
 
6
6
  def index
7
7
  super do
8
- Stack.includes(:commodity).where(store_id: params[:id])
8
+ Stack.includes(:commodity, :unit).where(store_id: params[:id])
9
9
  end
10
10
  end
11
11
 
12
12
  def filter
13
- query = Stack.includes(:commodity).where(store_id: params[:id]).ransack(params[:q])
13
+ query = Stack.includes(:commodity, :unit).where(store_id: params[:id]).ransack(params[:q])
14
14
  render json: { success: true, data: serialize(query.result) }
15
15
  end
16
16
 
@@ -3,7 +3,7 @@ module Cats
3
3
  class Authorization < ApplicationRecord
4
4
  self.abstract_class = true
5
5
  after_initialize :set_status
6
- before_save :set_unit
6
+ before_validation :set_unit
7
7
 
8
8
  # Authorization statuses
9
9
  AUTHORIZED = 'Authorized'.freeze
@@ -25,6 +25,7 @@ module Cats
25
25
  delegate(:dispatch_status, to: :dispatch)
26
26
  delegate(:plate_no, to: :dispatch)
27
27
  delegate(:driver_name, to: :dispatch)
28
+ delegate(:abbreviation, to: :unit, prefix: true)
28
29
 
29
30
  def set_unit
30
31
  return if unit
@@ -64,7 +65,7 @@ module Cats
64
65
  save!
65
66
  reload
66
67
  if dispatch.all_authorizations_confirmed?
67
- dispatch.generate_pin
68
+ Util.generate_pin(dispatch)
68
69
  dispatch.quantity = dispatch.dispatch_transactions.sum(:quantity)
69
70
  dispatch.dispatch_status = Dispatch::READY_TO_START
70
71
  dispatch.save!
@@ -81,17 +82,11 @@ module Cats
81
82
  self.received_quantity = total_received
82
83
  self.status = CONFIRMED
83
84
  save!
84
- generate_pin
85
+ Util.generate_pin(self)
85
86
  end
86
87
  self
87
88
  end
88
89
 
89
- def generate_pin
90
- pin = SecureRandom.hex(10)
91
- self.auth_details = { pin: pin, active: true, expires_at: DateTime.now + 1.hour }
92
- save!
93
- end
94
-
95
90
  private
96
91
 
97
92
  def set_status
@@ -57,6 +57,7 @@ module Cats
57
57
 
58
58
  delegate(:abbreviation, to: :unit_of_measure, prefix: 'unit')
59
59
  delegate(:code, to: :project, prefix: true)
60
+ delegate(:abbreviation, to: :package_unit, prefix: true, allow_nil: true)
60
61
 
61
62
  alias_attribute :unit, :unit_of_measure
62
63
 
@@ -118,12 +118,6 @@ module Cats
118
118
  }
119
119
  end
120
120
  end
121
-
122
- def generate_pin
123
- pin = SecureRandom.hex(10)
124
- self.auth_details = { pin: pin, active: true, expires_at: DateTime.now + 24.hour }
125
- save!
126
- end
127
121
  end
128
122
  end
129
123
  end
@@ -54,7 +54,9 @@ module Cats
54
54
  # A method which returns the total quantity in the dispatch plan
55
55
  # based on dispatch plan item quantities.
56
56
  def quantity
57
- dispatch_plan_items.sum(:quantity)
57
+ raise(StandardError, 'Dispatchable must be RHN request.') unless dispatchable.instance_of?(RhnRequest)
58
+
59
+ UnitConversion.harmonized_total(dispatch_plan_items, dispatchable.unit)
58
60
  end
59
61
 
60
62
  def region
@@ -1,7 +1,7 @@
1
1
  module Cats
2
2
  module Core
3
3
  class DispatchTransaction < Transaction
4
- before_save :set_unit
4
+ before_validation :set_unit
5
5
 
6
6
  belongs_to :source, class_name: 'Cats::Core::Stack'
7
7
  belongs_to :dispatch_authorization
@@ -1,7 +1,7 @@
1
1
  module Cats
2
2
  module Core
3
3
  class HubAuthorization < ApplicationRecord
4
- before_save :set_unit
4
+ before_validation :set_unit
5
5
 
6
6
  SOURCE = 'Source'.freeze
7
7
  DESTINATION = 'Destination'.freeze
@@ -20,6 +20,7 @@ module Cats
20
20
  delegate(:plan_reference_no, to: :dispatch_plan_item)
21
21
  delegate(:full_name, to: :authorized_by, prefix: true)
22
22
  delegate(:name, to: :store, prefix: true)
23
+ delegate(:abbreviation, to: :unit, prefix: true)
23
24
 
24
25
  def set_unit
25
26
  return if unit
@@ -1,7 +1,7 @@
1
1
  module Cats
2
2
  module Core
3
3
  class LostCommodity < ApplicationRecord
4
- before_save :set_unit
4
+ before_validation :set_unit
5
5
 
6
6
  belongs_to :receipt_authorization
7
7
  belongs_to :unit, class_name: 'Cats::Core::UnitOfMeasure'
@@ -9,6 +9,8 @@ module Cats
9
9
  validates :quantity, presence: true, numericality: { greater_than: 0 }
10
10
  validate :validate_quantity
11
11
 
12
+ delegate(:abbreviation, to: :unit, prefix: true)
13
+
12
14
  def set_unit
13
15
  return if unit
14
16
 
@@ -1,7 +1,7 @@
1
1
  module Cats
2
2
  module Core
3
3
  class Receipt < ApplicationRecord
4
- before_save :set_unit
4
+ before_validation :set_unit
5
5
 
6
6
  belongs_to :receipt_authorization
7
7
  belongs_to :unit, class_name: 'Cats::Core::UnitOfMeasure'
@@ -11,6 +11,8 @@ module Cats
11
11
  validates :quantity, presence: true, numericality: { greater_than: 0 }
12
12
  validate :validate_quantity
13
13
 
14
+ delegate(:abbreviation, to: :unit, prefix: true)
15
+
14
16
  def set_unit
15
17
  return if unit
16
18
 
@@ -1,7 +1,7 @@
1
1
  module Cats
2
2
  module Core
3
3
  class ReceiptTransaction < Transaction
4
- before_save :set_unit
4
+ before_validation :set_unit
5
5
 
6
6
  belongs_to :receipt_authorization
7
7
  belongs_to :destination, class_name: 'Cats::Core::Stack'
@@ -3,7 +3,7 @@ module Cats
3
3
  class RhnRequest < ApplicationRecord
4
4
  include Dispatchable
5
5
 
6
- before_save :set_unit
6
+ before_validation :set_unit
7
7
 
8
8
  ALLOCATED = 'Allocated'.freeze
9
9
  STATUSES << ALLOCATED
@@ -18,6 +18,7 @@ module Cats
18
18
  validate :validate_commodity_status, :validate_quantity
19
19
 
20
20
  delegate(:batch_no, to: :commodity, prefix: true)
21
+ delegate(:abbreviation, to: :unit, prefix: true)
21
22
 
22
23
  def set_unit
23
24
  return if unit
@@ -27,6 +27,7 @@ module Cats
27
27
  unless: -> { store && (store.code == 'SUP-STORE' || store.code.start_with?('FDP-ST')) }
28
28
 
29
29
  delegate :batch_no, to: :commodity, prefix: true
30
+ delegate :abbreviation, to: :unit, prefix: true
30
31
 
31
32
  after_save :update_store_space
32
33
 
@@ -15,6 +15,8 @@ module Cats
15
15
  validates :quantity, numericality: { greater_than: 0 }
16
16
  validates :status, inclusion: { in: STATUSES }
17
17
 
18
+ delegate(:abbreviation, to: :unit, prefix: true)
19
+
18
20
  def commit
19
21
  raise(NotImplementedError, 'Method should be implemented in child classes.')
20
22
  end
@@ -3,7 +3,7 @@ module Cats
3
3
  class CommoditySerializer < ActiveModel::Serializer
4
4
  attributes :id, :name, :batch_no, :description, :unit_of_measure_id, :unit_abbreviation, :project_id,
5
5
  :project_code, :quantity, :best_use_before, :volume_per_metric_ton, :arrival_status, :status,
6
- :shipping_reference, :commodity_grade
6
+ :shipping_reference, :commodity_grade, :package_unit_id, :package_unit_abbreviation
7
7
  end
8
8
  end
9
9
  end
@@ -2,7 +2,8 @@ module Cats
2
2
  module Core
3
3
  class DispatchAuthorizationSerializer < ActiveModel::Serializer
4
4
  attributes :id, :dispatch_id, :dispatch_reference_no, :store_id, :store_name, :quantity, :authorized_by_id,
5
- :authorizer_full_name, :dispatch_status, :plate_no, :driver_name, :status
5
+ :authorizer_full_name, :dispatch_status, :plate_no, :driver_name, :status, :unit_id,
6
+ :unit_abbreviation
6
7
  end
7
8
  end
8
9
  end
@@ -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
7
+ :commodity_shipping_reference, :unit_id
8
8
  end
9
9
  end
10
10
  end
@@ -1,7 +1,8 @@
1
1
  module Cats
2
2
  module Core
3
3
  class DispatchTransactionSerializer < ActiveModel::Serializer
4
- attributes :id, :source_id, :source_code, :dispatch_authorization_id, :quantity, :transaction_date, :status
4
+ attributes :id, :source_id, :source_code, :dispatch_authorization_id, :quantity, :transaction_date, :status,
5
+ :unit_id, :unit_abbreviation
5
6
  end
6
7
  end
7
8
  end
@@ -1,7 +1,7 @@
1
1
  module Cats
2
2
  module Core
3
3
  class LostCommoditySerializer < ActiveModel::Serializer
4
- attributes :id, :receipt_authorization_id, :quantity, :remark
4
+ attributes :id, :receipt_authorization_id, :quantity, :remark, :unit_id, :unit_abbreviation
5
5
  end
6
6
  end
7
7
  end
@@ -3,7 +3,7 @@ module Cats
3
3
  class ReceiptAuthorizationSerializer < ActiveModel::Serializer
4
4
  attributes :id, :dispatch_id, :dispatch_reference_no, :store_id, :store_name, :quantity, :received_quantity,
5
5
  :remark, :status, :authorized_by_id, :authorizer_full_name, :auth_details, :plate_no, :driver_name,
6
- :dispatch_status
6
+ :dispatch_status, :unit_id, :unit_abbreviation
7
7
  end
8
8
  end
9
9
  end
@@ -1,7 +1,8 @@
1
1
  module Cats
2
2
  module Core
3
3
  class ReceiptSerializer < ActiveModel::Serializer
4
- attributes :id, :receipt_authorization_id, :commodity_status, :commodity_grade, :quantity, :remark
4
+ attributes :id, :receipt_authorization_id, :commodity_status, :commodity_grade, :quantity, :remark,
5
+ :unit_id, :unit_abbreviation
5
6
  end
6
7
  end
7
8
  end
@@ -2,7 +2,7 @@ module Cats
2
2
  module Core
3
3
  class ReceiptTransactionSerializer < ActiveModel::Serializer
4
4
  attributes :id, :receipt_authorization_id, :dispatch_reference_no, :destination_id, :destination_code, :quantity,
5
- :transaction_date, :status
5
+ :transaction_date, :status, :unit_id, :unit_abbreviation
6
6
  end
7
7
  end
8
8
  end
@@ -2,7 +2,7 @@ module Cats
2
2
  module Core
3
3
  class StackSerializer < ActiveModel::Serializer
4
4
  attributes :id, :code, :length, :width, :height, :start_x, :start_y, :commodity_id, :store_id, :commodity_status,
5
- :stack_status, :quantity, :commodity_batch_no
5
+ :stack_status, :quantity, :commodity_batch_no, :unit_id, :unit_abbreviation
6
6
  end
7
7
  end
8
8
  end
@@ -4,6 +4,12 @@ module Cats
4
4
  def self.send_chain(obj, arr)
5
5
  arr.inject(obj) { |o, a| o.send(a) }
6
6
  end
7
+
8
+ def self.generate_pin(obj)
9
+ pin = SecureRandom.hex(10)
10
+ obj.auth_details = { pin: pin, active: true, expires_at: DateTime.now + 24.hour }
11
+ obj.save!
12
+ end
7
13
  end
8
14
  end
9
15
  end
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = '1.5.3'.freeze
3
+ VERSION = '1.5.4'.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.5.3
4
+ version: 1.5.4
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-09-30 00:00:00.000000000 Z
11
+ date: 2022-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers