cats_core 1.1.12 → 1.1.16

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: 94bf88876f024323ea55e55b6a01fe74af037d2dda21c0c673d969e603d4d3ff
4
- data.tar.gz: 865354149f6c009cec575207990fd8c5b47bbf002e5a884f6a2dd717886ba1d8
3
+ metadata.gz: b5e9151667e330955db4a89a8bf0bdd3d00c297859866ed57aeb763cbcbc48d4
4
+ data.tar.gz: 903b632addec26d908e48b14b06773fc9757b247c50ea8598dd0932a0714ad8f
5
5
  SHA512:
6
- metadata.gz: 20da152cd17a483350c82d530d24e09489b0b85a2150752b3bd008902346364cc8cd506dcd8c3c4306558ec47be7a34b5c4215e5bbba7772173b0a1d120ea42f
7
- data.tar.gz: 5ef09f36850fcc7a1ce7af5bb5f584d4fe6c1245edc0df3ed1226985fb38e493ac9589036d749b98cdb2db75413fc68356538b1c4035ace11368504dc4bc339d
6
+ metadata.gz: aab3a1d980859f6660fa0dc49c8d13cf41beb586ea0a74599e2ff94a3ec7be22fe21c65b039c706b37bd79b8b9c0827abe723f59d978a10628e03ad7b26f5d9a
7
+ data.tar.gz: 6ddf1fbdccd9781098d4ac2f9d3bb42b89d2129bd620c194da91c6508302a19da84aafe3ed2036adee6df36259914cb7e3fa3773c7383cc63fd953436ade2497
@@ -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
 
@@ -8,6 +8,7 @@ module Cats
8
8
  belongs_to :rhn_request, optional: true
9
9
  belongs_to :commodity
10
10
  belongs_to :source, class_name: 'Cats::Core::Location'
11
+ has_many :allocation_items
11
12
 
12
13
  validates :commodity_status, :allocation_status, presence: true
13
14
  validates :reference_no, presence: true, uniqueness: true
@@ -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_save :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.12'.freeze
3
+ VERSION = '1.1.16'.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.12
4
+ version: 1.1.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henock L.