dscf-marketplace 0.2.7 → 0.2.9
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/controllers/concerns/dscf/marketplace/nested_creatable.rb +47 -0
- data/app/controllers/dscf/marketplace/orders_controller.rb +3 -1
- data/app/controllers/dscf/marketplace/quotations_controller.rb +3 -1
- data/app/controllers/dscf/marketplace/request_for_quotations_controller.rb +3 -1
- data/app/models/dscf/marketplace/order.rb +1 -0
- data/app/models/dscf/marketplace/quotation.rb +1 -0
- data/app/models/dscf/marketplace/request_for_quotation.rb +1 -0
- data/app/models/dscf/marketplace/supplier_product.rb +2 -6
- data/app/serializers/dscf/marketplace/supplier_product_serializer.rb +2 -1
- data/config/locales/en.yml +1 -1
- data/lib/dscf/marketplace/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f51a5b893502ce6049f446264e9b3c7bab06887f7a8364a70d8a80c247470cc9
|
4
|
+
data.tar.gz: 05306e10728b7fcf42b05e8a80387e7d7833a8c7e54f5abd8fa4295cf1c1d5bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9438af1ce5588f183b3421199c0b9e656576d2cd89aa89d6a0e9b8e5c552dab0030df18f185e896b2ffcb53b79bf548e03bb1c348c8928b52b706840ede268cd
|
7
|
+
data.tar.gz: '0948cb5588ba6f5a5c7d1e572b992a6d96fde59d0944c7c505aa0e630c0018d35a21cd9613191e0434c24b880b0a3117f60fe782d61ee836797356a041b22749'
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Dscf::Marketplace::NestedCreatable
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
# Override the create method from Dscf::Core::Common
|
6
|
+
def create
|
7
|
+
obj = @clazz.new(model_params)
|
8
|
+
assign_current_user(obj) if respond_to?(:assign_current_user)
|
9
|
+
|
10
|
+
if obj.save
|
11
|
+
obj = @clazz.includes(eager_loaded_associations).find(obj.id) if eager_loaded_associations.present?
|
12
|
+
|
13
|
+
includes = serializer_includes_for_action(:create)
|
14
|
+
options = {include: includes} if includes.present?
|
15
|
+
|
16
|
+
# Get success message from locales
|
17
|
+
model_name = @clazz.name.demodulize.underscore
|
18
|
+
message_key = "#{model_name}.success.create"
|
19
|
+
message = I18n.t(message_key, default: "#{model_name.titleize} created successfully")
|
20
|
+
|
21
|
+
# Include associated items in response for orders
|
22
|
+
if model_name == "order" && obj.respond_to?(:order_items)
|
23
|
+
render_success(message, data: obj, order_items: obj.order_items, serializer_options: options, status: :created)
|
24
|
+
else
|
25
|
+
render_success(message, data: obj, serializer_options: options, status: :created)
|
26
|
+
end
|
27
|
+
else
|
28
|
+
Rails.logger.error("#{model_name} save failed: #{obj.errors.full_messages}")
|
29
|
+
|
30
|
+
# Get error message from locales
|
31
|
+
error_key = "#{model_name}.errors.create"
|
32
|
+
error_message = I18n.t(error_key, default: "Failed to create #{model_name}")
|
33
|
+
|
34
|
+
render_error(error_message, status: :unprocessable_entity)
|
35
|
+
end
|
36
|
+
rescue => e
|
37
|
+
render_error(e.message)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def assign_current_user(obj)
|
44
|
+
obj.user = current_user if obj.respond_to?(:user=)
|
45
|
+
obj.ordered_by = current_user if obj.respond_to?(:ordered_by=)
|
46
|
+
end
|
47
|
+
end
|
@@ -2,6 +2,7 @@ module Dscf
|
|
2
2
|
module Marketplace
|
3
3
|
class OrdersController < ApplicationController
|
4
4
|
include Dscf::Core::Common
|
5
|
+
include Dscf::Marketplace::NestedCreatable
|
5
6
|
|
6
7
|
def confirm
|
7
8
|
@obj = find_record
|
@@ -49,7 +50,8 @@ module Dscf
|
|
49
50
|
def model_params
|
50
51
|
params.require(:order).permit(
|
51
52
|
:quotation_id, :listing_id, :user_id, :ordered_by_id, :ordered_to_id, :delivery_order_id,
|
52
|
-
:order_type, :status, :fulfillment_type
|
53
|
+
:order_type, :status, :fulfillment_type,
|
54
|
+
order_items_attributes: [ :id, :quotation_item_id, :listing_id, :product_id, :unit_id, :quantity, :unit_price, :status, :_destroy ]
|
53
55
|
)
|
54
56
|
end
|
55
57
|
|
@@ -2,6 +2,7 @@ module Dscf
|
|
2
2
|
module Marketplace
|
3
3
|
class QuotationsController < ApplicationController
|
4
4
|
include Dscf::Core::Common
|
5
|
+
include Dscf::Marketplace::NestedCreatable
|
5
6
|
|
6
7
|
def accept
|
7
8
|
@obj = find_record
|
@@ -47,7 +48,8 @@ module Dscf
|
|
47
48
|
def model_params
|
48
49
|
params.require(:quotation).permit(
|
49
50
|
:request_for_quotation_id, :business_id, :total_price,
|
50
|
-
:delivery_date, :valid_until, :status, :notes
|
51
|
+
:delivery_date, :valid_until, :status, :notes,
|
52
|
+
quotation_items_attributes: [ :id, :rfq_item_id, :product_id, :unit_id, :quantity, :unit_price, :subtotal, :_destroy ]
|
51
53
|
)
|
52
54
|
end
|
53
55
|
|
@@ -2,6 +2,7 @@ module Dscf
|
|
2
2
|
module Marketplace
|
3
3
|
class RequestForQuotationsController < ApplicationController
|
4
4
|
include Dscf::Core::Common
|
5
|
+
include Dscf::Marketplace::NestedCreatable
|
5
6
|
|
6
7
|
def send_rfq
|
7
8
|
@obj = find_record
|
@@ -37,7 +38,8 @@ module Dscf
|
|
37
38
|
|
38
39
|
def model_params
|
39
40
|
params.require(:request_for_quotation).permit(
|
40
|
-
:user_id, :selected_quotation_id, :status, :notes
|
41
|
+
:user_id, :selected_quotation_id, :status, :notes,
|
42
|
+
rfq_items_attributes: [ :id, :product_id, :unit_id, :quantity, :notes, :_destroy ]
|
41
43
|
)
|
42
44
|
end
|
43
45
|
|
@@ -11,6 +11,7 @@ module Dscf::Marketplace
|
|
11
11
|
belongs_to :ordered_to, class_name: "Dscf::Core::Business"
|
12
12
|
belongs_to :delivery_order, optional: true
|
13
13
|
has_many :order_items, dependent: :destroy
|
14
|
+
accepts_nested_attributes_for :order_items, allow_destroy: true
|
14
15
|
|
15
16
|
validates :order_type, presence: true
|
16
17
|
validates :status, presence: true
|
@@ -6,6 +6,7 @@ module Dscf
|
|
6
6
|
|
7
7
|
has_many :quotation_items, class_name: "Dscf::Marketplace::QuotationItem", dependent: :destroy
|
8
8
|
has_one :order, class_name: "Dscf::Marketplace::Order", dependent: :destroy
|
9
|
+
accepts_nested_attributes_for :quotation_items, allow_destroy: true
|
9
10
|
|
10
11
|
validates :request_for_quotation_id, presence: true
|
11
12
|
validates :business_id, presence: true
|
@@ -6,6 +6,7 @@ module Dscf
|
|
6
6
|
|
7
7
|
has_many :rfq_items, class_name: "Dscf::Marketplace::RfqItem", dependent: :destroy
|
8
8
|
has_many :quotations, class_name: "Dscf::Marketplace::Quotation", dependent: :destroy
|
9
|
+
accepts_nested_attributes_for :rfq_items, allow_destroy: true
|
9
10
|
|
10
11
|
validates :user_id, presence: true
|
11
12
|
enum :status, {draft: 0, sent: 1, responded: 2, selected: 3, closed: 4}, default: :draft
|
@@ -1,28 +1,24 @@
|
|
1
1
|
module Dscf::Marketplace
|
2
2
|
class SupplierProduct < ApplicationRecord
|
3
|
-
# References
|
4
3
|
belongs_to :business, class_name: "Dscf::Core::Business"
|
5
4
|
belongs_to :product, class_name: "Dscf::Marketplace::Product"
|
6
5
|
|
7
|
-
|
6
|
+
delegate :name, :description, :thumbnail_url, :images_urls, to: :product, allow_nil: true
|
7
|
+
|
8
8
|
has_many :listings, class_name: "Dscf::Marketplace::Listing"
|
9
9
|
has_many :order_items, class_name: "Dscf::Marketplace::OrderItem"
|
10
10
|
|
11
|
-
# Status enum
|
12
11
|
enum :status, {active: 0, inactive: 1, discontinued: 2}, default: :active
|
13
12
|
|
14
|
-
# Validations
|
15
13
|
validates :supplier_price, numericality: {greater_than: 0}, presence: true
|
16
14
|
validates :available_quantity, numericality: {greater_than_or_equal_to: 0}
|
17
15
|
validates :minimum_order_quantity, numericality: {greater_than: 0}, allow_nil: true
|
18
16
|
|
19
|
-
# Scopes
|
20
17
|
scope :active, -> { where(status: :active) }
|
21
18
|
scope :in_stock, -> { where("available_quantity > 0") }
|
22
19
|
scope :by_business, ->(business_id) { where(business_id: business_id) }
|
23
20
|
scope :by_product, ->(product_id) { where(product_id: product_id) }
|
24
21
|
|
25
|
-
# Ransack configuration for secure filtering
|
26
22
|
def self.ransackable_attributes(_auth_object = nil)
|
27
23
|
%w[id business_id product_id supplier_price available_quantity minimum_order_quantity status created_at updated_at]
|
28
24
|
end
|
@@ -3,7 +3,8 @@ module Dscf
|
|
3
3
|
class SupplierProductSerializer < ActiveModel::Serializer
|
4
4
|
attributes :id, :business_id, :product_id, :supplier_price, :available_quantity,
|
5
5
|
:minimum_order_quantity, :status, :created_at, :updated_at,
|
6
|
-
:in_stock?, :price_per_unit, :display_name
|
6
|
+
:in_stock?, :price_per_unit, :display_name, :name, :description,
|
7
|
+
:thumbnail_url, :images_urls
|
7
8
|
|
8
9
|
belongs_to :business
|
9
10
|
belongs_to :product
|
data/config/locales/en.yml
CHANGED
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.2.
|
4
|
+
version: 0.2.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Asrat
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-09-
|
10
|
+
date: 2025-09-05 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: rails
|
@@ -416,6 +416,7 @@ extra_rdoc_files: []
|
|
416
416
|
files:
|
417
417
|
- MIT-LICENSE
|
418
418
|
- Rakefile
|
419
|
+
- app/controllers/concerns/dscf/marketplace/nested_creatable.rb
|
419
420
|
- app/controllers/dscf/marketplace/application_controller.rb
|
420
421
|
- app/controllers/dscf/marketplace/businesses_controller.rb
|
421
422
|
- app/controllers/dscf/marketplace/categories_controller.rb
|