New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Orphaned Inventory Units in Backend, Possibly Related to Spree::Order#associate_user! #6675
Comments
I believe this is a duplicate of #6605 |
I was able to reproduce the orphaned InventoryUnit while using @tesserakt's modified If you take the steps outlined above with the following in the application: Spree::Stock::InventoryUnitBuilder.class_eval do
def initialize(order)
@order = order
end
def units
@order.line_items.flat_map do |line_item|
line_item.quantity.times.map do |i|
Spree::InventoryUnit.new(
pending: true,
variant: line_item.variant,
line_item: line_item,
order: @order
)
end
end
end
end The issue above is still reproducible. |
Perhaps it would be useful to look at additional output after following the steps in the issue above. The following are the InventoryUnit associated with the Order after taking the steps above. [
#<Spree::InventoryUnit id: 372,
state: "on_hand",
variant_id: 2079,
order_id: 152,
shipment_id: 297,
created_at: "2015-08-18 14:40:59",
updated_at: "2015-08-18 14:40:59",
pending: true,
line_item_id: 282>,
#<Spree::InventoryUnit id: 373,
state: "on_hand",
variant_id: 2079,
order_id: 152,
shipment_id: 298,
created_at: "2015-08-18 14:41:21",
updated_at: "2015-08-18 14:41:21",
pending: true,
line_item_id: 282>] The InventoryUnit hasn't actually been doubled. They are created at different times and associated with different shipments. The issue is that |
It seems like when I use the admin interface to create orders in the following order,
Spree::InventoryUnit
rows associated with a destroyed shipment will be left behind. To reproduce in 2.4 (I don't have a 3.0 install to test on):Setup
Ensure you have at least one user and the bare minimum to complete an order with shipping method/rate.
Steps
In the Rails console, I can then run
Spree::Order.find_by(number: "ORDER NUMBER").inventory_units
and there will be two records returned. One will be associated with a shipment that exists, the other will not. Running the following will return 1 in the above scenario from a clean install after taking the above steps:Spree::InventoryUnit.where(pending: true).where.not(shipment_id: Spree::Shipment.pluck('id')).count
I believe this occurs because of the call to
update_all
on the order in theSpree::Order#associate_user!
method. However, I'm not sure if this is acceptable behavior or not. Is it Spree's intention to have these orphaned inventory units, or would the expectation be that they are cleaned up when the new shipment is created for the order by associating a user with an address?The text was updated successfully, but these errors were encountered: