Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Fix quantity check inside `stock_movements` nested attributes (#12238)

Damian Kaczmarczyk025d2f7ae0b9
diff --git a/core/app/models/spree/stock_transfer.rb b/core/app/models/spree/stock_transfer.rb
index 7faeeb3ae8..deb4066f6a 100644
--- a/core/app/models/spree/stock_transfer.rb
+++ b/core/app/models/spree/stock_transfer.rb
@@ -9,7 +9,10 @@ module Spree
end
has_many :stock_movements, as: :originator
- accepts_nested_attributes_for :stock_movements, reject_if: :all_blank
+ accepts_nested_attributes_for :stock_movements, reject_if: proc { |attributes|
+ attributes[:quantity] = attributes[:quantity].to_i
+ attributes[:quantity].blank? || attributes[:quantity].zero? || attributes[:stock_item_id].blank? || attributes[:originator_id].blank?
+ }
belongs_to :source_location, class_name: 'StockLocation', optional: true
belongs_to :destination_location, class_name: 'StockLocation'