Skip to content

Commit

Permalink
Merge pull request #4669 from rubyforgood/fix-distribution-error
Browse files Browse the repository at this point in the history
Fix for error on complex case involving multiple distribution destroy…
  • Loading branch information
awwaiid authored Sep 28, 2024
2 parents 5fbeea1 + 8839e19 commit 640b7ba
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions app/events/inventory_aggregate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ def on(*event_types, &block)
# @param event_time [DateTime]
# @param validate [Boolean]
# @return [EventTypes::Inventory]
# This method can take a block so that you can build up the history of a particular item over
# time, for instance
def inventory_for(organization_id, event_time: nil, validate: false)
last_snapshot = Event.most_recent_snapshot(organization_id)

Expand All @@ -35,11 +37,13 @@ def inventory_for(organization_id, event_time: nil, validate: false)
# don't do grouping for UpdateExistingEvents
if event_batch.any? { |e| e.is_a?(UpdateExistingEvent) }
handle(last_grouped_event, inventory, validate: validate)
yield last_grouped_event, inventory if block_given?
next
end
previous_event = event_hash[last_grouped_event.eventable]
event_hash[last_grouped_event.eventable] = last_grouped_event
previous_event = event_hash[[last_grouped_event.eventable_type, last_grouped_event.eventable_id]]
event_hash[[last_grouped_event.eventable_type, last_grouped_event.eventable_id]] = last_grouped_event
handle(last_grouped_event, inventory, validate: validate, previous_event: previous_event)
yield last_grouped_event, inventory if block_given?
end
inventory
end
Expand Down

0 comments on commit 640b7ba

Please sign in to comment.