From 327b460370aa9eaa38b46cb34328d83a02ffbcac Mon Sep 17 00:00:00 2001 From: Du Peng Date: Wed, 22 Jan 2025 17:06:10 +0100 Subject: [PATCH] (bug) unable to update product low stock alert --- CHANGELOG.md | 1 + app/services/product_service.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 51d35c84c..ddf402c7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - updated rails to 7.0.8.7 - updated tzinfo-data to 1.2025.1 - Fix a bug: unable to update opening/closing time for the calendar +- Fix a bug: unable to update product low stock alert ## v6.3.36 2024 December 12 diff --git a/app/services/product_service.rb b/app/services/product_service.rb index 0e75c0bda..deb8a1a29 100644 --- a/app/services/product_service.rb +++ b/app/services/product_service.rb @@ -41,7 +41,7 @@ def amount_multiplied_by_hundred(amount) # @param stock_movements [{stock_type: string, reason: string, quantity: number|string, order_item_id: number|nil}] def update_stock(product, stock_movements = nil) remaining_stock = { internal: product.stock['internal'], external: product.stock['external'] } - product.product_stock_movements_attributes = stock_movements&.map do |movement| + product.product_stock_movements_attributes = stock_movements&.compact_blank&.map do |movement| quantity = ProductStockMovement::OUTGOING_REASONS.include?(movement[:reason]) ? -movement[:quantity].to_i : movement[:quantity].to_i remaining_stock[movement[:stock_type].to_sym] += quantity {