human-essentials icon indicating copy to clipboard operation
human-essentials copied to clipboard

prevent multiple imports of inventory

Open fchatterji opened this issue 1 year ago • 12 comments

Resolves #3687

Description

Added a check that the storage location doesn't already have items before importing the inventory. This prevents double imports and makes sure that, whenever an import is made, items can only be added. Added the corresponding error, handled it in the controller to show it to the user Disable the button after click by using the existing ui helper "submit button"

Added the replace inventory option, used only for the inventory csv import. With the option enabled, imports replace existing quantities instead of just adding. It's not great code as it adds to the already overly complex increase inventory function,there's probably a refactor to do and change the logging, in a separate issue.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Added tests in the model

Screenshots

the new error: image

if you click on the button to import, you can see the disabled state, with text "in progress"

fchatterji avatar Jun 28 '23 15:06 fchatterji

Hey @fchatterji - this isn't what was asked for in the ticket. We'd like the import to still work, but to adjust the levels of inventory to match what's in the import, rather than blindly adding them.

dorner avatar Jun 28 '23 21:06 dorner

@dorner ok, what I did was prevent importing when there are already items in the inventory. So whenever an import is made, it is made on an empty inventory. So the inventory after import will always match the content of the import (it cannot add if there is nothing before adding, if you have 10 in the import you'll always have 10 in the inventory at the end).

But yeah right now the import inventory method in storage location still uses an "adjustment", so if there were values in the inventory it would add to them. So I guess you want me to remove this?

fchatterji avatar Jun 29 '23 17:06 fchatterji

So the idea here is to have the ultimate inventory match what's in the import, regardless of what's in the inventory right now. For example:

Current inventory:

1 item1, 2 item2

Import:

2 item1, 3 item2

This would result in an increase of 1 to item1 and an increase of 1 to item2.

dorner avatar Jun 29 '23 18:06 dorner

ok gotcha, the PR is ready for review

fchatterji avatar Jun 30 '23 16:06 fchatterji

Hey, so i adjusted the PR for a new review. As discussed on slack, i left the inventory already has items error.

fchatterji avatar Jul 02 '23 16:07 fchatterji

@cielf can you take a look at this? I'm still a bit fuzzy on what the issue is asking compared to what's being done in the PR.

dorner avatar Jul 06 '23 19:07 dorner

Am looking at it, and it is complicated... g .. Sorry it has taken me so long -- I kept handling the easier ones.

This issue was born because people were managing to import inventory twice, even though they weren't supposed to, and it was doubling the inventory.

So we wanted import to effectively replace rather than add.

The issue also has a bunch of measures to prevent this happening in the first place. Not sure why we had both.

cielf avatar Aug 17 '23 13:08 cielf

@fchatterji Sorry for the delay and the confusion. We discussed and decided that your original approach which focused on preventing imports from happening if the storage location had any inventory was the correct thing to do - replacing existing inventory is a red herring and we do not want or need that.

Really sorry for the back and forth here. Hope this is still workable!

dorner avatar Aug 20 '23 14:08 dorner

I also updated https://github.com/rubyforgood/human-essentials/issues/3687 to reflect the clarified thinking!

awwaiid avatar Aug 20 '23 14:08 awwaiid

@dorner No worries, i understand. So what remains to be done on this ticket? Just removing the split_difference?

fchatterji avatar Aug 30 '23 01:08 fchatterji

Yes, and please revert the PR back to the original approach.

dorner avatar Aug 30 '23 12:08 dorner

@fchatterji there's been no movement on this in a very long time - are you still around?

dorner avatar Apr 05 '24 20:04 dorner

This was replaced by https://github.com/rubyforgood/human-essentials/pull/4300 I think! Thank you for the work @fchatterji, parts of it went into the merged PR.

awwaiid avatar May 20 '24 12:05 awwaiid