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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fc104d1c83591c9db1a70f89044e124322826738e56a7803c5ae0487421e3f17
4
- data.tar.gz: 4f80cded8f41799a6d77c87f8c920db0eb3ca86f8bad20a230a246ef35a667ca
3
+ metadata.gz: 3b4daffc3ad671e1f4b955ec649f6186cc8048ffc0a74972292e2b745460b28c
4
+ data.tar.gz: a75cb602fd8859e7e39f064212cee3daafc6a8dfda04247614d2608058433183
5
5
  SHA512:
6
- metadata.gz: 067a3510964611f5ab157eb661613082148bbd27b55ce0bd8cf89bea7a6d582099f0f17e44e7b31434acafcff2c68660da58e300c21d381a675a8d38be6c0dec
7
- data.tar.gz: b5068dda8fa207fbaa39282fa106c63a84e291777900c660e177b12ca5709059ef2d9c479ed239ea3a08b924b102846d6e5d944bdbe0a69c3d17a53a20c0f04b
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
@@ -46,7 +46,7 @@ module Cats
46
46
  end
47
47
 
48
48
  def model_params
49
- params.require('payload').permit(:name, :location_type, :description, :parent_id)
49
+ params.require(:payload).permit(:name, :location_type, :description, :parent_id)
50
50
  end
51
51
  end
52
52
  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
@@ -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
@@ -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 CurrencySerializer < ActiveModel::Serializer
2
+ attributes :id, :code, :name
3
+ end
data/config/routes.rb CHANGED
@@ -33,4 +33,5 @@ Cats::Core::Engine.routes.draw do
33
33
  get 'children'
34
34
  end
35
35
  end
36
+ resources :currencies, except: %i[destroy]
36
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,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
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = '1.0.21'.freeze
3
+ VERSION = '1.0.25'.freeze
4
4
  end
5
5
  end
@@ -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.21
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