Skip to content

Commit 9ec6d0a

Browse files
Merge pull request #5481 from Budmin/5476_purchase_correction_location_fix
Itemizable checks if the storage location changes, and updates inventory
2 parents 3e5c963 + ed8fff3 commit 9ec6d0a

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

app/services/itemizable_update_service.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def call(itemizable:, params: {}, event_class: nil)
3737
# TODO once event sourcing has been out for long enough, we can safely remove this
3838
if Event.where(eventable: itemizable).none? || UpdateExistingEvent.where(eventable: itemizable).any?
3939
UpdateExistingEvent.publish(itemizable, previous, original_storage_location)
40-
elsif inventory_changes?(previous, params[:line_items_attributes])
40+
elsif inventory_changes?(previous, params[:line_items_attributes]) || itemizable.storage_location_id != original_storage_location.id
4141
event_class&.publish(itemizable)
4242
end
4343
end

spec/services/itemizable_update_service_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,24 @@
215215
expect(UpdateExistingEvent.count).to eq(1)
216216
expect(View::Inventory.total_inventory(organization.id)).to eq(75) # 40 - 5 (item1) - 10 (item2) + 50 (item3)
217217
end
218+
219+
it "should send an event when the storage location changes" do
220+
DonationEvent.publish(itemizable)
221+
expect(DonationEvent.count).to eq(1)
222+
223+
# attributes that keep quantities the same but change storage location
224+
same_quantities_attributes = {
225+
storage_location_id: new_storage_location.id,
226+
line_items_attributes: {
227+
"0" => {item_id: item1.id, quantity: 10},
228+
"1" => {item_id: item2.id, quantity: 10}
229+
}
230+
}
231+
232+
described_class.call(itemizable: itemizable, params: same_quantities_attributes, event_class: DonationEvent)
233+
234+
expect(DonationEvent.count).to eq(2)
235+
end
218236
end
219237
describe "with distributions" do
220238
before(:each) do

0 commit comments

Comments
 (0)