Skip to content
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

Disable inactivating item with inventory and don't show inactive item… #4179

Merged
merged 12 commits into from
Mar 17, 2024

Conversation

dorner
Copy link
Collaborator

@dorner dorner commented Mar 10, 2024

…s on storage location.

Might have some failing tests here as I updated the inventory_for to stop showing zero-inventory items, so might need to fix other expectations.

@cielf
Copy link
Collaborator

cielf commented Mar 11, 2024

@dorner Hrm. That's not quite what I expected. The storage location should show active items with 0 inventory (if it's ever had them -- I'm not sure if we currently show inventory levels in an SL if it's never had the items) just not inactive ones.

@dorner
Copy link
Collaborator Author

dorner commented Mar 11, 2024

It should still show them on the storage location page because it explicitly includes them in the query.

@cielf
Copy link
Collaborator

cielf commented Mar 11, 2024

It's still letting me inactivate with non-zero inventory, too.

@cielf
Copy link
Collaborator

cielf commented Mar 11, 2024

After inactivating a couple, I got this on signing in again: View::Inventory::ViewInventoryItem#name delegated to db_item.name, but db_item is nil: #<View::Inventory::ViewInventoryItem item_id=1 quantity=0 storage_location_id=1 db_item=nil>" Edit: I'll see if i can recreate this.

@cielf
Copy link
Collaborator

cielf commented Mar 11, 2024

It should still show them on the storage location page because it explicitly includes them in the query.

Well, I did an inventory adjustment of AB L/XL down to 0, and it disappeared from the SL page. Checked the current behaviour on the production branch -- it doesn't disappear.

@dorner
Copy link
Collaborator Author

dorner commented Mar 11, 2024

Hmm... not sure what happened here then. Will take this back.

@cielf
Copy link
Collaborator

cielf commented Mar 13, 2024

Please make this one your first priority, coding-wise, as it will hold up the release. Danke.

@dorner
Copy link
Collaborator Author

dorner commented Mar 14, 2024

@cielf Pushed a fix to show the 0-inventory items. I haven't been able to recreate the other two things you mentioned.

@cielf
Copy link
Collaborator

cielf commented Mar 14, 2024

Ignore the comment from 2:28 or so. Didn't have the very latest. Am trying to recreate again.

@cielf
Copy link
Collaborator

cielf commented Mar 14, 2024

Well, the first part is definitely still happening on my local, without read_events:
Login as org_admin1@example.com
Click Inventory, then Storage Location, them the 'view' button beside Adult Briefs L/XL. Confirm that it is not zero.
Click items & Inventory, then click the 'Delete' beside Adult Briefs L/XL. Click OK. It says that item has been removed, and it does not appear in the list anymore.
We shouldn't according to my understanding, be able to delete that item, because it has inventory.

@cielf
Copy link
Collaborator

cielf commented Mar 14, 2024

I'm getting the same results with read_events enabled.

@dorner
Copy link
Collaborator Author

dorner commented Mar 14, 2024

@cielf deleting an item is not the same as making it inactive. There is a checkbox in the "edit" page that does that.

@cielf
Copy link
Collaborator

cielf commented Mar 14, 2024

Hrm. Um - but it shows up again if I click 'Also include inactive items" So what is the difference? (We may have a terminology inconsistency)

@cielf
Copy link
Collaborator

cielf commented Mar 14, 2024

Also - on the read_events side, after deleting the item, I got the error I mentioned (View::Inventory::ViewInventoryItem#name delegated to db_item.name, but db_item is nil: #<View::Inventory::ViewInventoryItem item_id=1 quantity=699 storage_location_id=1 db_item=nil>) If I tried to view the storage location after the above steps.

@dorner
Copy link
Collaborator Author

dorner commented Mar 14, 2024

... Item.destroy is redefined to instead deactivate it. 🤦 so we have to copy that check to that place. I'd rather fix it so that doesn't happen, tbh, and have that handled in a delete service.

Thanks - will look again tomorrow.

@cielf
Copy link
Collaborator

cielf commented Mar 14, 2024

The delete calls item.destroy , which is overriden to call deactivate if the item has history
From item.rb:

def destroy
if has_history?
deactivate
else
super
end
end

@dorner
Copy link
Collaborator Author

dorner commented Mar 14, 2024

This is a footgun just waiting to go off. Looks like there is already an issue because one code path will deactivate an associated kit and the other won't.

@cielf any issues with removing one or the other paths? I think it'll be simpler to require users to click the "Delete" button to deactivate the item, and remove the checkbox from the update path. We can update the wording on the item to "Deactivate" if it has history. Thoughts?

@cielf
Copy link
Collaborator

cielf commented Mar 15, 2024

If we're only to keep one, I would keep the button in the list. I like the idea of changing the wording.

We can probably 'sell' it as a simplification.

@dorner
Copy link
Collaborator Author

dorner commented Mar 15, 2024

@cielf finally got this done
image

Item page will show "Delete" if it has no history at all, "Deactivate" if it has history but no inventory/kits, and a disabled "Deactivate" button if it has either of those and hence can't even be deactivated. Removed the "Item Is Active?" field from the edit page.

Not sure if some tests will fail, will wait to see.

@dorner
Copy link
Collaborator Author

dorner commented Mar 15, 2024

Finally good to go here I think!

@cielf
Copy link
Collaborator

cielf commented Mar 16, 2024

From functional test: If you have an active item that been in a storage location but is now 0 there, the storage location should show in the list in the item view (Inventory | Items & Inventory | view the item in question). It isn't appearing if read_events is enabled.
I'm willing to let this go forward with this issue in place and fix it for next time.

@cielf
Copy link
Collaborator

cielf commented Mar 16, 2024

From functional test. Still getting this, with read_events enabled, viewing a storage location after having deactivated an item. FWIW, the item was deactivated with read_events off (I think) but that is certainly in the "could happen" category.
Screenshot 2024-03-16 at 8 57 03 AM

(Sigh) And I can make it disappear. Will recreate from fresh seed.

@cielf
Copy link
Collaborator

cielf commented Mar 16, 2024

Here is a shortish path to the error:
1/ fully enable read_events
2/ login as org_admin1
3/ Inventory Adjustments — put Adult Briefs L/XL to 0 for both storage locations
4/ Items & Inventory — Deactivate AB L/XL
5/ Storage Locations
and I get the error

If I restore the item, the error goes away.

@cielf
Copy link
Collaborator

cielf commented Mar 16, 2024

So. It looks good to me, functionally, when read_events is not enabled, but is not ready for prime time when read_events is enabled.

FWIW, This sequence was not in my event source testing list. So this problem may have already been there.

@cielf cielf requested a review from awwaiid March 16, 2024 13:37
@cielf
Copy link
Collaborator

cielf commented Mar 16, 2024

I checked against the production branch, though, and I didn't get the error. That was unexpected. EDIT: Seems ok on main too!?

@cielf
Copy link
Collaborator

cielf commented Mar 16, 2024

@dorner It appears to me that StorageLocation.items_inventoried is doing things with all items, but trips over its shoelaces on the inactive item. Given the removal of the filter on Storage Locations, I posit that items_inventoried should only be looking at active items. Does that make sense? (or is that the wrong place to fix this)

EDIT: Nope -- it's also dying in much the same way on the dashboard, so either the place to fix it is further 'down' the chain, or we need to fix it in multiple places.

@dorner
Copy link
Collaborator Author

dorner commented Mar 17, 2024

I think I was being dumb with the View::Inventory class. It's OK for it to have inactive items in its cache because it only uses it to populate the db_item for the in-memory item. As long as we have it, it should be populated. Taking an item that used to be active and making it inactive doesn't change all the previous history that had that item in it, and we should be able to view that.


it "should show all active items with corresponding buttons" do
get items_path(default_params)
page = Nokogiri::HTML(response.body)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I was looking for this the other day for another spec, heh

Copy link
Collaborator

@awwaiid awwaiid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I walked through and also did some interactive testing as well, focusing on the non-event branches. Looks like you just fixed the event-branch issue, and the fix makes sense. All of this look good to me.

Copy link
Collaborator

@awwaiid awwaiid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We reviewed the event-based part together and it looks good/safe.

@awwaiid awwaiid merged commit 05aaec9 into main Mar 17, 2024
20 checks passed
@awwaiid awwaiid deleted the invalid-fixes branch March 17, 2024 14:36
Copy link
Contributor

@dorner: Your PR Disable inactivating item with inventory and don't show inactive item… is part of today's Human Essentials production release: 2024.03.17.
Thank you very much for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants