dscf-marketplace 0.2.96 → 0.2.97

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: 337301146588e5fb9301adbb623f086e2cbc44ab193247ef22095868e2bcfc6e
4
- data.tar.gz: 07f2f4c37075de27e77f71f09043aae1ef6e67ac0d8b9cb3ec6c13a87aad6b43
3
+ metadata.gz: ac33f2e1d75896ac1b646325ea4644d462a898a90faee7a2c09ac2ef3b42190b
4
+ data.tar.gz: a408d6430e056a6d8b0d42168b8c6f33fed208f961973efdbaca4dd4dc1c6550
5
5
  SHA512:
6
- metadata.gz: 6953d8e4c94403e5856d6f6095ad6891886d186c5f69a12c86c002974fb90c07f4f21b12051aaac77443b1830334b509da64b97f712e2bd21f97c395358a2c46
7
- data.tar.gz: 3e3e8c5b5d5f627a186ba00c07559c73716410bafc426f18ec140d427b5171ee39d49dc28d0914b164bd4df2dae3a173ca13e184933bc30c2a0122cd2c319232
6
+ metadata.gz: 9ca871053dba043306d13c00181b907f711c75063f7ddc20c0b86f97ed23bd92ce38d3c0d764fc136f2b1a2a2a6096770e13de3fd3951fa842fc0e1416182dc8
7
+ data.tar.gz: 7409c3056f032dc9f4e66d819c8c021431cc14f6d8b5d5708b8bfd87a688d829af5664b00697b0c0ef94f3e229bae64d8d4337f0a591f8ad4b9aa0b0b3cb4b7e
@@ -3,6 +3,23 @@ module Dscf
3
3
  class RequestForQuotationsController < ApplicationController
4
4
  include Dscf::Core::Common
5
5
 
6
+ def create
7
+ obj = @clazz.new(model_params)
8
+ if obj.save
9
+ obj = @clazz.includes(eager_loaded_associations).find(obj.id) if eager_loaded_associations.present?
10
+ includes = default_serializer_includes[:create] || []
11
+ options = {include: includes} if includes.present?
12
+ Rails.logger.info("RFQ created with #{obj.rfq_items.count} items")
13
+ render_success(data: obj, serializer_options: options, status: :created)
14
+ else
15
+ Rails.logger.info("RFQ save failed: #{obj.errors.full_messages}")
16
+ Rails.logger.info("RFQ rfq_items errors: #{obj.rfq_items.map(&:errors).map(&:full_messages)}")
17
+ render_error(errors: "Validation failed: #{obj.errors.full_messages.join(", ")}", status: :unprocessable_entity)
18
+ end
19
+ rescue => e
20
+ render_error(error: e.message)
21
+ end
22
+
6
23
  def send_rfq
7
24
  @obj = find_record
8
25
  if @obj.draft? && @obj.update(status: :sent)
@@ -10,7 +10,7 @@ module Dscf::Marketplace
10
10
  belongs_to :ordered_by, class_name: "Dscf::Core::User"
11
11
  belongs_to :ordered_to, class_name: "Dscf::Core::Business"
12
12
  belongs_to :delivery_order, optional: true
13
- has_many :order_items, dependent: :destroy, inverse_of: :order
13
+ has_many :order_items, dependent: :destroy, autosave: true
14
14
  accepts_nested_attributes_for :order_items, allow_destroy: true
15
15
 
16
16
  validates :order_type, presence: true
@@ -4,7 +4,7 @@ module Dscf::Marketplace
4
4
 
5
5
  delegate :name, :description, :thumbnail_url, :images_urls, to: :product, allow_nil: true
6
6
 
7
- belongs_to :order, optional: true, inverse_of: :order_items
7
+ belongs_to :order, optional: true
8
8
  belongs_to :quotation_item, optional: true
9
9
  belongs_to :listing, optional: true
10
10
  belongs_to :product
@@ -4,7 +4,7 @@ module Dscf
4
4
  belongs_to :request_for_quotation, class_name: "Dscf::Marketplace::RequestForQuotation"
5
5
  belongs_to :business, class_name: "Dscf::Core::Business", optional: true if defined?(Dscf::Core)
6
6
 
7
- has_many :quotation_items, class_name: "Dscf::Marketplace::QuotationItem", dependent: :destroy, inverse_of: :quotation
7
+ has_many :quotation_items, class_name: "Dscf::Marketplace::QuotationItem", dependent: :destroy, autosave: true
8
8
  has_one :order, class_name: "Dscf::Marketplace::Order", dependent: :destroy
9
9
  accepts_nested_attributes_for :quotation_items, allow_destroy: true
10
10
 
@@ -1,20 +1,18 @@
1
1
  module Dscf
2
2
  module Marketplace
3
3
  class QuotationItem < ApplicationRecord
4
- belongs_to :quotation, class_name: "Dscf::Marketplace::Quotation", inverse_of: :quotation_items
4
+ belongs_to :quotation, class_name: "Dscf::Marketplace::Quotation"
5
5
  belongs_to :rfq_item, class_name: "Dscf::Marketplace::RfqItem"
6
6
  belongs_to :product, class_name: "Dscf::Marketplace::Product"
7
7
  belongs_to :unit, class_name: "Dscf::Marketplace::Unit"
8
8
 
9
- validates :quotation_id, presence: true
10
- validates :rfq_item_id, presence: true
11
9
  validates :product_id, presence: true
12
10
  validates :quantity, presence: true, numericality: {greater_than: 0}
13
11
  validates :unit_id, presence: true
14
12
  validates :unit_price, numericality: {greater_than: 0}, allow_nil: true
15
13
  validates :subtotal, numericality: {greater_than_or_equal_to: 0}, allow_nil: true
16
14
  validate :product_matches_rfq_item
17
- validate :unit_compatible_with_product
15
+ # validate :unit_compatible_with_product
18
16
  validate :subtotal_matches_calculation, if: :should_validate_subtotal?
19
17
  before_save :calculate_subtotal, if: :should_recalculate_subtotal?
20
18
 
@@ -126,8 +124,8 @@ module Dscf
126
124
  def unit_compatible_with_product
127
125
  return unless product_id && unit_id
128
126
 
129
- unless product.unit_id == unit_id || product.unit.convertible_to?(unit)
130
- errors.add(:unit_id, "is not compatible with the selected product")
127
+ unless product.unit_id == unit_id
128
+ errors.add(:unit_id, "must match the product's base unit")
131
129
  end
132
130
  end
133
131
 
@@ -4,11 +4,10 @@ module Dscf
4
4
  belongs_to :user, class_name: "Dscf::Core::User", optional: true if defined?(Dscf::Core)
5
5
  belongs_to :selected_quotation, class_name: "Dscf::Marketplace::Quotation", optional: true
6
6
 
7
- has_many :rfq_items, class_name: "Dscf::Marketplace::RfqItem", dependent: :destroy, inverse_of: :request_for_quotation
7
+ has_many :rfq_items, class_name: "Dscf::Marketplace::RfqItem", dependent: :destroy, autosave: true
8
8
  has_many :quotations, class_name: "Dscf::Marketplace::Quotation", dependent: :destroy
9
9
  accepts_nested_attributes_for :rfq_items, allow_destroy: true
10
10
 
11
- validates :user_id, presence: true
12
11
  enum :status, {draft: 0, sent: 1, responded: 2, selected: 3, closed: 4}, default: :draft
13
12
  validates :notes, length: {maximum: 2000}, allow_blank: true
14
13
 
@@ -1,19 +1,16 @@
1
1
  module Dscf
2
2
  module Marketplace
3
3
  class RfqItem < ApplicationRecord
4
- belongs_to :request_for_quotation, class_name: "Dscf::Marketplace::RequestForQuotation", inverse_of: :rfq_items
4
+ belongs_to :request_for_quotation, class_name: "Dscf::Marketplace::RequestForQuotation"
5
5
  belongs_to :product, class_name: "Dscf::Marketplace::Product"
6
6
  belongs_to :unit, class_name: "Dscf::Marketplace::Unit"
7
7
 
8
8
  has_many :quotation_items, class_name: "Dscf::Marketplace::QuotationItem", dependent: :destroy
9
9
 
10
- validates :request_for_quotation_id, presence: true
11
- validates :product_id, presence: true
12
10
  validates :quantity, presence: true, numericality: {greater_than: 0}
13
- validates :unit_id, presence: true
14
11
  validates :notes, length: {maximum: 1000}, allow_blank: true
15
12
 
16
- validate :unit_compatible_with_product
13
+ # validate :unit_compatible_with_product
17
14
 
18
15
  scope :by_product, ->(product_id) { where(product_id: product_id) }
19
16
  scope :by_unit, ->(unit_id) { where(unit_id: unit_id) }
@@ -81,8 +78,8 @@ module Dscf
81
78
  def unit_compatible_with_product
82
79
  return unless product_id && unit_id
83
80
 
84
- unless product.unit_id == unit_id || product.unit.convertible_to?(unit)
85
- errors.add(:unit_id, "is not compatible with the selected product")
81
+ unless product.unit_id == unit_id
82
+ errors.add(:unit_id, "must match the product's base unit")
86
83
  end
87
84
  end
88
85
  end
@@ -1,5 +1,5 @@
1
1
  module Dscf
2
2
  module Marketplace
3
- VERSION = "0.2.96".freeze
3
+ VERSION = "0.2.97".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dscf-marketplace
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.96
4
+ version: 0.2.97
5
5
  platform: ruby
6
6
  authors:
7
7
  - Asrat