Skip to content

Conversation

dorner
Copy link
Collaborator

@dorner dorner commented Jul 11, 2025

This PR makes it so that donations, distributions and purchases can no longer have inventory changes once a snapshot event exists between its creation date and the current time.

This includes both internal model validations as well as UI indicators that show that editing inventory can no longer happen, while still allowing editing of other values.

image

@dorner dorner requested review from awwaiid and cielf July 11, 2025 20:25
@cielf
Copy link
Collaborator

cielf commented Jul 12, 2025

Hey @dorner --
I feel like there is no case where the business would need to delete purchases and donations prior to the last snapshot.

Let's discuss on Sunday whether consistency dictates that we disallow reclaims. (they are so simple)

@cielf
Copy link
Collaborator

cielf commented Jul 12, 2025

In the case where they've already had an audit and it's before the snapshot, we could happily suppress the message about the audit as useless (this was on purchase 4151 from MHM, but I think we do the same on donations and distributions).

@cielf
Copy link
Collaborator

cielf commented Jul 12, 2025

Problem (as opposed to thing that needs discussion) 1:
Here's a sequence that failed,
View an old donation (I used donation 20637, from the start of last year with MHM)
Change the issued_on date
Save
Error updating donation: Cannot update donation because there has been an intervening snapshot of the inventory.
Editing Donation from Misc. Donation
The items also disappeared.
(For a lark, I pressed "save" again, and got a no method error Not sure that that's relevant)

Same thing happens if you change the comment.

@cielf
Copy link
Collaborator

cielf commented Jul 12, 2025

Problem 2:
A similar problem happens with editing the old pruchase -- though the items don't disappear in that case. I expected to be able to update the comment. (#4151, which is the first purchase of last year for MHM, if you're trying to recreate).

Problem 3:
Same for distribution (62502, first distribution of 2024 for MHM)

cielf
cielf previously requested changes Jul 12, 2025
Copy link
Collaborator

@cielf cielf left a comment

Choose a reason for hiding this comment

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

Let's talk about reclaims and deletes on Sunday, but please see the above problems.

@dorner
Copy link
Collaborator Author

dorner commented Jul 18, 2025

@cielf I've fixed the audit warnings and the disallowing of editing with no inventory changes (turns out if you disable everything, it doesn't send any parameters at all for it!)

Did we discuss the reclaiming? I don't remember.

@cielf
Copy link
Collaborator

cielf commented Jul 19, 2025

It looks like we did, but I don't remember what we decided either. Adding it for this week.

@cielf
Copy link
Collaborator

cielf commented Jul 21, 2025

So, adding a note here to confirm what we discussed -- that we are disallowing the reclaiming of distributions entered before before the snapshot.

@cielf
Copy link
Collaborator

cielf commented Jul 28, 2025

@dorner

I'm only part way through the testing -- I've noticed one thing that's jarring.

Some, at least, of the error messaging is a bit awkward or misleading. Recording examples here to inform action;

-- Donation 22692 failed to be removed because Cannot delete this donation because it has an intervening snapshot.
-- Cannot delete this purchase because it has an intervening snapshot (not bad, but do they know what a snapshot is?)
-- Could not destroy distribution 70150. Please contact technical support. (I think we don't need them to anymore.)

Can we make it so that we have the same pattern for all of the itemizables? (Is that out of scope?)

I'm trying to think about how to express it best to the users -- who might not know what a snapshot is, and think they've done something wrong.

At the moment, I like the following pattern -- but I'm open to suggestions:

"We can't delete Donation 22892. This donation was entered before the latest inventory snapshot (2024/05/26)."

Or merely,

"We can't delete Donations entered before [date of snapshot].

Or

"We can't delete this Donation because it is too old"

Thoughts? I like including the ID for support reasons.

@cielf
Copy link
Collaborator

cielf commented Jul 28, 2025

it's looking good other than that, though.

@dorner
Copy link
Collaborator Author

dorner commented Aug 1, 2025

@cielf tried to fix as much as I could. Let me know if there's anything else needed.

@cielf
Copy link
Collaborator

cielf commented Aug 2, 2025

I didn't get to this in today's session -- will look at it Monday -- I think we're at a point where we can pass it to @awwaiid for the technical pass, though.

@cielf
Copy link
Collaborator

cielf commented Aug 4, 2025

I need to apologize for calling out the error messaging - it distracted me from how we should actually be handling this. We should be consistent in how we handle distributions, donations, and purchases -- that is, we should also be disabling the item quantity edits on purchases and donations, right?

Or am I missing something?

@awwaiid
Copy link
Collaborator

awwaiid commented Aug 9, 2025

@cielf if I'm reading this change correctly it has a core implementation on Event itself that prevents inventory edits on anything created before a snapshot, and most of the rest is making that friendly. So it should prevent purchases and donations too. Mind you I've only read the code, not run it yet :)

@cielf
Copy link
Collaborator

cielf commented Aug 9, 2025

@awwaiid I was referring to the UI -- IIRC when last I looked at this, the user was prevented from attempting inventory changes on old distributions, but not on old donations and purchases -- those were caught at save.

@cielf
Copy link
Collaborator

cielf commented Aug 9, 2025

@dorner Minor thing, but in case I've missed something -- is this a full solution for #5262, if so, please note that in the top comment (I feel like maybe it wasn't originally, but now is)

@dorner
Copy link
Collaborator Author

dorner commented Aug 10, 2025

@cielf this should work for all three types.

@dorner dorner force-pushed the 5262-editing-old-inventory branch from c6fe3e6 to 79ed827 Compare August 10, 2025 14:18
Copy link
Collaborator

@cielf cielf left a comment

Choose a reason for hiding this comment

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

LGTM, functionality-wise, so it's on @awwaiid's plate for the technical review.

@awwaiid awwaiid self-assigned this Aug 24, 2025
# @param record [#organization_id, #created_at]
# @return [SnapshotEvent, nil] the intervening snapshot event or null if there aren't any
def self.intervening(record)
where(organization_id: record.organization_id, event_time: record.created_at..).first
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need a sort to reliably get the first snapshot after record create? Also, should we get the most recent? Or does neither matter and we are wanting to know if there is ANY intervening?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed! It should always get the most recent one.


it "does not delete the donation if there is an intervening snapshot" do
data = EventTypes::Inventory.new(storage_locations: {}, organization_id: organization.id)
travel(-1.day) do
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there any reason that sometimes we time-travel to back date the SnapshotEvent and sometimes we put an older timestamp as the created_at/event_time?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not particularly. Just how the tests were written.

@dorner dorner requested a review from awwaiid October 10, 2025 17:40
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.

Looks great!

@awwaiid awwaiid dismissed cielf’s stale review October 12, 2025 14:12

All validated

@awwaiid awwaiid merged commit ff8c978 into main Oct 12, 2025
31 of 35 checks passed
@awwaiid awwaiid deleted the 5262-editing-old-inventory branch October 12, 2025 14:12
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