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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4b374eba7361b8c758484bc9424ca026e43e5be805bf073073cfc33f113d63c8
4
- data.tar.gz: 0dbd00825791a10d4305db34c648d3e5d3d297b066c14dcd0b9f344ade29e32f
3
+ metadata.gz: f51a5b893502ce6049f446264e9b3c7bab06887f7a8364a70d8a80c247470cc9
4
+ data.tar.gz: 05306e10728b7fcf42b05e8a80387e7d7833a8c7e54f5abd8fa4295cf1c1d5bc
5
5
  SHA512:
6
- metadata.gz: 292f84ae8497ade0754a27e868a5ffc2848e50f9805c29516a2388bedaf93fd5216efec2694300658652388c81ebc7f73c663279dcbddbc13699cd11baec3e3d
7
- data.tar.gz: 238c5be87bd5c1a50d7f2972f4be6a28818e96aabd5b64af9e77d43de60b61daf07aef5300190d9c03d263d8fabce6c9be618a1e47ac63a2b0db6e2fbf1654ba
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
- # Relationships
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
@@ -89,7 +89,7 @@ en:
89
89
  update: "Failed to update supplier product"
90
90
  destroy: "Failed to delete supplier product"
91
91
 
92
- listing:
92
+ listings:
93
93
  success:
94
94
  index: "Listings retrieved successfully"
95
95
  show: "Listing details retrieved successfully"
@@ -1,5 +1,5 @@
1
1
  module Dscf
2
2
  module Marketplace
3
- VERSION = "0.2.7".freeze
3
+ VERSION = "0.2.9".freeze
4
4
  end
5
5
  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.2.7
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-03 00:00:00.000000000 Z
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