cats_core 1.0.21 → 1.0.25
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 +4 -4
- data/app/controllers/cats/core/currencies_controller.rb +46 -0
- data/app/controllers/cats/core/locations_controller.rb +1 -1
- data/app/models/cats/core/commodity.rb +16 -0
- data/app/models/cats/core/donation.rb +3 -0
- data/app/models/cats/core/gift_certificate.rb +2 -0
- data/app/models/cats/core/purchase_order.rb +2 -0
- data/app/serializers/cats/core/currency_serializer.rb +3 -0
- data/config/routes.rb +1 -0
- data/db/migrate/20210717033223_create_cats_core_commodities.rb +3 -0
- data/lib/cats/core/version.rb +1 -1
- data/spec/factories/cats/core/commodities.rb +3 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b4daffc3ad671e1f4b955ec649f6186cc8048ffc0a74972292e2b745460b28c
|
4
|
+
data.tar.gz: a75cb602fd8859e7e39f064212cee3daafc6a8dfda04247614d2608058433183
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43c85afb0693fb6158597758b1a8399e6490b7fdcaf7291dda9304e02be716aab33e25f02408539a46e5b3c3adddd746e9a94ed14754999ec51048c411408041
|
7
|
+
data.tar.gz: d7dc26e79aafdf1429fc0d1a40a988f9608c6db56c137cc2a46cfdeb630fa957882329fc1cca0df8dd9396651b2dcd372193eb75129d0d743da6df3e10efc961
|
@@ -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
|
@@ -1,17 +1,33 @@
|
|
1
1
|
module Cats
|
2
2
|
module Core
|
3
3
|
class Commodity < ApplicationRecord
|
4
|
+
after_initialize :set_approved
|
5
|
+
|
4
6
|
# Commodity statuses
|
5
7
|
GOOD = 'Good'.freeze
|
6
8
|
DAMAGED = 'Damaged'.freeze
|
7
9
|
COMMODITY_STATUSES = [GOOD, DAMAGED].freeze
|
8
10
|
|
11
|
+
# Arrival Statuses
|
12
|
+
AT_SOURCE = 'At Source'.freeze
|
13
|
+
IN_TRANSIT = 'In Transit'.freeze
|
14
|
+
ARRIVED = 'Arrived'.freeze
|
15
|
+
ARRIVAL_STATUSES = [AT_SOURCE, IN_TRANSIT, ARRIVED].freeze
|
16
|
+
|
9
17
|
belongs_to :unit_of_measure
|
10
18
|
belongs_to :source, polymorphic: true
|
11
19
|
|
12
20
|
validates :best_use_before, presence: true
|
21
|
+
validates :batch_no, presence: true, uniqueness: true
|
13
22
|
validates :quantity, presence: true, numericality: { greater_than: 0 }
|
14
23
|
validates :volume_per_metric_ton, numericality: { greater_than: 0, allow_nil: true }
|
24
|
+
validates :arrival_status, presence: true, inclusion: { in: ARRIVAL_STATUSES }
|
25
|
+
|
26
|
+
def set_approved
|
27
|
+
return unless new_record?
|
28
|
+
|
29
|
+
self.approved = false
|
30
|
+
end
|
15
31
|
end
|
16
32
|
end
|
17
33
|
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
|
data/config/routes.rb
CHANGED
@@ -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,8 @@ 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'
|
15
|
+
t.boolean :approved, null: false, default: false
|
13
16
|
|
14
17
|
t.timestamps
|
15
18
|
end
|
data/lib/cats/core/version.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
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 }
|
11
|
+
approved { false }
|
9
12
|
end
|
10
13
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cats_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.25
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henock L.
|
@@ -219,6 +219,7 @@ files:
|
|
219
219
|
- app/controllers/cats/core/access_controller.rb
|
220
220
|
- app/controllers/cats/core/application_controller.rb
|
221
221
|
- app/controllers/cats/core/commodity_categories_controller.rb
|
222
|
+
- app/controllers/cats/core/currencies_controller.rb
|
222
223
|
- app/controllers/cats/core/locations_controller.rb
|
223
224
|
- app/controllers/cats/core/menus_controller.rb
|
224
225
|
- app/controllers/cats/core/notifications_controller.rb
|
@@ -261,6 +262,7 @@ files:
|
|
261
262
|
- app/models/cats/core/user.rb
|
262
263
|
- app/notifications/cats/core/simple_notification.rb
|
263
264
|
- app/serializers/cats/core/commodity_category_serializer.rb
|
265
|
+
- app/serializers/cats/core/currency_serializer.rb
|
264
266
|
- app/serializers/cats/core/location_serializer.rb
|
265
267
|
- app/serializers/cats/core/role_menu_serializer.rb
|
266
268
|
- app/services/cats/core/menu_service.rb
|