-
-
Notifications
You must be signed in to change notification settings - Fork 573
Expand file tree
/
Copy pathkit_deallocate_event.rb
More file actions
33 lines (32 loc) · 1.01 KB
/
kit_deallocate_event.rb
File metadata and controls
33 lines (32 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class KitDeallocateEvent < Event
def self.event_line_items(kit, storage_location, quantity)
items = kit.kit_item.line_items.map do |item|
EventTypes::EventLineItem.new(
quantity: item.quantity * quantity,
item_id: item.item_id,
item_value_in_cents: item.item.value_in_cents,
to_storage_location: storage_location,
from_storage_location: nil
)
end
items.push(EventTypes::EventLineItem.new(
quantity: quantity,
item_id: kit.kit_item.id,
item_value_in_cents: kit.kit_item.value_in_cents,
from_storage_location: storage_location,
to_storage_location: nil
))
items
end
def self.publish(kit, storage_location, quantity)
create(
eventable: kit,
group_id: "kit-deallocate-#{kit.id}-#{SecureRandom.hex}",
organization_id: kit.organization_id,
event_time: Time.zone.now,
data: EventTypes::InventoryPayload.new(
items: event_line_items(kit, storage_location, quantity)
)
)
end
end