cats_core 1.5.2 → 1.5.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) 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 +3 -3
  4. data/app/controllers/cats/core/dispatch_transactions_controller.rb +2 -2
  5. data/app/controllers/cats/core/lost_commodities_controller.rb +2 -2
  6. data/app/controllers/cats/core/receipt_authorizations_controller.rb +4 -3
  7. data/app/controllers/cats/core/receipt_transactions_controller.rb +3 -2
  8. data/app/controllers/cats/core/receipts_controller.rb +2 -2
  9. data/app/controllers/cats/core/stacks_controller.rb +3 -3
  10. data/app/models/cats/core/application_setting.rb +10 -0
  11. data/app/models/cats/core/authorization.rb +14 -8
  12. data/app/models/cats/core/commodity.rb +10 -0
  13. data/app/models/cats/core/dispatch.rb +3 -19
  14. data/app/models/cats/core/dispatch_authorization.rb +13 -0
  15. data/app/models/cats/core/dispatch_plan.rb +3 -1
  16. data/app/models/cats/core/dispatch_plan_item.rb +4 -3
  17. data/app/models/cats/core/dispatch_transaction.rb +23 -10
  18. data/app/models/cats/core/hub_authorization.rb +15 -9
  19. data/app/models/cats/core/lost_commodity.rb +29 -0
  20. data/app/models/cats/core/receipt.rb +22 -0
  21. data/app/models/cats/core/receipt_authorization.rb +5 -8
  22. data/app/models/cats/core/receipt_transaction.rb +13 -5
  23. data/app/models/cats/core/rhn_request.rb +25 -8
  24. data/app/models/cats/core/stack.rb +3 -0
  25. data/app/models/cats/core/stack_transaction.rb +1 -0
  26. data/app/models/cats/core/transaction.rb +4 -0
  27. data/app/models/cats/core/unit_conversion.rb +21 -3
  28. data/app/notifications/cats/core/dispatch_notification.rb +2 -0
  29. data/app/serializers/cats/core/commodity_serializer.rb +1 -1
  30. data/app/serializers/cats/core/dispatch_authorization_serializer.rb +2 -1
  31. data/app/serializers/cats/core/dispatch_plan_item_serializer.rb +1 -1
  32. data/app/serializers/cats/core/dispatch_transaction_serializer.rb +2 -1
  33. data/app/serializers/cats/core/lost_commodity_serializer.rb +1 -1
  34. data/app/serializers/cats/core/receipt_authorization_serializer.rb +1 -1
  35. data/app/serializers/cats/core/receipt_serializer.rb +2 -1
  36. data/app/serializers/cats/core/receipt_transaction_serializer.rb +1 -1
  37. data/app/serializers/cats/core/stack_serializer.rb +1 -1
  38. data/app/services/cats/core/authorization_service.rb +2 -0
  39. data/app/services/cats/core/dispatch_plan_service.rb +1 -0
  40. data/app/utils/cats/core/util.rb +15 -0
  41. data/app/utils/cats/core/validation_util.rb +20 -0
  42. data/db/migrate/20210717033223_create_cats_core_commodities.rb +5 -0
  43. data/db/migrate/20210717171101_create_cats_core_stacks.rb +4 -0
  44. data/db/migrate/20210718042755_create_cats_core_rhn_requests.rb +4 -0
  45. data/db/migrate/20210718045516_create_cats_core_dispatches.rb +1 -1
  46. data/db/migrate/20210718055414_create_cats_core_dispatch_authorizations.rb +4 -0
  47. data/db/migrate/20210718202957_create_cats_core_dispatch_transactions.rb +4 -0
  48. data/db/migrate/20210727074646_create_cats_core_receipt_authorizations.rb +4 -0
  49. data/db/migrate/20210727105834_create_cats_core_receipts.rb +4 -0
  50. data/db/migrate/20210728041505_create_cats_core_lost_commodities.rb +4 -0
  51. data/db/migrate/20210814160628_create_cats_core_receipt_transactions.rb +4 -0
  52. data/db/migrate/20210814175406_create_cats_core_stack_transactions.rb +4 -0
  53. data/db/migrate/20220209083928_create_cats_core_hub_authorizations.rb +4 -0
  54. data/db/migrate/20220923190857_create_cats_core_application_settings.rb +14 -0
  55. data/lib/cats/core/version.rb +1 -1
  56. data/spec/factories/cats/core/application_settings.rb +7 -0
  57. data/spec/factories/cats/core/commodities.rb +1 -0
  58. data/spec/factories/cats/core/dispatch_authorizations.rb +1 -0
  59. data/spec/factories/cats/core/dispatch_transactions.rb +5 -4
  60. data/spec/factories/cats/core/dispatches.rb +7 -1
  61. data/spec/factories/cats/core/hub_authorizations.rb +1 -0
  62. data/spec/factories/cats/core/lost_commodities.rb +1 -0
  63. data/spec/factories/cats/core/receipt_authorizations.rb +1 -0
  64. data/spec/factories/cats/core/receipt_transactions.rb +5 -1
  65. data/spec/factories/cats/core/receipts.rb +1 -0
  66. data/spec/factories/cats/core/rhn_requests.rb +1 -0
  67. data/spec/factories/cats/core/stack_transactions.rb +1 -0
  68. data/spec/factories/cats/core/stacks.rb +1 -0
  69. metadata +7 -2
@@ -3,13 +3,13 @@ module Cats
3
3
  class RhnRequest < ApplicationRecord
4
4
  include Dispatchable
5
5
 
6
- # DRAFT = 'Draft'.freeze
7
- # APPROVED = 'Approved'.freeze
8
- # RESERVED = 'Reserved'.freeze
6
+ before_validation :set_unit
7
+
9
8
  ALLOCATED = 'Allocated'.freeze
10
9
  STATUSES << ALLOCATED
11
10
 
12
11
  belongs_to :commodity
12
+ belongs_to :unit, class_name: 'Cats::Core::UnitOfMeasure'
13
13
 
14
14
  validates :reference_no, :request_date, :quantity, presence: true
15
15
  validates :reference_no, uniqueness: true
@@ -18,6 +18,15 @@ 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)
22
+
23
+ def set_unit
24
+ return if unit
25
+
26
+ return unless commodity
27
+
28
+ self.unit = commodity.unit
29
+ end
21
30
 
22
31
  def request_reference
23
32
  reference_no
@@ -34,13 +43,21 @@ module Cats
34
43
  end
35
44
 
36
45
  def validate_quantity
37
- return unless commodity && quantity
46
+ return unless commodity && quantity && unit
38
47
 
39
- requested = RhnRequest.where(commodity: commodity).sum(:quantity)
40
- remaining = commodity.quantity - requested
48
+ requested = commodity.requested_quantity
41
49
 
42
- remaining += quantity_was if quantity_was
43
- errors.add(:quantity, "exceeds commodity quantity. Maximum allowed is #{remaining}") if quantity > remaining
50
+ remaining = commodity.quantity - requested
51
+ if quantity_was
52
+ additional = UnitConversion.convert(unit, commodity.unit_of_measure, quantity_was)
53
+ remaining += additional
54
+ end
55
+ new_quantity = UnitConversion.convert(unit, commodity.unit_of_measure, quantity)
56
+ return unless new_quantity > remaining
57
+
58
+ remaining = UnitConversion.convert(commodity.unit_of_measure, unit, remaining)
59
+ message = "exceeds commodity quantity. Maximum allowed is #{remaining} #{unit.abbreviation}"
60
+ errors.add(:quantity, message)
44
61
  end
45
62
 
46
63
  def approve
@@ -9,6 +9,8 @@ module Cats
9
9
 
10
10
  belongs_to :commodity
11
11
  belongs_to :store
12
+ belongs_to :unit, class_name: 'Cats::Core::UnitOfMeasure'
13
+
12
14
  has_many :dispatch_transactions, foreign_key: :source_id
13
15
  has_many :receipt_transactions, foreign_key: :destination_id
14
16
 
@@ -25,6 +27,7 @@ module Cats
25
27
  unless: -> { store && (store.code == 'SUP-STORE' || store.code.start_with?('FDP-ST')) }
26
28
 
27
29
  delegate :batch_no, to: :commodity, prefix: true
30
+ delegate :abbreviation, to: :unit, prefix: true
28
31
 
29
32
  after_save :update_store_space
30
33
 
@@ -3,6 +3,7 @@ module Cats
3
3
  class StackTransaction < Transaction
4
4
  belongs_to :source, class_name: 'Cats::Core::Stack'
5
5
  belongs_to :destination, class_name: 'Cats::Core::Stack'
6
+ belongs_to :unit, class_name: 'Cats::Core::UnitOfMeasure'
6
7
 
7
8
  def validate_quantity
8
9
  return unless quantity.present? && source.present?
@@ -9,10 +9,14 @@ module Cats
9
9
  COMMITTED = 'Committed'.freeze
10
10
  STATUSES = [DRAFT, COMMITTED].freeze
11
11
 
12
+ belongs_to :unit, class_name: 'Cats::Core::UnitOfMeasure'
13
+
12
14
  validates :transaction_date, :quantity, :status, presence: true
13
15
  validates :quantity, numericality: { greater_than: 0 }
14
16
  validates :status, inclusion: { in: STATUSES }
15
17
 
18
+ delegate(:abbreviation, to: :unit, prefix: true)
19
+
16
20
  def commit
17
21
  raise(NotImplementedError, 'Method should be implemented in child classes.')
18
22
  end
@@ -15,10 +15,28 @@ module Cats
15
15
  return value if from == to
16
16
 
17
17
  conversion = find_by(from: from, to: to)
18
- error = "Conversion factor from #{from.abbreviation} to #{to.abbreviation} not found."
19
- raise(StandardError, error) unless conversion
18
+ return value * conversion.factor if conversion
20
19
 
21
- value * conversion.factor
20
+ # Check if there is reverse conversion entry defined
21
+ conversion = find_by(from: to, to: from)
22
+ unless conversion
23
+ raise(StandardError, "Conversion factor between #{from.abbreviation} and #{to.abbreviation} not found.")
24
+ end
25
+
26
+ value / conversion.factor
27
+ end
28
+
29
+ ##
30
+ # This function calculates the sum of quantities of a list of objects with quantities and different
31
+ # units into one. The list can be a list of hub authorizations, RHN requests, dispatch plan items,
32
+ # etc ... This method assumes that quantity is represented by the attribute <tt>quantity</tt> and unit of
33
+ # measure is represented by the attribute <tt>unit</tt> for each object in the object list. If that is not
34
+ # true then one should create those two attributes as aliases in the respective models.
35
+ #
36
+ def self.harmonized_total(list, unit)
37
+ list.inject(0) do |res, obj|
38
+ res + UnitConversion.convert(obj.unit, unit, obj.quantity)
39
+ end
22
40
  end
23
41
  end
24
42
  end
@@ -12,11 +12,13 @@ module Cats
12
12
  date = Date.today
13
13
  body = <<~BODY
14
14
  Commodity with the following details has been dispatched to you:
15
+ Authorization no. = #{dispatch.dispatch_plan_item.reference_no}
15
16
  Dispatch Ref. = #{dispatch.reference_no}
16
17
  Batch No. = #{commodity.batch_no}
17
18
  Commodity = #{commodity.name}
18
19
  Allocated Quantity = #{dispatch.dispatch_plan_item.quantity}
19
20
  Quantity = #{dispatch.quantity}
21
+ Unit = #{dispatch.unit.abbreviation}
20
22
  Truck Plate No. = #{dispatch.plate_no}
21
23
  Driver Name = #{dispatch.driver_name}
22
24
  Driver Phone = #{dispatch.driver_phone}
@@ -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
@@ -46,6 +46,7 @@ module Cats
46
46
  start_x: 2,
47
47
  start_y: 2,
48
48
  commodity: commodity,
49
+ unit: commodity.package_unit,
49
50
  store: authorization.store,
50
51
  commodity_status: Commodity::GOOD,
51
52
  stack_status: Stack::ALLOCATED
@@ -54,6 +55,7 @@ module Cats
54
55
  receipt_authorization: authorization,
55
56
  destination: stack,
56
57
  quantity: authorization.received_quantity,
58
+ unit: authorization.unit,
57
59
  status: Transaction::DRAFT,
58
60
  transaction_date: Date.today
59
61
  )
@@ -15,6 +15,7 @@ module Cats
15
15
  dispatch_plan_item_id: item.id,
16
16
  store_id: store.id,
17
17
  quantity: item.quantity,
18
+ unit_id: item.unit_id,
18
19
  authorization_type: HubAuthorization::SOURCE,
19
20
  authorized_by_id: keeper.id,
20
21
  created_at: Date.today,
@@ -0,0 +1,15 @@
1
+ module Cats
2
+ module Core
3
+ class Util
4
+ def self.send_chain(obj, arr)
5
+ arr.inject(obj) { |o, a| o.send(a) }
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
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,20 @@
1
+ module Cats
2
+ module Core
3
+ class ValidationUtil
4
+ def self.validate_quantity(obj, parent_attr, relation, error_key, quantity_attribs = nil, unit_attribs = nil)
5
+ parent = obj.send(parent_attr)
6
+ quantity = quantity_attribs ? Util.send_chain(parent, quantity_attribs) : parent.quantity
7
+ unit = unit_attribs ? Util.send_chain(parent, unit_attribs) : parent.unit
8
+ total = UnitConversion.convert(unit, obj.unit, quantity)
9
+ used = UnitConversion.harmonized_total(relation, obj.unit)
10
+ used -= obj.quantity_was if obj.quantity_was
11
+
12
+ remaining = total - used
13
+ return unless obj.quantity > remaining
14
+
15
+ error = "exceeds #{error_key} quantity. Maximum allowed is #{remaining} #{obj.unit.abbreviation}"
16
+ obj.errors.add(:quantity, error)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -10,6 +10,11 @@ class CreateCatsCoreCommodities < ActiveRecord::Migration[6.1]
10
10
  null: false,
11
11
  index: { name: 'project_on_commodity_indx' },
12
12
  foreign_key: { to_table: :cats_core_projects }
13
+ t.references :package_unit,
14
+ null: true,
15
+ index: { name: 'pu_on_commodity_indx' },
16
+ foreign_key: { to_table: :cats_core_unit_of_measures }
17
+
13
18
  t.float :quantity, null: false
14
19
  t.string :description
15
20
  t.date :best_use_before, null: false
@@ -18,6 +18,10 @@ class CreateCatsCoreStacks < ActiveRecord::Migration[6.1]
18
18
  t.string :commodity_status, null: false, default: 'Good'
19
19
  t.string :stack_status, null: false, default: 'Reserved'
20
20
  t.float :quantity, null: false, default: 0
21
+ t.references :unit,
22
+ null: false,
23
+ index: { name: 'unit_on_stack_indx' },
24
+ foreign_key: { to_table: :cats_core_unit_of_measures }
21
25
 
22
26
  t.timestamps
23
27
  end
@@ -7,6 +7,10 @@ class CreateCatsCoreRhnRequests < ActiveRecord::Migration[6.1]
7
7
  index: { name: 'commodity_on_rhn_indx' },
8
8
  foreign_key: { to_table: :cats_core_commodities }
9
9
  t.float :quantity, null: false
10
+ t.references :unit,
11
+ null: false,
12
+ index: { name: 'unit_on_rhn_indx' },
13
+ foreign_key: { to_table: :cats_core_unit_of_measures }
10
14
  t.date :request_date, null: false
11
15
  t.string :requested_by
12
16
 
@@ -17,7 +17,7 @@ class CreateCatsCoreDispatches < ActiveRecord::Migration[6.1]
17
17
  t.references :unit,
18
18
  null: false,
19
19
  index: { name: 'unit_on_dispatches_indx' },
20
- foreign_key: { to_table: :cats_core_unit_of_measures }
20
+ foreign_key: { to_table: :cats_core_unit_of_measures }
21
21
  t.string :commodity_status, null: false, default: 'Good'
22
22
  t.string :remark
23
23
  t.references :prepared_by,
@@ -10,6 +10,10 @@ class CreateCatsCoreDispatchAuthorizations < ActiveRecord::Migration[7.0]
10
10
  index: { name: 'store_on_da_indx' },
11
11
  foreign_key: { to_table: :cats_core_stores }
12
12
  t.float :quantity, null: false
13
+ t.references :unit,
14
+ null: false,
15
+ index: { name: 'unit_on_da_indx' },
16
+ foreign_key: { to_table: :cats_core_unit_of_measures }
13
17
  t.string :status, null: false, default: 'Authorized'
14
18
  t.references :authorized_by,
15
19
  null: false,
@@ -11,6 +11,10 @@ class CreateCatsCoreDispatchTransactions < ActiveRecord::Migration[6.1]
11
11
  foreign_key: { to_table: :cats_core_dispatch_authorizations }
12
12
  t.date :transaction_date, null: false
13
13
  t.float :quantity, null: false
14
+ t.references :unit,
15
+ null: false,
16
+ index: { name: 'unit_on_dt_indx' },
17
+ foreign_key: { to_table: :cats_core_unit_of_measures }
14
18
  t.string :status, null: false, default: 'Draft'
15
19
 
16
20
  t.timestamps
@@ -10,6 +10,10 @@ class CreateCatsCoreReceiptAuthorizations < ActiveRecord::Migration[6.1]
10
10
  index: { name: 'store_on_ra_indx' },
11
11
  foreign_key: { to_table: :cats_core_stores }
12
12
  t.float :quantity, null: false
13
+ t.references :unit,
14
+ null: false,
15
+ index: { name: 'r_unit_on_da_indx' },
16
+ foreign_key: { to_table: :cats_core_unit_of_measures }
13
17
  t.float :received_quantity, null: false, default: 0
14
18
  t.string :status, null: false, default: 'Authorized'
15
19
  t.string :remark
@@ -8,6 +8,10 @@ class CreateCatsCoreReceipts < ActiveRecord::Migration[7.0]
8
8
  t.string :commodity_status, null: false
9
9
  t.string :commodity_grade
10
10
  t.float :quantity, null: false
11
+ t.references :unit,
12
+ null: false,
13
+ index: { name: 'unit_on_receipts_indx' },
14
+ foreign_key: { to_table: :cats_core_unit_of_measures }
11
15
  t.string :remark
12
16
 
13
17
  t.timestamps
@@ -6,6 +6,10 @@ class CreateCatsCoreLostCommodities < ActiveRecord::Migration[7.0]
6
6
  index: { name: 'ra_on_lc_indx' },
7
7
  foreign_key: { to_table: :cats_core_receipt_authorizations }
8
8
  t.float :quantity, null: false
9
+ t.references :unit,
10
+ null: false,
11
+ index: { name: 'unit_on_lc_indx' },
12
+ foreign_key: { to_table: :cats_core_unit_of_measures }
9
13
  t.string :remark
10
14
 
11
15
  t.timestamps
@@ -11,6 +11,10 @@ class CreateCatsCoreReceiptTransactions < ActiveRecord::Migration[6.1]
11
11
  foreign_key: { to_table: :cats_core_stacks }
12
12
  t.date :transaction_date, null: false
13
13
  t.float :quantity, null: false
14
+ t.references :unit,
15
+ null: false,
16
+ index: { name: 'r_unit_on_dt_indx' },
17
+ foreign_key: { to_table: :cats_core_unit_of_measures }
14
18
  t.string :status, null: false, default: 'Draft'
15
19
 
16
20
  t.timestamps
@@ -11,6 +11,10 @@ class CreateCatsCoreStackTransactions < ActiveRecord::Migration[6.1]
11
11
  foreign_key: { to_table: :cats_core_stacks }
12
12
  t.date :transaction_date, null: false
13
13
  t.float :quantity, null: false
14
+ t.references :unit,
15
+ null: false,
16
+ index: { name: 'unit_on_st_indx' },
17
+ foreign_key: { to_table: :cats_core_unit_of_measures }
14
18
  t.string :status, null: false, default: 'Draft'
15
19
 
16
20
  t.timestamps
@@ -10,6 +10,10 @@ class CreateCatsCoreHubAuthorizations < ActiveRecord::Migration[7.0]
10
10
  index: { name: 'store_on_ha_indx' },
11
11
  foreign_key: { to_table: :cats_core_stores }
12
12
  t.float :quantity, null: false
13
+ t.references :unit,
14
+ null: false,
15
+ index: { name: 'unit_on_ha_indx' },
16
+ foreign_key: { to_table: :cats_core_unit_of_measures }
13
17
  t.string :authorization_type, null: false
14
18
  t.references :authorized_by,
15
19
  null: false,
@@ -0,0 +1,14 @@
1
+ class CreateCatsCoreApplicationSettings < ActiveRecord::Migration[7.0]
2
+ def change
3
+ create_table :cats_core_application_settings do |t|
4
+ t.string :key, unique: true
5
+ t.string :value, null: false
6
+ t.references :application_module,
7
+ null: false,
8
+ index: { name: 'am_on_as_indx' },
9
+ foreign_key: { to_table: :cats_core_application_modules }
10
+
11
+ t.timestamps
12
+ end
13
+ end
14
+ end
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = '1.5.2'.freeze
3
+ VERSION = '1.5.4'.freeze
4
4
  end
5
5
  end
@@ -0,0 +1,7 @@
1
+ FactoryBot.define do
2
+ factory :application_setting, class: 'Cats::Core::ApplicationSetting' do
3
+ key { FFaker::Name.name }
4
+ value { FFaker::Name.name }
5
+ application_module
6
+ end
7
+ end
@@ -3,6 +3,7 @@ FactoryBot.define do
3
3
  batch_no { FFaker::Name.name }
4
4
  description { FFaker::Name.name }
5
5
  unit_of_measure
6
+ package_unit factory: :unit_of_measure
6
7
  project
7
8
  quantity { 100 }
8
9
  best_use_before { Date.today + 2.month }
@@ -7,6 +7,7 @@ FactoryBot.define do
7
7
  dispatch
8
8
  store { s }
9
9
  quantity { 100 }
10
+ unit { dispatch.unit }
10
11
  status { Cats::Core::ReceiptAuthorization::AUTHORIZED }
11
12
  authorized_by factory: :user
12
13
 
@@ -1,12 +1,13 @@
1
1
  FactoryBot.define do
2
2
  factory :dispatch_transaction, class: 'Cats::Core::DispatchTransaction' do
3
- transient do
4
- stack { create(:stack) }
5
- end
6
- source { stack }
7
3
  association :dispatch_authorization, :approved
4
+ source do
5
+ create(:stack, unit: dispatch_authorization.unit)
6
+ end
7
+
8
8
  transaction_date { Date.today }
9
9
  quantity { 100 }
10
+ unit { dispatch_authorization.unit }
10
11
  status { Cats::Core::Transaction::DRAFT }
11
12
  end
12
13
  end
@@ -10,7 +10,7 @@ FactoryBot.define do
10
10
  create(:hub_authorization, dispatch_plan_item: plan_item, quantity: 100, store: stack.store)
11
11
  plan_item
12
12
  end
13
- unit factory: :unit_of_measure
13
+ unit { dispatch_plan_item.unit }
14
14
  transporter
15
15
  plate_no { FFaker::Name.name }
16
16
  driver_name { FFaker::Name.name }
@@ -29,6 +29,8 @@ FactoryBot.define do
29
29
  after(:create) do |dispatch, options|
30
30
  authorization = create(:dispatch_authorization, dispatch: dispatch, store: options.stack.store)
31
31
  dispatch.approve
32
+ options.stack.unit = dispatch.unit
33
+ options.stack.save!
32
34
  create(:dispatch_transaction, dispatch_authorization: authorization, source: options.stack, quantity: 100)
33
35
  end
34
36
  end
@@ -37,6 +39,8 @@ FactoryBot.define do
37
39
  after(:create) do |dispatch, options|
38
40
  authorization = create(:dispatch_authorization, dispatch: dispatch, store: options.stack.store)
39
41
  dispatch.approve
42
+ options.stack.unit = dispatch.unit
43
+ options.stack.save!
40
44
  create(:dispatch_transaction, dispatch_authorization: authorization, source: options.stack, quantity: 100)
41
45
  authorization.confirm
42
46
  dispatch.quantity = 100
@@ -49,6 +53,8 @@ FactoryBot.define do
49
53
  after(:create) do |dispatch, options|
50
54
  authorization = create(:dispatch_authorization, dispatch: dispatch, store: options.stack.store)
51
55
  dispatch.approve
56
+ options.stack.unit = dispatch.unit
57
+ options.stack.save!
52
58
  create(:dispatch_transaction, dispatch_authorization: authorization, source: options.stack, quantity: 100)
53
59
  authorization.confirm
54
60
  dispatch.quantity = 100
@@ -3,6 +3,7 @@ FactoryBot.define do
3
3
  dispatch_plan_item
4
4
  store
5
5
  quantity { 100 }
6
+ unit { dispatch_plan_item.unit }
6
7
  authorization_type { Cats::Core::HubAuthorization::SOURCE }
7
8
  authorized_by factory: :user
8
9
  end
@@ -2,6 +2,7 @@ FactoryBot.define do
2
2
  factory :lost_commodity, class: 'Cats::Core::LostCommodity' do
3
3
  receipt_authorization
4
4
  quantity { 100 }
5
+ unit { receipt_authorization.unit }
5
6
  remark { FFaker::Name.name }
6
7
  end
7
8
  end
@@ -3,6 +3,7 @@ FactoryBot.define do
3
3
  association :dispatch, :started
4
4
  store
5
5
  quantity { 100 }
6
+ unit { dispatch.unit }
6
7
  received_quantity { 0 }
7
8
  remark { FFaker::Name.name }
8
9
  status { Cats::Core::ReceiptAuthorization::AUTHORIZED }
@@ -1,9 +1,13 @@
1
1
  FactoryBot.define do
2
2
  factory :receipt_transaction, class: 'Cats::Core::ReceiptTransaction' do
3
3
  association :receipt_authorization, :confirmed
4
- destination factory: :stack
4
+ destination do
5
+ create(:stack, unit: receipt_authorization.unit)
6
+ end
7
+
5
8
  transaction_date { Date.today }
6
9
  quantity { 100 }
10
+ unit { receipt_authorization.unit }
7
11
  status { Cats::Core::Transaction::DRAFT }
8
12
  end
9
13
  end
@@ -3,6 +3,7 @@ FactoryBot.define do
3
3
  receipt_authorization
4
4
  commodity_status { Cats::Core::Commodity::GOOD }
5
5
  quantity { 50 }
6
+ unit { receipt_authorization.unit }
6
7
  remark { FFaker::Name.name }
7
8
  end
8
9
  end
@@ -6,6 +6,7 @@ FactoryBot.define do
6
6
  c.approve
7
7
  c
8
8
  end
9
+ unit { commodity.unit_of_measure }
9
10
  quantity { 100 }
10
11
  request_date { Date.today }
11
12
  requested_by { FFaker::Name.name }
@@ -4,6 +4,7 @@ FactoryBot.define do
4
4
  destination factory: :stack
5
5
  transaction_date { Date.today }
6
6
  quantity { 25 }
7
+ unit { source.unit }
7
8
  status { Cats::Core::Transaction::DRAFT }
8
9
  end
9
10
  end
@@ -11,5 +11,6 @@ FactoryBot.define do
11
11
  commodity_status { Cats::Core::Commodity::GOOD }
12
12
  stack_status { Cats::Core::Stack::RESERVED }
13
13
  quantity { 100 }
14
+ unit { commodity.package_unit }
14
15
  end
15
16
  end