-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor stock related service objects to deal with inventory units.
Prior to this change, stock related service objects (coordinator, packer, prioritizer, package, adjuster) were tightly coupled to orders and line items, such that they would only create a set of shipments for the set of line items for an order. This change makes those objects work with inventory units, which enables future enhancements that would create shipments for an order that are not necessarily tied to the initial purchase (e.g. upcoming exchanges work). Fixes #5042
- Loading branch information
Showing
31 changed files
with
403 additions
and
284 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
module Spree | ||
module Stock | ||
class ContentItem | ||
attr_accessor :inventory_unit, :state | ||
|
||
def initialize(inventory_unit, state = :on_hand) | ||
@inventory_unit = inventory_unit | ||
@state = state | ||
end | ||
|
||
def variant | ||
inventory_unit.variant | ||
end | ||
|
||
def weight | ||
variant.weight * quantity | ||
end | ||
|
||
def line_item | ||
inventory_unit.line_item | ||
end | ||
|
||
def on_hand? | ||
state.to_s == "on_hand" | ||
end | ||
|
||
def backordered? | ||
state.to_s == "backordered" | ||
end | ||
|
||
def price | ||
variant.price | ||
end | ||
|
||
def amount | ||
price * quantity | ||
end | ||
|
||
def quantity | ||
# Since inventory units don't have a quantity, | ||
# make this always 1 for now, leaving ourselves | ||
# open to a different possibility in the future, | ||
# but this massively simplifies things for now | ||
1 | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module Spree | ||
module Stock | ||
class InventoryUnitBuilder | ||
def initialize(order) | ||
@order = order | ||
end | ||
|
||
def units | ||
@order.line_items.flat_map do |line_item| | ||
line_item.quantity.times.map do |i| | ||
InventoryUnit.new( | ||
pending: true, | ||
variant: line_item.variant, | ||
line_item: line_item | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.