Skip to content

Commit 99d417d

Browse files
authored
add unicity on low inventory query items returned (#4782)
1 parent a1d71fc commit 99d417d

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

app/queries/low_inventory_query.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class LowInventoryQuery
22
def self.call(organization)
33
inventory = View::Inventory.new(organization.id)
4-
items = inventory.all_items
4+
items = inventory.all_items.uniq(&:item_id)
55

66
low_inventory_items = []
77
items.each do |item|

spec/queries/low_inventory_query_spec.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,32 @@
8484
})
8585
}
8686
end
87+
88+
context "when items are in multiple storage locations" do
89+
let(:recommended_quantity) { 300 }
90+
let(:secondary_storage_location) { create :storage_location, organization: organization }
91+
let!(:secondary_purchase) {
92+
create :purchase,
93+
:with_items,
94+
organization: organization,
95+
storage_location: secondary_storage_location,
96+
item: item,
97+
item_quantity: inventory_item_quantity,
98+
issued_at: Time.current
99+
}
100+
101+
it {
102+
expect(subject.count).to eq 1
103+
}
104+
105+
it {
106+
is_expected.to include({
107+
id: item.id,
108+
name: item.name,
109+
on_hand_minimum_quantity: 0,
110+
on_hand_recommended_quantity: 300,
111+
total_quantity: 200
112+
})
113+
}
114+
end
87115
end

0 commit comments

Comments
 (0)