cats_core 1.0.20 → 1.0.24

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1e43803d54552bb7ba268834f78d698a473b0228e72d84f368840376b455c676
4
- data.tar.gz: f66be9d90ee324a3b986534137e68010c47451fcbf7a64143afa15b369b0a979
3
+ metadata.gz: 42be12240a7c83fb5885cf25ae71c6926078e982975b6b07d9a3b60cc5c355c3
4
+ data.tar.gz: 7479ddfee27ddc4f2e7de0b4f40b8efd3e218026cb51ba3bbeb9ea77f8b2ade8
5
5
  SHA512:
6
- metadata.gz: fca03d960014c11e58d50b5feb9448e8225bf0ff669e55c851d30b2673ec9aa68bdf9be47274a7c0b04b705108e5fce20d6e17806f2e9b287d2c3411548155cd
7
- data.tar.gz: c2e9e3fc5caf396c90091e246cd235acfaad8991ff0345d24aec4e568319d2202e73e4b726cd52c866b8fb98c62bea98fc5b8d7d619512a73bb13cb855a64fd9
6
+ metadata.gz: 3640d304c753328131f660578553eda3bfc50fb98e955a86b35eca4fa3efff58fbe069dcddce891001a566069dc2f3da48a361adb577fbf71a9cca96d56b1f60
7
+ data.tar.gz: 85786685e2667ac62d0f73d793c78efcbe3c5bebe18524d1c6402acc5188cf60670f0dbfabc9f5229ef4bf3941907c918433bb713758b7077bfe21f62dc06123
@@ -0,0 +1,55 @@
1
+ module Cats
2
+ module Core
3
+ class CommodityCategoriesController < ApplicationController
4
+ before_action :set_commodity_category, only: %i[show update]
5
+
6
+ def index
7
+ commodity_categories = Cats::Core::CommodityCategory.all.reject(&:has_children?)
8
+ data = ActiveModelSerializers::SerializableResource.new(commodity_categories)
9
+ render json: { success: true, data: data }
10
+ end
11
+
12
+ def show
13
+ data = ActiveModelSerializers::SerializableResource.new(@commodity_category)
14
+ render json: { success: true, data: data }
15
+ end
16
+
17
+ def children
18
+ parent = Cats::Core::CommodityCategory.find(params[:id])
19
+ data = ActiveModelSerializers::SerializableResource.new(parent.children)
20
+ render json: { success: true, data: data }
21
+ end
22
+
23
+ def create
24
+ obj = Cats::Core::CommodityCategory.new(model_params)
25
+ if obj.save
26
+ data = ActiveModelSerializers::SerializableResource.new(obj)
27
+ render json: { success: true, data: data }, status: :created
28
+ else
29
+ render json: { success: false, error: obj.errors.full_messages[0] }, status: :unprocessable_entity
30
+ end
31
+ end
32
+
33
+ def update
34
+ if @commodity_category.update(model_params)
35
+ data = ActiveModelSerializers::SerializableResource.new(@commodity_category)
36
+ render json: { success: true, data: data }
37
+ else
38
+ render json: {
39
+ success: false, error: @commodity_category.errors.full_messages[0]
40
+ }, status: :unprocessable_entity
41
+ end
42
+ end
43
+
44
+ private
45
+
46
+ def set_commodity_category
47
+ @commodity_category = Cats::Core::CommodityCategory.find(params[:id])
48
+ end
49
+
50
+ def model_params
51
+ params.require('payload').permit(:code, :name, :description, :parent_id)
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,46 @@
1
+ module Cats
2
+ module Core
3
+ class CurrenciesController < ApplicationController
4
+ before_action :set_currency, only: %i[show update]
5
+
6
+ def index
7
+ data = ActiveModelSerializers::SerializableResource.new(Cats::Core::Currency.all)
8
+ render json: { success: true, data: data }
9
+ end
10
+
11
+ def show
12
+ data = ActiveModelSerializers::SerializableResource.new(@currency)
13
+ render json: { success: true, data: data }
14
+ end
15
+
16
+ def create
17
+ obj = Cats::Core::Currency.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 @currency.update(model_params)
28
+ data = ActiveModelSerializers::SerializableResource.new(@currency)
29
+ render json: { success: true, data: data }
30
+ else
31
+ render json: { success: false, error: @currency.errors.full_messages[0] }, status: :unprocessable_entity
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ def set_currency
38
+ @currency = Cats::Core::Currency.find(params[:id])
39
+ end
40
+
41
+ def model_params
42
+ params.require(:payload).permit(:code, :name)
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,53 @@
1
+ module Cats
2
+ module Core
3
+ class LocationsController < ApplicationController
4
+ before_action :set_location, only: %i[show update]
5
+
6
+ def index
7
+ locations = Cats::Core::Location.where(location_type: params[:location_type])
8
+ data = ActiveModelSerializers::SerializableResource.new(locations)
9
+ render json: { success: true, data: data }
10
+ end
11
+
12
+ def show
13
+ data = ActiveModelSerializers::SerializableResource.new(@location)
14
+ render json: { success: true, data: data }
15
+ end
16
+
17
+ def children
18
+ parent = Cats::Core::Location.find(params[:id])
19
+ data = ActiveModelSerializers::SerializableResource.new(parent.children)
20
+ render json: { success: true, data: data }
21
+ end
22
+
23
+ def create
24
+ obj = Cats::Core::Location.new(model_params)
25
+ if obj.save
26
+ data = ActiveModelSerializers::SerializableResource.new(obj)
27
+ render json: { success: true, data: data }, status: :created
28
+ else
29
+ render json: { success: false, error: obj.errors.full_messages[0] }, status: :unprocessable_entity
30
+ end
31
+ end
32
+
33
+ def update
34
+ if @location.update(model_params)
35
+ data = ActiveModelSerializers::SerializableResource.new(@location)
36
+ render json: { success: true, data: data }
37
+ else
38
+ render json: { success: false, error: @location.errors.full_messages[0] }, status: :unprocessable_entity
39
+ end
40
+ end
41
+
42
+ private
43
+
44
+ def set_location
45
+ @location = Cats::Core::Location.find(params[:id])
46
+ end
47
+
48
+ def model_params
49
+ params.require(:payload).permit(:name, :location_type, :description, :parent_id)
50
+ end
51
+ end
52
+ end
53
+ end
@@ -6,12 +6,20 @@ module Cats
6
6
  DAMAGED = 'Damaged'.freeze
7
7
  COMMODITY_STATUSES = [GOOD, DAMAGED].freeze
8
8
 
9
+ # Arrival Statuses
10
+ AT_SOURCE = 'At Source'.freeze
11
+ IN_TRANSIT = 'In Transit'.freeze
12
+ ARRIVED = 'Arrived'.freeze
13
+ ARRIVAL_STATUSES = [AT_SOURCE, IN_TRANSIT, ARRIVED].freeze
14
+
9
15
  belongs_to :unit_of_measure
10
16
  belongs_to :source, polymorphic: true
11
17
 
12
18
  validates :best_use_before, presence: true
19
+ validates :batch_no, presence: true, uniqueness: true
13
20
  validates :quantity, presence: true, numericality: { greater_than: 0 }
14
21
  validates :volume_per_metric_ton, numericality: { greater_than: 0, allow_nil: true }
22
+ validates :arrival_status, presence: true, inclusion: { in: ARRIVAL_STATUSES }
15
23
  end
16
24
  end
17
25
  end
@@ -1,6 +1,8 @@
1
1
  module Cats
2
2
  module Core
3
3
  class CommodityCategory < ApplicationRecord
4
+ has_ancestry
5
+
4
6
  validates :code, presence: true, uniqueness: true
5
7
  validates :name, presence: true
6
8
  end
@@ -13,6 +13,9 @@ module Cats
13
13
  validates :reference_no, uniqueness: true
14
14
  validates :donation_type, inclusion: { in: DONATION_TYPES }
15
15
  validates :currency, :amount, presence: true, if: -> { donation_type == CASH }
16
+
17
+ delegate(:name, to: :donor, prefix: true)
18
+ delegate(:reference_no, to: :hrp, prefix: true)
16
19
  end
17
20
  end
18
21
  end
@@ -6,6 +6,8 @@ module Cats
6
6
 
7
7
  validates :reference_no, presence: true, uniqueness: true
8
8
  validates :gift_date, presence: true
9
+
10
+ delegate(:name, to: :commodity_category, prefix: true)
9
11
  end
10
12
  end
11
13
  end
@@ -8,6 +8,9 @@ module Cats
8
8
  validates :beneficiaries, presence: true, numericality: { greater_than: 0 }
9
9
  validates :commodity_amount, presence: true, numericality: { greater_than: 0 }
10
10
  validates :hrp_id, uniqueness: { scope: :woreda_id }
11
+
12
+ delegate(:name, to: :woreda, prefix: true)
13
+ delegate(:name, to: :operator, prefix: true)
11
14
  end
12
15
  end
13
16
  end
@@ -6,6 +6,8 @@ module Cats
6
6
 
7
7
  validates :reference_no, :order_date, :supplier, presence: true
8
8
  validates :reference_no, uniqueness: true
9
+
10
+ delegate(:name, to: :commodity_category, prefix: true)
9
11
  end
10
12
  end
11
13
  end
@@ -0,0 +1,3 @@
1
+ class CommodityCategorySerializer < ActiveModel::Serializer
2
+ attributes :id, :code, :name, :description, :parent_id
3
+ end
@@ -0,0 +1,3 @@
1
+ class CurrencySerializer < ActiveModel::Serializer
2
+ attributes :id, :code, :name
3
+ end
@@ -0,0 +1,3 @@
1
+ class LocationSerializer < ActiveModel::Serializer
2
+ attributes :id, :name, :location_type, :description, :parent_id
3
+ end
data/config/routes.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  Cats::Core::Engine.routes.draw do
2
+ get 'locations/index'
3
+ get 'locations/children'
2
4
  post '/login', controller: :access, action: :login
3
5
  get '/notifications/unread', controller: :notifications, action: :unread
4
6
  get '/notifications/read', controller: :notifications, action: :read
@@ -21,4 +23,15 @@ Cats::Core::Engine.routes.draw do
21
23
  get 'warehouses', controller: :users, action: :warehouses
22
24
  end
23
25
  end
26
+ resources :locations, except: %i[destroy] do
27
+ member do
28
+ get 'children'
29
+ end
30
+ end
31
+ resources :commodity_categories, except: %i[destroy] do
32
+ member do
33
+ get 'children'
34
+ end
35
+ end
36
+ resources :currencies, except: %i[destroy]
24
37
  end
@@ -1,6 +1,7 @@
1
1
  class CreateCatsCoreCommodities < ActiveRecord::Migration[6.1]
2
2
  def change
3
3
  create_table :cats_core_commodities do |t|
4
+ t.string :batch_no, unique: true
4
5
  t.references :unit_of_measure,
5
6
  null: false,
6
7
  index: { name: 'uom_on_commodities_indx' },
@@ -10,6 +11,7 @@ class CreateCatsCoreCommodities < ActiveRecord::Migration[6.1]
10
11
  t.string :description
11
12
  t.date :best_use_before, null: false
12
13
  t.float :volume_per_metric_ton
14
+ t.string :arrival_status, null: false, default: 'At Source'
13
15
 
14
16
  t.timestamps
15
17
  end
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = '1.0.20'.freeze
3
+ VERSION = '1.0.24'.freeze
4
4
  end
5
5
  end
@@ -1,10 +1,12 @@
1
1
  FactoryBot.define do
2
2
  factory :commodity, class: 'Cats::Core::Commodity' do
3
+ batch_no { FFaker::Name.name }
3
4
  description { FFaker::Name.name }
4
5
  unit_of_measure
5
6
  source factory: :gift_certificate
6
7
  quantity { 100 }
7
8
  best_use_before { Date.today + 2.month }
8
9
  volume_per_metric_ton { 10 }
10
+ arrival_status { Cats::Core::Commodity::AT_SOURCE }
9
11
  end
10
12
  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.0.20
4
+ version: 1.0.24
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-04 00:00:00.000000000 Z
11
+ date: 2021-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers
@@ -218,6 +218,9 @@ files:
218
218
  - Rakefile
219
219
  - app/controllers/cats/core/access_controller.rb
220
220
  - app/controllers/cats/core/application_controller.rb
221
+ - app/controllers/cats/core/commodity_categories_controller.rb
222
+ - app/controllers/cats/core/currencies_controller.rb
223
+ - app/controllers/cats/core/locations_controller.rb
221
224
  - app/controllers/cats/core/menus_controller.rb
222
225
  - app/controllers/cats/core/notifications_controller.rb
223
226
  - app/controllers/cats/core/roles_controller.rb
@@ -258,6 +261,9 @@ files:
258
261
  - app/models/cats/core/unit_of_measure.rb
259
262
  - app/models/cats/core/user.rb
260
263
  - app/notifications/cats/core/simple_notification.rb
264
+ - app/serializers/cats/core/commodity_category_serializer.rb
265
+ - app/serializers/cats/core/currency_serializer.rb
266
+ - app/serializers/cats/core/location_serializer.rb
261
267
  - app/serializers/cats/core/role_menu_serializer.rb
262
268
  - app/services/cats/core/menu_service.rb
263
269
  - app/services/cats/core/notification_service.rb