snf_core 0.2.0 → 0.2.2
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 +4 -4
- data/app/models/snf_core/business.rb +11 -11
- data/app/models/snf_core/category.rb +7 -7
- data/app/models/snf_core/store_inventory.rb +24 -0
- data/app/models/snf_core/user.rb +10 -0
- data/app/models/snf_core/wallet.rb +21 -0
- data/db/migrate/20250226064444_create_snf_core_categories.rb +11 -11
- data/db/migrate/20250226080323_create_snf_core_businesses.rb +14 -14
- data/db/migrate/{20250226190655_create_snf_core_store_inventories.rb → 20250226190000_create_snf_core_store_inventories.rb} +4 -3
- data/db/migrate/20250227075048_create_snf_core_wallets.rb +14 -0
- data/db/migrate/20250227102833_modify_store_inventories.rb +7 -0
- data/lib/snf_core/version.rb +1 -1
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 107c2b4bcb53bb8c967d74d387c25cbb51b25fa6dec1f37c30d9ccee1d81eee9
|
4
|
+
data.tar.gz: 7263a0d543014d4e588ba7b876f872bbdb0b5c2b506d8fd3981a9eabd42f1fd4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c823bad5b8a31a97018a7a76bbc111300ac7883baa72aafd7f61ea2edf318c6f8c04ff561ed206cfafb870ef0efcb37103de9b911422aa379941caf95d372d13
|
7
|
+
data.tar.gz: 7ac8229fa5264eb80f1f60c61da558d0f769329422b6b494061df772ddff3344071eef5bd11ff498d64393681be27e6399c04a2d5cbd4d6f687826c76da8745c
|
@@ -1,11 +1,11 @@
|
|
1
|
-
module SnfCore
|
2
|
-
class Business < ApplicationRecord
|
3
|
-
belongs_to :user
|
4
|
-
|
5
|
-
validates :business_name, :tin_number, :business_type, :verification_status, presence: true
|
6
|
-
validates :tin_number, uniqueness: true
|
7
|
-
|
8
|
-
enum :business_type, { retailer: 0, wholesaler: 1 }
|
9
|
-
enum :verification_status, { pending: 0, approved: 1, rejected: 2 }
|
10
|
-
end
|
11
|
-
end
|
1
|
+
module SnfCore
|
2
|
+
class Business < ApplicationRecord
|
3
|
+
belongs_to :user
|
4
|
+
|
5
|
+
validates :business_name, :tin_number, :business_type, :verification_status, presence: true
|
6
|
+
validates :tin_number, uniqueness: true
|
7
|
+
|
8
|
+
enum :business_type, { retailer: 0, wholesaler: 1 }
|
9
|
+
enum :verification_status, { pending: 0, approved: 1, rejected: 2 }
|
10
|
+
end
|
11
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
module SnfCore
|
2
|
-
class Category < ApplicationRecord
|
3
|
-
belongs_to :parent, optional: true, class_name: "SnfCore::Category"
|
4
|
-
|
5
|
-
validates :name, presence: true, uniqueness: true
|
6
|
-
end
|
7
|
-
end
|
1
|
+
module SnfCore
|
2
|
+
class Category < ApplicationRecord
|
3
|
+
belongs_to :parent, optional: true, class_name: "SnfCore::Category"
|
4
|
+
|
5
|
+
validates :name, presence: true, uniqueness: true
|
6
|
+
end
|
7
|
+
end
|
@@ -2,5 +2,29 @@ module SnfCore
|
|
2
2
|
class StoreInventory < ApplicationRecord
|
3
3
|
belongs_to :store
|
4
4
|
belongs_to :product
|
5
|
+
|
6
|
+
enum :status, {
|
7
|
+
available: 0,
|
8
|
+
unavailable: 1
|
9
|
+
}
|
10
|
+
|
11
|
+
validates :status, presence: true
|
12
|
+
|
13
|
+
validates :base_price, presence: true, numericality: {
|
14
|
+
greater_than_or_equal_to: 0
|
15
|
+
}
|
16
|
+
|
17
|
+
validate :unique_store_product_combination
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def unique_store_product_combination
|
22
|
+
existing = StoreInventory.where(store_id: store_id, product_id: product_id)
|
23
|
+
existing = existing.where.not(id: id) if persisted?
|
24
|
+
|
25
|
+
if existing.exists?
|
26
|
+
errors.add(:base, "Product already exists in this store's inventory")
|
27
|
+
end
|
28
|
+
end
|
5
29
|
end
|
6
30
|
end
|
data/app/models/snf_core/user.rb
CHANGED
@@ -1,8 +1,18 @@
|
|
1
1
|
module SnfCore
|
2
2
|
class User < ApplicationRecord
|
3
|
+
has_one :wallet, dependent: :destroy
|
4
|
+
|
3
5
|
validates :first_name, :middle_name, :last_name, :phone_number, :role, presence: true
|
4
6
|
validates :phone_number, :email, uniqueness: true
|
5
7
|
|
6
8
|
enum :role, { admin: 0, wholesaler: 1, retailer: 2, consumer: 3 }
|
9
|
+
|
10
|
+
after_create :create_default_wallet
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def create_default_wallet
|
15
|
+
create_wallet(balance: 0.0, is_active: true)
|
16
|
+
end
|
7
17
|
end
|
8
18
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module SnfCore
|
2
|
+
class Wallet < ApplicationRecord
|
3
|
+
belongs_to :user
|
4
|
+
|
5
|
+
validates :wallet_number, :balance, :is_active, presence: true
|
6
|
+
validates :wallet_number, uniqueness: { case_sensitive: false }
|
7
|
+
validates :is_active, inclusion: { in: [ true, false ] }
|
8
|
+
|
9
|
+
before_validation :generate_wallet_number, on: :create
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def generate_wallet_number
|
14
|
+
loop do
|
15
|
+
random_digits = SecureRandom.random_number(10**10).to_s.rjust(10, "0")
|
16
|
+
self.wallet_number = "BB#{random_digits}"
|
17
|
+
break unless Wallet.exists?(wallet_number: wallet_number)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -1,11 +1,11 @@
|
|
1
|
-
class CreateSnfCoreCategories < ActiveRecord::Migration[8.0]
|
2
|
-
def change
|
3
|
-
create_table :snf_core_categories do |t|
|
4
|
-
t.string :name, null: false
|
5
|
-
t.string :description
|
6
|
-
t.references :parent, null: true, foreign_key: { to_table: :snf_core_categories }
|
7
|
-
|
8
|
-
t.timestamps
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
1
|
+
class CreateSnfCoreCategories < ActiveRecord::Migration[8.0]
|
2
|
+
def change
|
3
|
+
create_table :snf_core_categories do |t|
|
4
|
+
t.string :name, null: false
|
5
|
+
t.string :description
|
6
|
+
t.references :parent, null: true, foreign_key: { to_table: :snf_core_categories }
|
7
|
+
|
8
|
+
t.timestamps
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -1,14 +1,14 @@
|
|
1
|
-
class CreateSnfCoreBusinesses < ActiveRecord::Migration[8.0]
|
2
|
-
def change
|
3
|
-
create_table :snf_core_businesses do |t|
|
4
|
-
t.references :user, null: false, foreign_key: { to_table: :snf_core_users }
|
5
|
-
t.string :business_name, null: false
|
6
|
-
t.string :tin_number, null: false
|
7
|
-
t.integer :business_type, null: false
|
8
|
-
t.datetime :verified_at
|
9
|
-
t.integer :verification_status, null: false
|
10
|
-
|
11
|
-
t.timestamps
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
1
|
+
class CreateSnfCoreBusinesses < ActiveRecord::Migration[8.0]
|
2
|
+
def change
|
3
|
+
create_table :snf_core_businesses do |t|
|
4
|
+
t.references :user, null: false, foreign_key: { to_table: :snf_core_users }
|
5
|
+
t.string :business_name, null: false
|
6
|
+
t.string :tin_number, null: false
|
7
|
+
t.integer :business_type, null: false
|
8
|
+
t.datetime :verified_at
|
9
|
+
t.integer :verification_status, null: false
|
10
|
+
|
11
|
+
t.timestamps
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -1,13 +1,14 @@
|
|
1
1
|
class CreateSnfCoreStoreInventories < ActiveRecord::Migration[8.0]
|
2
2
|
def change
|
3
3
|
create_table :snf_core_store_inventories do |t|
|
4
|
-
t.string :stock_quantity
|
5
|
-
t.float :reorder_level
|
6
|
-
t.datetime :last_restocked_at
|
7
4
|
t.references :store, null: false, foreign_key: { to_table: :snf_core_stores }
|
8
5
|
t.references :product, null: false, foreign_key: { to_table: :snf_core_products }
|
6
|
+
t.integer :stock_quantity, null: false, default: 0
|
7
|
+
t.decimal :base_price, precision: 10, scale: 2, null: false
|
9
8
|
|
10
9
|
t.timestamps
|
11
10
|
end
|
11
|
+
|
12
|
+
add_index :snf_core_store_inventories, [ :store_id, :product_id ], unique: true
|
12
13
|
end
|
13
14
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class CreateSnfCoreWallets < ActiveRecord::Migration[8.0]
|
2
|
+
def change
|
3
|
+
create_table :snf_core_wallets do |t|
|
4
|
+
t.references :user, null: false, foreign_key: { to_table: :snf_core_users }
|
5
|
+
t.string :wallet_number, null: false
|
6
|
+
t.decimal :balance, null: false
|
7
|
+
t.boolean :is_active, null: false, default: true
|
8
|
+
|
9
|
+
t.timestamps
|
10
|
+
|
11
|
+
t.index :wallet_number, unique: true
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/snf_core/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: snf_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Asrat
|
@@ -299,6 +299,7 @@ files:
|
|
299
299
|
- app/models/snf_core/store.rb
|
300
300
|
- app/models/snf_core/store_inventory.rb
|
301
301
|
- app/models/snf_core/user.rb
|
302
|
+
- app/models/snf_core/wallet.rb
|
302
303
|
- config/routes.rb
|
303
304
|
- db/migrate/20250226042622_create_snf_core_users.rb
|
304
305
|
- db/migrate/20250226064444_create_snf_core_categories.rb
|
@@ -307,18 +308,20 @@ files:
|
|
307
308
|
- db/migrate/20250226110217_create_snf_core_addresses.rb
|
308
309
|
- db/migrate/20250226115215_create_snf_core_stores.rb
|
309
310
|
- db/migrate/20250226181007_create_snf_core_products.rb
|
310
|
-
- db/migrate/
|
311
|
+
- db/migrate/20250226190000_create_snf_core_store_inventories.rb
|
311
312
|
- db/migrate/20250226192104_create_snf_core_groups.rb
|
312
313
|
- db/migrate/20250226193938_create_snf_core_customer_groups.rb
|
314
|
+
- db/migrate/20250227075048_create_snf_core_wallets.rb
|
315
|
+
- db/migrate/20250227102833_modify_store_inventories.rb
|
313
316
|
- lib/snf_core.rb
|
314
317
|
- lib/snf_core/engine.rb
|
315
318
|
- lib/snf_core/version.rb
|
316
319
|
- lib/tasks/snf_core_tasks.rake
|
317
|
-
homepage: https://
|
320
|
+
homepage: https://mksaddis.com/
|
318
321
|
licenses:
|
319
322
|
- MIT
|
320
323
|
metadata:
|
321
|
-
homepage_uri: https://
|
324
|
+
homepage_uri: https://mksaddis.com/
|
322
325
|
source_code_uri: https://github.com/BITS-DEVSEC
|
323
326
|
changelog_uri: https://github.com/BITS-DEVSEC
|
324
327
|
rdoc_options: []
|