snf_core 0.1.2 → 0.2.1
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/address.rb +6 -0
- data/app/models/snf_core/business.rb +11 -0
- data/app/models/snf_core/business_document.rb +12 -0
- data/app/models/snf_core/category.rb +7 -7
- data/app/models/snf_core/customer_group.rb +6 -0
- data/app/models/snf_core/group.rb +7 -0
- data/app/models/snf_core/product.rb +11 -0
- data/app/models/snf_core/store.rb +10 -0
- data/app/models/snf_core/store_inventory.rb +30 -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 -0
- data/db/migrate/20250226102931_create_snf_core_business_documents.rb +14 -0
- data/db/migrate/20250226110217_create_snf_core_addresses.rb +14 -0
- data/db/migrate/20250226115215_create_snf_core_stores.rb +13 -0
- data/db/migrate/20250226181007_create_snf_core_products.rb +13 -0
- data/db/migrate/20250226190000_create_snf_core_store_inventories.rb +14 -0
- data/db/migrate/20250226192104_create_snf_core_groups.rb +10 -0
- data/db/migrate/20250226193938_create_snf_core_customer_groups.rb +13 -0
- data/db/migrate/20250227075048_create_snf_core_wallets.rb +14 -0
- data/lib/snf_core/engine.rb +2 -0
- data/lib/snf_core/version.rb +1 -1
- metadata +20 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b148e772bedfc2369e9eb125c9e752f3f7519cb1ac47e5c365416e45fe549796
|
4
|
+
data.tar.gz: 1bbb2accd13bc2f00ae5f4b6e55061ea54d47f563a99811c2594be72f4efb4c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06a09af28f6ea76d7e2ccdf0ec82b620e0108fae243b399d734400cd37ff76f81acb7b44c64445dc4fa8988109fe8fc2a8203ccd90bd404d9e0e2d1a44b8ca3d
|
7
|
+
data.tar.gz: e2650005be78578265bbbaaea8690d68efd8f1f87f63defef03554dbb36d95b79dd129b7c86897d95deac52250095d2ed95d0a24f545916797c50084db77d602
|
@@ -0,0 +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
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module SnfCore
|
2
|
+
class BusinessDocument < ApplicationRecord
|
3
|
+
belongs_to :business
|
4
|
+
belongs_to :verified_by, class_name: "SnfCore::User", optional: true
|
5
|
+
|
6
|
+
enum :document_type, { business_license: 0, representative_id: 1 }
|
7
|
+
|
8
|
+
has_one_attached :document
|
9
|
+
|
10
|
+
validates :document_type, :uploaded_at, :document, presence: true
|
11
|
+
end
|
12
|
+
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
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module SnfCore
|
2
|
+
class StoreInventory < ApplicationRecord
|
3
|
+
belongs_to :store
|
4
|
+
belongs_to :product
|
5
|
+
|
6
|
+
validates :stock_quantity, presence: true, numericality: {
|
7
|
+
only_integer: true,
|
8
|
+
greater_than_or_equal_to: 0
|
9
|
+
}
|
10
|
+
validates :base_price, presence: true, numericality: {
|
11
|
+
greater_than_or_equal_to: 0
|
12
|
+
}
|
13
|
+
|
14
|
+
validate :unique_store_product_combination
|
15
|
+
|
16
|
+
scope :out_of_stock, -> { where(stock_quantity: 0) }
|
17
|
+
scope :in_stock, -> { where("stock_quantity > 0") }
|
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
|
29
|
+
end
|
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
|
@@ -0,0 +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
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class CreateSnfCoreBusinessDocuments < ActiveRecord::Migration[8.0]
|
2
|
+
def change
|
3
|
+
create_table :snf_core_business_documents do |t|
|
4
|
+
t.references :business, null: false, foreign_key: { to_table: :snf_core_businesses }
|
5
|
+
t.integer :document_type, null: false
|
6
|
+
t.datetime :verified_at
|
7
|
+
t.references :verified_by, foreign_key: { to_table: :snf_core_users }, null: true
|
8
|
+
t.datetime :uploaded_at
|
9
|
+
t.boolean :is_verified, null: false, default: false
|
10
|
+
|
11
|
+
t.timestamps
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class CreateSnfCoreAddresses < ActiveRecord::Migration[8.0]
|
2
|
+
def change
|
3
|
+
create_table :snf_core_addresses do |t|
|
4
|
+
t.string :address_type, null: false
|
5
|
+
t.string :city, null: false
|
6
|
+
t.string :sub_city, null: false
|
7
|
+
t.string :woreda
|
8
|
+
t.decimal :latitude, null: false
|
9
|
+
t.decimal :longitude, null: false
|
10
|
+
|
11
|
+
t.timestamps
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class CreateSnfCoreStores < ActiveRecord::Migration[8.0]
|
2
|
+
def change
|
3
|
+
create_table :snf_core_stores do |t|
|
4
|
+
t.string :name, null: false
|
5
|
+
t.string :email
|
6
|
+
t.integer :operational_status, null: false, default: 1
|
7
|
+
t.references :business, null: false, foreign_key: { to_table: :snf_core_businesses }
|
8
|
+
t.references :address, null: false, foreign_key: { to_table: :snf_core_addresses }
|
9
|
+
|
10
|
+
t.timestamps
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class CreateSnfCoreProducts < ActiveRecord::Migration[8.0]
|
2
|
+
def change
|
3
|
+
create_table :snf_core_products do |t|
|
4
|
+
t.string :sku, null: false
|
5
|
+
t.string :name, null: false
|
6
|
+
t.string :description
|
7
|
+
t.references :category, null: false, foreign_key: { to_table: :snf_core_categories }
|
8
|
+
t.float :base_price
|
9
|
+
|
10
|
+
t.timestamps
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class CreateSnfCoreStoreInventories < ActiveRecord::Migration[8.0]
|
2
|
+
def change
|
3
|
+
create_table :snf_core_store_inventories do |t|
|
4
|
+
t.references :store, null: false, foreign_key: { to_table: :snf_core_stores }
|
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
|
8
|
+
|
9
|
+
t.timestamps
|
10
|
+
end
|
11
|
+
|
12
|
+
add_index :snf_core_store_inventories, [ :store_id, :product_id ], unique: true
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class CreateSnfCoreGroups < ActiveRecord::Migration[8.0]
|
2
|
+
def change
|
3
|
+
create_table :snf_core_groups do |t|
|
4
|
+
t.string :name, null: false
|
5
|
+
t.references :business, null: false, foreign_key: { to_table: :snf_core_businesses }
|
6
|
+
|
7
|
+
t.timestamps
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class CreateSnfCoreCustomerGroups < ActiveRecord::Migration[8.0]
|
2
|
+
def change
|
3
|
+
create_table :snf_core_customer_groups do |t|
|
4
|
+
t.string :discount_code
|
5
|
+
t.datetime :expire_date
|
6
|
+
t.boolean :is_used
|
7
|
+
t.references :group, null: false, foreign_key: { to_table: :snf_core_groups }
|
8
|
+
t.references :customer, null: false, foreign_key: { to_table: :snf_core_users }
|
9
|
+
|
10
|
+
t.timestamps
|
11
|
+
end
|
12
|
+
end
|
13
|
+
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/engine.rb
CHANGED
data/lib/snf_core/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: snf_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Asrat
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-02-
|
10
|
+
date: 2025-02-27 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: active_model_serializers
|
@@ -288,12 +288,30 @@ files:
|
|
288
288
|
- app/controllers/snf_core/application_controller.rb
|
289
289
|
- app/jobs/snf_core/application_job.rb
|
290
290
|
- app/mailers/snf_core/application_mailer.rb
|
291
|
+
- app/models/snf_core/address.rb
|
291
292
|
- app/models/snf_core/application_record.rb
|
293
|
+
- app/models/snf_core/business.rb
|
294
|
+
- app/models/snf_core/business_document.rb
|
292
295
|
- app/models/snf_core/category.rb
|
296
|
+
- app/models/snf_core/customer_group.rb
|
297
|
+
- app/models/snf_core/group.rb
|
298
|
+
- app/models/snf_core/product.rb
|
299
|
+
- app/models/snf_core/store.rb
|
300
|
+
- app/models/snf_core/store_inventory.rb
|
293
301
|
- app/models/snf_core/user.rb
|
302
|
+
- app/models/snf_core/wallet.rb
|
294
303
|
- config/routes.rb
|
295
304
|
- db/migrate/20250226042622_create_snf_core_users.rb
|
296
305
|
- db/migrate/20250226064444_create_snf_core_categories.rb
|
306
|
+
- db/migrate/20250226080323_create_snf_core_businesses.rb
|
307
|
+
- db/migrate/20250226102931_create_snf_core_business_documents.rb
|
308
|
+
- db/migrate/20250226110217_create_snf_core_addresses.rb
|
309
|
+
- db/migrate/20250226115215_create_snf_core_stores.rb
|
310
|
+
- db/migrate/20250226181007_create_snf_core_products.rb
|
311
|
+
- db/migrate/20250226190000_create_snf_core_store_inventories.rb
|
312
|
+
- db/migrate/20250226192104_create_snf_core_groups.rb
|
313
|
+
- db/migrate/20250226193938_create_snf_core_customer_groups.rb
|
314
|
+
- db/migrate/20250227075048_create_snf_core_wallets.rb
|
297
315
|
- lib/snf_core.rb
|
298
316
|
- lib/snf_core/engine.rb
|
299
317
|
- lib/snf_core/version.rb
|