cats_core 1.1.11 → 1.1.15

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: bbc34455b593fd71880ccf827b6d2e3c9aea723471d877780d4f44b18297cb92
4
- data.tar.gz: f2867e4a074fe84990e005a845844f06a3433e6fed52d9e56f12eb5943c061ed
3
+ metadata.gz: 9c73eb407823b6e404e576cd94dd8ac14228db71edce2fab923be1fc4a76752a
4
+ data.tar.gz: 43743939e2a9b6f3aaa3f27c5898e52619d7c00ec36896cd2d4c587a90ead623
5
5
  SHA512:
6
- metadata.gz: 13a7abd31cdaa640da8486fb394b7896e919c79229233fdee4f8fd5ebae5498f55987ba72f30189486812a9273be8efe4e246cd2bd9d410f32996bee1deff037
7
- data.tar.gz: e9dafd860e39d9751a6ddade1adf4d6df4373c37c38f4e267ed2056b1eef7e756a1a29b4b44d62907329348e1a8d8e8d7998e4bd92d78baf2564e6ffc0daf7a6
6
+ metadata.gz: 224e70bc25588e883cdc642db7e85dfb18c2389a9f147ada262a3891feedaf595f827fe28fb8c092449ef2ec7f3c70c8dff4a7f20891fb4d5756ec61e363a2f8
7
+ data.tar.gz: 9eaf7c258dcf29107a7ec15c6db97c088dfa5569a3ceabcccd4c179f82c6edecc7e231139c403abe52577cea6153795ea0723eaab91d821c9b4726ccfe1c3399
@@ -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,14 @@ 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
+ before_save :set_commodity_category
9
13
  after_create :update_donation
10
14
 
11
15
  def update_donation
@@ -15,6 +19,14 @@ module Cats
15
19
  donation.active = true
16
20
  donation.save!
17
21
  end
22
+
23
+ def set_commodity_category
24
+ return unless donation
25
+
26
+ return if commodity_category == donation.commodity_category
27
+
28
+ self.commodity_category = donation.commodity_category
29
+ end
18
30
  end
19
31
  end
20
32
  end
@@ -0,0 +1,8 @@
1
+ module Cats
2
+ module Core
3
+ class NotificationRule < ApplicationRecord
4
+ validates :code, :roles, presence: true
5
+ validates :code, uniqueness: true
6
+ end
7
+ end
8
+ 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
@@ -0,0 +1,10 @@
1
+ class CreateCatsCoreNotificationRules < ActiveRecord::Migration[6.1]
2
+ def change
3
+ create_table :cats_core_notification_rules do |t|
4
+ t.string :code, unique: true
5
+ t.string :roles, array: true, null: false
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = '1.1.11'.freeze
3
+ VERSION = '1.1.15'.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
@@ -0,0 +1,6 @@
1
+ FactoryBot.define do
2
+ factory :notification_rule, class: 'Cats::Core::NotificationRule' do
3
+ code { FFaker::Name.name }
4
+ roles { %i[role1 role2] }
5
+ end
6
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cats_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.11
4
+ version: 1.1.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henock L.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-30 00:00:00.000000000 Z
11
+ date: 2021-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers
@@ -266,6 +266,7 @@ files:
266
266
  - app/models/cats/core/menu.rb
267
267
  - app/models/cats/core/menu_item.rb
268
268
  - app/models/cats/core/notification.rb
269
+ - app/models/cats/core/notification_rule.rb
269
270
  - app/models/cats/core/operator.rb
270
271
  - app/models/cats/core/program.rb
271
272
  - app/models/cats/core/purchase_order.rb
@@ -339,6 +340,7 @@ files:
339
340
  - db/migrate/20210727074646_create_cats_core_receipts.rb
340
341
  - db/migrate/20210814160628_create_cats_core_receipt_transactions.rb
341
342
  - db/migrate/20210814175406_create_cats_core_stack_transactions.rb
343
+ - db/migrate/20211002050739_create_cats_core_notification_rules.rb
342
344
  - lib/cats/core.rb
343
345
  - lib/cats/core/engine.rb
344
346
  - lib/cats/core/version.rb
@@ -361,6 +363,7 @@ files:
361
363
  - spec/factories/cats/core/locations.rb
362
364
  - spec/factories/cats/core/menu_items.rb
363
365
  - spec/factories/cats/core/menus.rb
366
+ - spec/factories/cats/core/notification_rules.rb
364
367
  - spec/factories/cats/core/notifications.rb
365
368
  - spec/factories/cats/core/operators.rb
366
369
  - spec/factories/cats/core/programs.rb