cats_core 1.1.13 → 1.1.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/cats/core/users_controller.rb +8 -3
- data/app/models/cats/core/commodity.rb +4 -2
- data/app/models/cats/core/gift_certificate.rb +16 -1
- data/app/models/cats/core/user.rb +9 -3
- data/app/serializers/cats/core/commodity_serializer.rb +2 -2
- data/config/routes.rb +2 -1
- data/db/migrate/20210715114910_create_cats_core_users.rb +1 -1
- data/db/migrate/20210717032602_create_cats_core_gift_certificates.rb +9 -1
- data/db/migrate/20210717033223_create_cats_core_commodities.rb +0 -4
- data/lib/cats/core/version.rb +1 -1
- data/spec/factories/cats/core/commodities.rb +0 -1
- data/spec/factories/cats/core/gift_certificates.rb +3 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3ab3c562deb4c4281588716e622326a2a81b09ccd0657e973e1fd9d5f3168b7
|
4
|
+
data.tar.gz: 4ec2d1f3ba28bbae43e058ebc1782ddaab27e4eaa6afdec20451a9ed247a6ce1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6196b576ccdcef0d2bc9d9fdf2583e8fb613c017f95187743957e28f473d557a153b623b655e8ea2a3f9e017cbb4893d5db425c57bf42dd93b7f0ea5677aea1e
|
7
|
+
data.tar.gz: dad6bf9d11ab9aea1ee0e7e4d000a8ca09799088ea209f133b763b514a0fa8ae90dfc5e5a887b3704d8d9c40a900a60b2f66e70508526e3bdbe3d086e0cdd556
|
@@ -1,15 +1,20 @@
|
|
1
1
|
module Cats
|
2
2
|
module Core
|
3
3
|
class UsersController < ApplicationController
|
4
|
-
before_action :set_user, only: %i[stores
|
4
|
+
before_action :set_user, only: %i[stores warehouse hub]
|
5
5
|
|
6
6
|
def stores
|
7
7
|
data = ActiveModelSerializers::SerializableResource.new(@user.stores)
|
8
8
|
render json: { success: true, data: data }
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
12
|
-
data = ActiveModelSerializers::SerializableResource.new(@user.
|
11
|
+
def warehouse
|
12
|
+
data = ActiveModelSerializers::SerializableResource.new(@user.warehouse)
|
13
|
+
render json: { success: true, data: data }
|
14
|
+
end
|
15
|
+
|
16
|
+
def hub
|
17
|
+
data = ActiveModelSerializers::SerializableResource.new(@user.hub)
|
13
18
|
render json: { success: true, data: data }
|
14
19
|
end
|
15
20
|
|
@@ -16,7 +16,6 @@ module Cats
|
|
16
16
|
|
17
17
|
belongs_to :unit_of_measure
|
18
18
|
belongs_to :source, polymorphic: true
|
19
|
-
belongs_to :commodity_category
|
20
19
|
|
21
20
|
validates :best_use_before, presence: true
|
22
21
|
validates :batch_no, presence: true, uniqueness: true
|
@@ -25,7 +24,6 @@ module Cats
|
|
25
24
|
validates :arrival_status, presence: true, inclusion: { in: ARRIVAL_STATUSES }
|
26
25
|
|
27
26
|
delegate(:abbreviation, to: :unit_of_measure, prefix: true)
|
28
|
-
delegate(:name, to: :commodity_category, prefix: true)
|
29
27
|
delegate(:reference_no, to: :source, prefix: true)
|
30
28
|
|
31
29
|
def set_approved
|
@@ -33,6 +31,10 @@ module Cats
|
|
33
31
|
|
34
32
|
self.approved = false
|
35
33
|
end
|
34
|
+
|
35
|
+
def name
|
36
|
+
source.commodity_category.name
|
37
|
+
end
|
36
38
|
end
|
37
39
|
end
|
38
40
|
end
|
@@ -2,10 +2,17 @@ module Cats
|
|
2
2
|
module Core
|
3
3
|
class GiftCertificate < ApplicationRecord
|
4
4
|
belongs_to :donation
|
5
|
+
belongs_to :commodity_category
|
6
|
+
belongs_to :unit_of_measure
|
5
7
|
|
6
8
|
validates :reference_no, presence: true, uniqueness: true
|
7
|
-
validates :gift_date, presence: true
|
9
|
+
validates :gift_date, :quantity, presence: true
|
10
|
+
validates :quantity, numericality: { greater_than: 0 }
|
8
11
|
|
12
|
+
delegate(:name, to: :commodity_category, prefix: true)
|
13
|
+
delegate(:abbreviation, to: :unit_of_measure, prefix: true)
|
14
|
+
|
15
|
+
before_validation :set_commodity_category
|
9
16
|
after_create :update_donation
|
10
17
|
|
11
18
|
def update_donation
|
@@ -15,6 +22,14 @@ module Cats
|
|
15
22
|
donation.active = true
|
16
23
|
donation.save!
|
17
24
|
end
|
25
|
+
|
26
|
+
def set_commodity_category
|
27
|
+
return unless donation
|
28
|
+
|
29
|
+
return if commodity_category == donation.commodity_category
|
30
|
+
|
31
|
+
self.commodity_category = donation.commodity_category
|
32
|
+
end
|
18
33
|
end
|
19
34
|
end
|
20
35
|
end
|
@@ -13,10 +13,10 @@ module Cats
|
|
13
13
|
validates :email, uniqueness: true, format: { with: URI::MailTo::EMAIL_REGEXP }
|
14
14
|
validate :validate_phone_number
|
15
15
|
|
16
|
-
def
|
17
|
-
return unless details.key?('
|
16
|
+
def warehouse
|
17
|
+
return unless details.key?('warehouse')
|
18
18
|
|
19
|
-
Cats::Core::Location.
|
19
|
+
Cats::Core::Location.find_by(id: details['warehouse'], location_type: Cats::Core::Location::WAREHOUSE)
|
20
20
|
end
|
21
21
|
|
22
22
|
def stores
|
@@ -25,6 +25,12 @@ module Cats
|
|
25
25
|
Cats::Core::Store.where(id: details['stores'])
|
26
26
|
end
|
27
27
|
|
28
|
+
def hub
|
29
|
+
return unless details.key?('hub')
|
30
|
+
|
31
|
+
Cats::Core::Location.find_by(id: details['hub'], location_type: Cats::Core::Location::HUB)
|
32
|
+
end
|
33
|
+
|
28
34
|
def validate_phone_number
|
29
35
|
return unless phone_number.present?
|
30
36
|
|
@@ -1,9 +1,9 @@
|
|
1
1
|
module Cats
|
2
2
|
module Core
|
3
3
|
class CommoditySerializer < ActiveModel::Serializer
|
4
|
-
attributes :id, :batch_no, :description, :unit_of_measure_id, :unit_of_measure_abbreviation, :source_id,
|
4
|
+
attributes :id, :name, :batch_no, :description, :unit_of_measure_id, :unit_of_measure_abbreviation, :source_id,
|
5
5
|
:source_type, :source_reference_no, :quantity, :best_use_before, :volume_per_metric_ton,
|
6
|
-
:
|
6
|
+
:arrival_status, :approved
|
7
7
|
end
|
8
8
|
end
|
9
9
|
end
|
data/config/routes.rb
CHANGED
@@ -20,7 +20,8 @@ Cats::Core::Engine.routes.draw do
|
|
20
20
|
resources :users do
|
21
21
|
member do
|
22
22
|
get 'stores', controller: :users, action: :stores
|
23
|
-
get '
|
23
|
+
get 'warehouse', controller: :users, action: :warehouse
|
24
|
+
get 'hub', controller: :users, action: :hub
|
24
25
|
end
|
25
26
|
end
|
26
27
|
|
@@ -6,7 +6,7 @@ class CreateCatsCoreUsers < ActiveRecord::Migration[6.1]
|
|
6
6
|
t.string :email, unique: true
|
7
7
|
t.boolean :active, null: false, default: true
|
8
8
|
t.string :password_digest
|
9
|
-
t.jsonb :details
|
9
|
+
t.jsonb :details, null: false, default: {}
|
10
10
|
t.string :phone_number
|
11
11
|
t.references :application_module,
|
12
12
|
null: false,
|
@@ -15,7 +15,15 @@ class CreateCatsCoreGiftCertificates < ActiveRecord::Migration[6.1]
|
|
15
15
|
t.integer :purchase_year
|
16
16
|
t.date :expiry_date
|
17
17
|
t.string :bill_of_lading_no
|
18
|
-
t.float :
|
18
|
+
t.float :quantity, null: false
|
19
|
+
t.references :commodity_category,
|
20
|
+
null: false,
|
21
|
+
index: { name: 'gc_on_cc_indx' },
|
22
|
+
foreign_key: { to_table: :cats_core_commodity_categories }
|
23
|
+
t.references :unit_of_measure,
|
24
|
+
null: false,
|
25
|
+
index: { name: 'uom_on_gc_indx' },
|
26
|
+
foreign_key: { to_table: :cats_core_unit_of_measures }
|
19
27
|
t.float :estimated_price
|
20
28
|
t.float :estimated_tax
|
21
29
|
|
@@ -6,10 +6,6 @@ class CreateCatsCoreCommodities < ActiveRecord::Migration[6.1]
|
|
6
6
|
null: false,
|
7
7
|
index: { name: 'uom_on_commodities_indx' },
|
8
8
|
foreign_key: { to_table: :cats_core_unit_of_measures }
|
9
|
-
t.references :commodity_category,
|
10
|
-
null: false,
|
11
|
-
index: { name: 'cc_on_commodities_indx' },
|
12
|
-
foreign_key: { to_table: :cats_core_commodity_categories }
|
13
9
|
t.references :source, polymorphic: true
|
14
10
|
t.float :quantity, null: false
|
15
11
|
t.string :description
|
data/lib/cats/core/version.rb
CHANGED
@@ -3,13 +3,15 @@ FactoryBot.define do
|
|
3
3
|
reference_no { FFaker::Name.name }
|
4
4
|
gift_date { Date.today - 1.month }
|
5
5
|
donation
|
6
|
+
commodity_category { donation.commodity_category }
|
7
|
+
unit_of_measure
|
6
8
|
vessel { FFaker::Name.name }
|
7
9
|
port { FFaker::Name.name }
|
8
10
|
customs_declaration_no { FFaker::Name.name }
|
9
11
|
purchase_year { 1 }
|
10
12
|
expiry_date { Date.today + 6.month }
|
11
13
|
bill_of_lading_no { FFaker::Name.name }
|
12
|
-
|
14
|
+
quantity { 1.5 }
|
13
15
|
estimated_price { 1.5 }
|
14
16
|
estimated_tax { 1.5 }
|
15
17
|
end
|