dscf-marketplace 0.1.3 → 0.1.4
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 483c018a55aced4c97a7dc9443c45721ba6571dd16100736e36281349bdb65a3
|
4
|
+
data.tar.gz: 49feba6deeec8f69dd7ad693e61c7f6e8c648480b35a8da2d97acd3ddf9152db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72d2b07581b5bbc8942c0b133d7a01b81be9238adc3a303a68c60f421a89145cf7d634c07fd77f7f2fa7b637d3ade0dd39f687442d7c678edc22edd52bc9b694
|
7
|
+
data.tar.gz: 4ac74190a143f232210958073b6720c5142da6f15052275121384dd162c08ea93f68f3e86ec59ddc2b161f5e745fdb9a7cc680a6f445d469bacf8b964300d42c
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module Dscf
|
2
|
+
module Marketplace
|
3
|
+
class Product < ApplicationRecord
|
4
|
+
belongs_to :category, class_name: "Dscf::Marketplace::Category"
|
5
|
+
belongs_to :unit, class_name: "Dscf::Marketplace::Unit"
|
6
|
+
|
7
|
+
has_many :supplier_products, class_name: "Dscf::Marketplace::SupplierProduct"
|
8
|
+
has_many :listings, class_name: "Dscf::Marketplace::Listing"
|
9
|
+
has_many :order_items, class_name: "Dscf::Marketplace::OrderItem"
|
10
|
+
has_many :rfq_items, class_name: "Dscf::Marketplace::RfqItem"
|
11
|
+
has_many :quotation_items, class_name: "Dscf::Marketplace::QuotationItem"
|
12
|
+
|
13
|
+
has_one_attached :thumbnail
|
14
|
+
has_many_attached :images
|
15
|
+
|
16
|
+
validates :sku, presence: true, uniqueness: true, length: {maximum: 50}
|
17
|
+
validates :name, presence: true, length: {maximum: 200}
|
18
|
+
validates :description, length: {maximum: 2000}, allow_blank: true
|
19
|
+
validates :category_id, presence: true
|
20
|
+
validates :base_price, presence: true, numericality: {greater_than: 0}
|
21
|
+
validates :business_only, inclusion: {in: [ true, false ]}
|
22
|
+
validates :unit_id, presence: true
|
23
|
+
validates :base_quantity, presence: true, numericality: {greater_than: 0}
|
24
|
+
|
25
|
+
scope :business_only, -> { where(business_only: true) }
|
26
|
+
scope :public_products, -> { where(business_only: false) }
|
27
|
+
scope :by_category, ->(category_id) { where(category_id: category_id) }
|
28
|
+
scope :by_unit, ->(unit_id) { where(unit_id: unit_id) }
|
29
|
+
|
30
|
+
def display_name
|
31
|
+
"#{name} (#{sku})"
|
32
|
+
end
|
33
|
+
|
34
|
+
def price_per_unit
|
35
|
+
return nil unless base_price && base_quantity && base_quantity > 0
|
36
|
+
base_price / base_quantity
|
37
|
+
end
|
38
|
+
|
39
|
+
def category_path
|
40
|
+
return nil unless category
|
41
|
+
category.ancestry_path
|
42
|
+
end
|
43
|
+
|
44
|
+
def convertible_to_units
|
45
|
+
return [] unless unit
|
46
|
+
unit.convertible_units
|
47
|
+
end
|
48
|
+
|
49
|
+
def thumbnail_url
|
50
|
+
return nil unless thumbnail.attached?
|
51
|
+
Rails.application.routes.url_helpers.rails_blob_url(thumbnail, only_path: true)
|
52
|
+
end
|
53
|
+
|
54
|
+
def images_urls
|
55
|
+
return [] unless images.attached?
|
56
|
+
images.map do |image|
|
57
|
+
Rails.application.routes.url_helpers.rails_blob_url(image, only_path: true)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
class CreateDscfMarketplaceProducts < ActiveRecord::Migration[8.0]
|
2
|
+
def change
|
3
|
+
create_table :dscf_marketplace_products do |t|
|
4
|
+
t.string :sku, null: false, limit: 50
|
5
|
+
t.string :name, null: false, limit: 200
|
6
|
+
t.text :description, limit: 2000
|
7
|
+
t.references :category,
|
8
|
+
index: {name: "category_on_dm_products_indx"},
|
9
|
+
null: false,
|
10
|
+
foreign_key: {to_table: :dscf_marketplace_categories}
|
11
|
+
t.decimal :base_price, precision: 15, scale: 2, null: false
|
12
|
+
t.boolean :business_only, null: false, default: false
|
13
|
+
t.references :unit,
|
14
|
+
index: {name: "unit_on_dm_products_indx"},
|
15
|
+
null: false,
|
16
|
+
foreign_key: {to_table: :dscf_marketplace_units}
|
17
|
+
t.decimal :base_quantity, precision: 15, scale: 6, null: false
|
18
|
+
|
19
|
+
t.timestamps
|
20
|
+
end
|
21
|
+
|
22
|
+
add_index :dscf_marketplace_products, :sku,
|
23
|
+
unique: true,
|
24
|
+
name: "sku_on_dm_products_indx"
|
25
|
+
add_index :dscf_marketplace_products, :business_only,
|
26
|
+
name: "business_only_on_dm_products_indx"
|
27
|
+
add_index :dscf_marketplace_products, [ :category_id, :business_only ],
|
28
|
+
name: "category_business_only_on_dm_products_indx"
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
FactoryBot.define do
|
2
|
+
factory :dscf_marketplace_product, class: 'Dscf::Marketplace::Product' do
|
3
|
+
sequence(:sku) { |n| "PRD-#{n.to_s.rjust(3, '0')}" }
|
4
|
+
sequence(:name) { |n| "Product #{n}" }
|
5
|
+
description { "Product description" }
|
6
|
+
category { create(:dscf_marketplace_category) }
|
7
|
+
base_price { 99.99 }
|
8
|
+
business_only { false }
|
9
|
+
unit { create(:dscf_marketplace_unit) }
|
10
|
+
base_quantity { 1.0 }
|
11
|
+
end
|
12
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dscf-marketplace
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Asrat
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-08-
|
10
|
+
date: 2025-08-28 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: rails
|
@@ -422,6 +422,7 @@ files:
|
|
422
422
|
- app/mailers/dscf/marketplace/application_mailer.rb
|
423
423
|
- app/models/dscf/marketplace/application_record.rb
|
424
424
|
- app/models/dscf/marketplace/category.rb
|
425
|
+
- app/models/dscf/marketplace/product.rb
|
425
426
|
- app/models/dscf/marketplace/unit.rb
|
426
427
|
- app/models/dscf/marketplace/unit_conversion.rb
|
427
428
|
- config/routes.rb
|
@@ -429,11 +430,13 @@ files:
|
|
429
430
|
- db/migrate/20250827173526_update_dscf_marketplace_categories_indexes.rb
|
430
431
|
- db/migrate/20250827182550_create_dscf_marketplace_units.rb
|
431
432
|
- db/migrate/20250827185656_create_dscf_marketplace_unit_conversions.rb
|
433
|
+
- db/migrate/20250828062945_create_dscf_marketplace_products.rb
|
432
434
|
- lib/dscf/marketplace.rb
|
433
435
|
- lib/dscf/marketplace/engine.rb
|
434
436
|
- lib/dscf/marketplace/version.rb
|
435
437
|
- lib/tasks/dscf/marketplace_tasks.rake
|
436
438
|
- spec/factories/dscf/marketplace/categories.rb
|
439
|
+
- spec/factories/dscf/marketplace/products.rb
|
437
440
|
- spec/factories/dscf/marketplace/unit_conversions.rb
|
438
441
|
- spec/factories/dscf/marketplace/units.rb
|
439
442
|
homepage: https://mksaddis.com/
|