cats_core 1.0.30 → 1.0.34

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: 0e916c12f4c3ac194aee51c1692ddba4484e234e64f020565d72e4bea7081c4e
4
- data.tar.gz: 28e582506d6bbbca6e33bc3f84bc698f9652e3f57684b4c14f15722e0f65ff7f
3
+ metadata.gz: 5f642691ce490f46cc23534f368644b7bd6cc2069736cae534994aafb8018d40
4
+ data.tar.gz: a3967aca1998cf19cbfa55af249e8023c664bb4066bb0c40224a209225584485
5
5
  SHA512:
6
- metadata.gz: d3baf1a07032560ee3136ff454fb4ab21db27d17afdd8eeabe826b4d49c811d261f0a7880c4ae80bafabe03d66ab8a0b699a49fe66fd123a5618b1d3c9dcd285
7
- data.tar.gz: f2633626ae8ba4c082618c0406657e0b4378af44d97c5416b329326aaf3dd77584b095541cd257b12698df525ab235b165f147a814dcbf3ca2049869e07a30e0
6
+ metadata.gz: 8147dfe37fbe8ad5c1ae9e3945b71936e5c0c135a00633fba2c9e3f1a6aeac4ce482d3f4d81e965c0a3cb00d8ac9bec58033b2d8c418a750f9b68b63c61c4788
7
+ data.tar.gz: d501edb9668b0372c6c6a91092619d467379083cc7c7ef3201856a43f1a53abcb5dcd0a97411d7e083ba8771f9ea66235213b283f5cdac64d870142bc1635840
@@ -0,0 +1,49 @@
1
+ module Cats
2
+ module Core
3
+ class UnitOfMeasuresController < ApplicationController
4
+ before_action :set_unit_of_measure, only: %i[show update]
5
+
6
+ def index
7
+ data = ActiveModelSerializers::SerializableResource.new(Cats::Core::UnitOfMeasure.all)
8
+ render json: { success: true, data: data }
9
+ end
10
+
11
+ def show
12
+ data = ActiveModelSerializers::SerializableResource.new(@unit_of_measure)
13
+ render json: { success: true, data: data }
14
+ end
15
+
16
+ def create
17
+ obj = Cats::Core::UnitOfMeasure.new(model_params)
18
+ if obj.save
19
+ data = ActiveModelSerializers::SerializableResource.new(obj)
20
+ render json: { success: true, data: data }, status: :created
21
+ else
22
+ render json: { success: false, error: obj.errors.full_messages[0] }, status: :unprocessable_entity
23
+ end
24
+ end
25
+
26
+ def update
27
+ if @unit_of_measure.update(model_params)
28
+ data = ActiveModelSerializers::SerializableResource.new(@unit_of_measure)
29
+ render json: { success: true, data: data }
30
+ else
31
+ render json: {
32
+ success: false,
33
+ error: @unit_of_measure.errors.full_messages[0]
34
+ }, status: :unprocessable_entity
35
+ end
36
+ end
37
+
38
+ private
39
+
40
+ def set_unit_of_measure
41
+ @unit_of_measure = Cats::Core::UnitOfMeasure.find(params[:id])
42
+ end
43
+
44
+ def model_params
45
+ params.require(:payload).permit(:abbreviation, :name, :unit_type)
46
+ end
47
+ end
48
+ end
49
+ end
@@ -6,12 +6,14 @@ module Cats
6
6
  belongs_to :source, class_name: 'Cats::Core::Location'
7
7
 
8
8
  validates :commodity_status, presence: true
9
+ validates :reference_no, presence: true, uniqueness: true
9
10
  validates :quantity, presence: true, numericality: { greater_than: 0 }
10
11
  validates :commodity_status, inclusion: { in: Cats::Core::Commodity::COMMODITY_STATUSES }
11
12
 
12
13
  delegate(:reference_no, to: :rhn_request, prefix: :rhn, allow_nil: true)
13
14
  delegate(:batch_no, to: :commodity, prefix: true)
14
15
  delegate(:name, to: :source, prefix: true)
16
+ delegate(:location_type, to: :source, prefix: true)
15
17
  end
16
18
  end
17
19
  end
@@ -13,6 +13,10 @@ module Cats
13
13
 
14
14
  errors.add(:base, 'source and destination cannot be the same') if allocation.source == destination
15
15
  end
16
+
17
+ delegate(:name, to: :destination, prefix: true)
18
+ delegate(:reference_no, to: :allocation, prefix: true)
19
+ delegate(:location_type, to: :destination, prefix: true)
16
20
  end
17
21
  end
18
22
  end
@@ -5,6 +5,8 @@ module Cats
5
5
 
6
6
  validates :reference_no, :request_date, presence: true
7
7
  validates :reference_no, uniqueness: true
8
+
9
+ delegate(:batch_no, to: :commodity, prefix: true)
8
10
  end
9
11
  end
10
12
  end
@@ -22,6 +22,8 @@ module Cats
22
22
  validate :validate_coordinates, :validate_dimensions, :validate_distance_from_wall, :validate_overlap,
23
23
  :validate_space_between_stack
24
24
 
25
+ after_save :update_store_space
26
+
25
27
  def validate_coordinates
26
28
  return unless store.present? && length.present? && width.present? && start_x.present? && start_y.present?
27
29
 
@@ -99,6 +101,21 @@ module Cats
99
101
 
100
102
  true
101
103
  end
104
+
105
+ def update_store_space
106
+ return unless length_previously_changed? || width_previously_changed? || stack_status_previously_changed?
107
+
108
+ old_area = if length_previously_was.nil? && width_previously_was.nil?
109
+ 0
110
+ else
111
+ length_previously_was * width_previously_was
112
+ end
113
+
114
+ store.available_space += old_area
115
+ store.available_space -= length * width unless stack_status == DESTROYED
116
+
117
+ store.save
118
+ end
102
119
  end
103
120
  end
104
121
  end
@@ -15,6 +15,7 @@ module Cats
15
15
  allow_nil: true
16
16
  validate :validate_location
17
17
 
18
+ before_create :update_usable_space
18
19
  after_save :update_store_keeper
19
20
 
20
21
  def validate_location
@@ -27,6 +28,12 @@ module Cats
27
28
  "#{store_keeper.first_name} #{store_keeper.last_name}"
28
29
  end
29
30
 
31
+ def update_usable_space
32
+ self.usable_space = (length - 2) * (width - 2)
33
+ self.usable_space -= (gangway_length * gangway_width) if has_gangway
34
+ self.available_space = self.usable_space
35
+ end
36
+
30
37
  def update_store_keeper
31
38
  return unless store_keeper_id_previously_changed?
32
39
 
@@ -0,0 +1,3 @@
1
+ class UnitOfMeasureSerializer < ActiveModel::Serializer
2
+ attributes :id, :abbreviation, :name, :unit_type
3
+ end
data/config/routes.rb CHANGED
@@ -34,4 +34,5 @@ Cats::Core::Engine.routes.draw do
34
34
  end
35
35
  end
36
36
  resources :currencies, except: %i[destroy]
37
+ resources :unit_of_measures, except: %i[destroy]
37
38
  end
@@ -5,6 +5,8 @@ class CreateCatsCoreStores < ActiveRecord::Migration[6.1]
5
5
  t.float :length, null: false
6
6
  t.float :width, null: false
7
7
  t.float :height, null: false
8
+ t.float :usable_space, null: false
9
+ t.float :available_space, null: false
8
10
  t.boolean :temporary, null: false, default: false
9
11
  t.boolean :has_gangway, null: false, default: false
10
12
  t.float :gangway_length
@@ -1,6 +1,7 @@
1
1
  class CreateCatsCoreAllocations < ActiveRecord::Migration[6.1]
2
2
  def change
3
3
  create_table :cats_core_allocations do |t|
4
+ t.string :reference_no, unique: true
4
5
  t.references :rhn_request,
5
6
  null: true,
6
7
  index: { name: 'rr_on_allocation_indx' },
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = '1.0.30'.freeze
3
+ VERSION = '1.0.34'.freeze
4
4
  end
5
5
  end
@@ -1,5 +1,6 @@
1
1
  FactoryBot.define do
2
2
  factory :allocation, class: 'Cats::Core::Allocation' do
3
+ reference_no { FFaker::Name.name }
3
4
  rhn_request { nil }
4
5
  commodity
5
6
  source factory: :location
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.0.30
4
+ version: 1.0.34
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henock L.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-09 00:00:00.000000000 Z
11
+ date: 2021-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers
@@ -224,6 +224,7 @@ files:
224
224
  - app/controllers/cats/core/menus_controller.rb
225
225
  - app/controllers/cats/core/notifications_controller.rb
226
226
  - app/controllers/cats/core/roles_controller.rb
227
+ - app/controllers/cats/core/unit_of_measures_controller.rb
227
228
  - app/controllers/cats/core/users_controller.rb
228
229
  - app/jobs/cats/core/application_job.rb
229
230
  - app/models/cats/core/allocation.rb
@@ -267,6 +268,7 @@ files:
267
268
  - app/serializers/cats/core/currency_serializer.rb
268
269
  - app/serializers/cats/core/location_serializer.rb
269
270
  - app/serializers/cats/core/role_menu_serializer.rb
271
+ - app/serializers/cats/core/unit_of_measure_serializer.rb
270
272
  - app/services/cats/core/menu_service.rb
271
273
  - app/services/cats/core/notification_service.rb
272
274
  - app/services/cats/core/token_auth_service.rb