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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b7f1333a43773f878d178ee7f3daad6af88994875ac5fc4584e4b8ebf3fb0c87
4
- data.tar.gz: c37663a1516cbc7847360a10efa6dfbf64d2f743b59beebc0916d0ec4b0766fd
3
+ metadata.gz: b3ab3c562deb4c4281588716e622326a2a81b09ccd0657e973e1fd9d5f3168b7
4
+ data.tar.gz: 4ec2d1f3ba28bbae43e058ebc1782ddaab27e4eaa6afdec20451a9ed247a6ce1
5
5
  SHA512:
6
- metadata.gz: 6b15f41ff65b916ae635fb575c95a24d6f7982fd79b517581f47f7cf09e50b9f90953df6b8d41e5776857807ee7cf480d9d7169365c57f5f4260ae73ea11620e
7
- data.tar.gz: 428f6deffeafecd95811843973aaae91567543b408955d556c35049f0cf94bc1b2addcd0a2e417728e7fd8cb5190ac8cdb930568570ae3ffa5f761189bf58732
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 warehouses]
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 warehouses
12
- data = ActiveModelSerializers::SerializableResource.new(@user.warehouses)
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 warehouses
17
- return unless details.key?('warehouses')
16
+ def warehouse
17
+ return unless details.key?('warehouse')
18
18
 
19
- Cats::Core::Location.where(id: details['warehouses'], location_type: Cats::Core::Location::WAREHOUSE)
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
- :commodity_category_id, :commodity_category_name, :arrival_status, :approved
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 'warehouses', controller: :users, action: :warehouses
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 :amount, null: false
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
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = '1.1.13'.freeze
3
+ VERSION = '1.1.17'.freeze
4
4
  end
5
5
  end
@@ -3,7 +3,6 @@ FactoryBot.define do
3
3
  batch_no { FFaker::Name.name }
4
4
  description { FFaker::Name.name }
5
5
  unit_of_measure
6
- commodity_category
7
6
  source factory: :gift_certificate
8
7
  quantity { 100 }
9
8
  best_use_before { Date.today + 2.month }
@@ -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
- amount { 1.5 }
14
+ quantity { 1.5 }
13
15
  estimated_price { 1.5 }
14
16
  estimated_tax { 1.5 }
15
17
  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.1.13
4
+ version: 1.1.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henock L.