From 6bfef716478b76e16de9b99a0048c4f99e5f1730 Mon Sep 17 00:00:00 2001 From: Daniel Orner Date: Sun, 12 Nov 2023 10:23:11 -0500 Subject: [PATCH] Better fix for adjustments --- app/events/event_types/event_line_item.rb | 24 +++++++++++++------ .../adjustment_create_service_spec.rb | 6 ++--- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/app/events/event_types/event_line_item.rb b/app/events/event_types/event_line_item.rb index a6dc418dce..6897a65a68 100644 --- a/app/events/event_types/event_line_item.rb +++ b/app/events/event_types/event_line_item.rb @@ -16,13 +16,23 @@ class EventLineItem < Dry::Struct # @param to [Integer] # @return [EventLineItem] def self.from_line_item(line_item, from: nil, to: nil) - new( - quantity: line_item.quantity, - item_id: line_item.item_id, - item_value_in_cents: line_item.item.value_in_cents, - from_storage_location: from, - to_storage_location: to - ) + if line_item.quantity.negative? + new( + quantity: -line_item.quantity, + item_id: line_item.item_id, + item_value_in_cents: line_item.item.value_in_cents, + from_storage_location: to, + to_storage_location: from + ) + else + new( + quantity: line_item.quantity, + item_id: line_item.item_id, + item_value_in_cents: line_item.item.value_in_cents, + from_storage_location: from, + to_storage_location: to + ) + end end # @param line_item [Array] diff --git a/spec/services/adjustment_create_service_spec.rb b/spec/services/adjustment_create_service_spec.rb index e5f49cf202..b0d0fcf369 100644 --- a/spec/services/adjustment_create_service_spec.rb +++ b/spec/services/adjustment_create_service_spec.rb @@ -49,10 +49,10 @@ expect(event.data).to eq(EventTypes::InventoryPayload.new( items: [ EventTypes::EventLineItem.new( - quantity: -5, + quantity: 5, item_id: item_1.id, - from_storage_location: nil, - to_storage_location: storage_location.id, + from_storage_location: storage_location.id, + to_storage_location: nil, item_value_in_cents: 0 ) ]