-
-
Notifications
You must be signed in to change notification settings - Fork 504
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
Invalid item inventory #3982
Invalid item inventory #3982
Conversation
Noting for @awwaiid 's benefit that we are going to have to communicate to the affected banks when this goes out |
But wait! What about the historical trends graph? |
I don't think they use inventory. |
However there is another edge case I just thought of -- reclaiming distributions. Might never happen, but.. |
And, of course, what happens if someone edits a donation or purchase that has an inactive item in it. Le Sigh |
I think if we're talking event-based, neither of those should be an issue. Editing something updates it at the time it was done - so if there are items that are now inactive, they may not have been inactive at the time of the donation etc. and they should show up on the edit page and in the event. Same with reclaiming (aka destroying) a distribution - we fire a new event that just says "this distribution never happened". |
return | ||
end | ||
|
||
if @item.save |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did we change from update to save?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update
both sets the parameters and saves in a single function. In this case we're setting the parameters early (to check if the active
parameter changed) and then saving it after our check.
app/controllers/kits_controller.rb
Outdated
@kit.reactivate | ||
redirect_back(fallback_location: dashboard_path, notice: "Kit has been reactivated!") | ||
else | ||
redirect_back(fallback_location: dashboard_path, alert: "Cannot reactivate kit - it has inactive item! Please reactivate the items first.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tiny grammar thing -- s.b. "it has inactive items!"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple more things to think about, if we haven't already (I just woke up, so the memory is not completely online yet)
What happens if editing a dist, and decreasing the # of the inactive item?
What happens if a request comes in with an inactive item?
What happens if a purchase/donation is edited and the amount on an inactive item is changed?
|
Yeah, all of this really hinges on the idea that editing a distribution is fixing a clerical error. If it actually represents real life changes, then it's potentially a different matter. |
While working on #3998 I noticed that inactive items are being reactivated upon editing distribution. I found that to be odd and may need some help understanding that. |
Ah, I knew I saw something weird. Yeah, it's very odd that we automatically make an item active whenever e.g. editing a distribution to change the amount of an item that's now inactive. It's like we kind of knew that inactive items were bad in a storage location, but also kind of didn't? In any case we probably should not be doing this without any notification to the user. This might be why I saw some organizations with three items with almost identical names, all with different quantities. |
I'll make some updates on Friday hopefully. |
Per discussion on Jan. 21 - we should prevent changing the inventory values for inactive items, by editing any Itemizable (i.e. if the edit would change the values of an item that is now inactive, it should fail). |
# Conflicts: # db/schema.rb
Fix pushed as per discussion @cielf |
Hey @dorner. Here's a thought: Regarding the migration making inactive items that are in (active) kits active, I suggest that we should make them not visible to partners. Reasoning: If they are inactive, the bank is definitely not offering them to the partners, and this would be the path of least surprise. |
# Conflicts: # app/controllers/items_controller.rb # app/controllers/storage_locations_controller.rb # app/queries/items_by_storage_collection_and_quantity_query.rb # app/views/distributions/_form.html.erb # spec/models/storage_location_spec.rb # spec/services/itemizable_update_service_spec.rb
Over to @awwaiid, then! |
@@ -142,7 +142,6 @@ def increase_inventory(itemizable_array) | |||
# This is, at least for now, how we log changes to the inventory made in this call | |||
log = {} | |||
# Iterate through each of the line-items in the moving box | |||
Item.reactivate(itemizable_array.map { |item_hash| item_hash[:item_id] }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very good
@@ -0,0 +1,23 @@ | |||
class RemoveInvalidInventory < ActiveRecord::Migration[7.0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Certainly the scariest thing here. Looks good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This all look great and I'm happy for the cleanup. I'm not merging it immediately until I confirm the timing.
@dorner: Your PR |
As per discussion with @cielf .
Currently, we allow items to be turned inactive even when it has inventory in a storage location, or is included in an active kit. Both of those things shouldn't be allowed, because it puts the system in an unknown state (what does it mean to have inventory of an item that isn't valid? Or to distribute kits that have invalid items in them?)
This PR makes a number of changes to make this flow stricter.
This will help with the event sourcing project as we will not need to track the active status of items for querying them on an inventory basis.