Skip to content

Commit

Permalink
Merge pull request #3937 from rubyforgood/new-adjustment-fix
Browse files Browse the repository at this point in the history
Better fix for adjustments
  • Loading branch information
awwaiid authored Nov 12, 2023
2 parents bb0c5f6 + 6bfef71 commit 1ed5c54
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
24 changes: 17 additions & 7 deletions app/events/event_types/event_line_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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<LineItem>]
Expand Down
6 changes: 3 additions & 3 deletions spec/services/adjustment_create_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
]
Expand Down

0 comments on commit 1ed5c54

Please sign in to comment.