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

Improve synchronization of items and their kits -- active status

Open cielf opened this issue 2 years ago • 12 comments

Summary

When you change the active status of a kit, that should be reflected in its corresponding item, and vice versa

Why

Reduce bank confusion (and support questions)

Details

When you create a kit, a corresponding item is also created. Currently The item and the kit can be deactivated/reactivated independently.
The active status of the kit and the item should always be the same.

  • If you deactivate an item, then deactivate the kit also.
  • If you deactivate a kit, then deactivate the item also
  • Similarly for reactivation.

Criteria for completion

  • [ ] Kits and Items active status are kept the same
  • [ ] Tests confirming this behaviour

cielf avatar Jan 26 '23 17:01 cielf

Hey, I'd like to work on this issue if possible :)

fchatterji avatar Feb 19 '23 22:02 fchatterji

It's yours!

dorner avatar Feb 19 '23 23:02 dorner

Hey @dorner @cielf , I checked the code. As the kit status and item status must always be the same, I would propose keeping just one database field, the item status. The kit status can then be delegated to item status. Because why have two database fields when they contain the same information.

There's a snag though: in the current code, kits must have at least one line item (there is a validation for it), but they must not have an item (there is no validation), even though items and line items are linked. So you can theoretically create a kit, with a line item pointing to an item on a different kit. Is that intended?

If it's a feature, then the only way I see to resolve the issue is to use multiple callbacks on create and update, on both kits and items, to ensure sync.

fchatterji avatar Feb 20 '23 17:02 fchatterji

That sounds like it's an oversight rather than a feature. @cielf can you confirm?

dorner avatar Feb 20 '23 18:02 dorner

Remembering that kits contain items, but there is an item that contains/represents the whole kit -- and it's hard to talk about both. So I'm not 100% sure that I get the question... here goes.

From the business point of view, you should be able to have the same item appear in different kits. For example, you might have a kit that has 50 newborn diapers and some wipes, and have another kit that has 40 size 6 diapers, wipes, and a book. In both cases, that kit would have the item "wipes".

Does that clear things up?

For clarity -- when we're talking about keeping the item and the kit synchronized we are talking about the item that "is" the kit, rather than the items that are pointed to by the line items In the kit.

cielf avatar Feb 20 '23 21:02 cielf

@cielf Hmm, ok sorry for the unclear question. Let me try again :)

When i talk about item and kit i talk about the "item" and "kit" models in rails. The fields you want synchronized are item.active and kit.active. Best solution seems to me to just keep one field in the database, to avoid a complex sync. The kit and item model have a one-on-one relationship. So we could keep item.active. To get kit.active, you would just look at the corresponding item.active field.

This would work, except that you can create a kit without an item. Question is, is it normal to be able to create a kit without an item? And Iḿ asking because a kit must have at least one line item (there is a validation for it in the kit model, line 51), so it seems logical to have also an item.

Hoping this makes it clearer. Or am I just overthinking this and we could add callbacks to synchronise the two fields?

fchatterji avatar Feb 22 '23 02:02 fchatterji

Ah. Are you saying that a kit can be created without an item through the user interface? Or just that the model allows it. If the latter (but not the former) I would term it an oversight. If you're saying we can create kits without items through the app, I'll need to take a deeper look to answer your question.

Your logic does not take into account that there are two different ways that kits relate to items. One is that there is an item that represents the kit, the other are the items that the kit "contains". I'm 99% sure that the line items relate to the latter, and the item, the former. Does that track?

cielf avatar Feb 22 '23 03:02 cielf

@cielf Yes i was talking about the rails models, it is not possible in the interface, it returns an error. I'll try to fix the oversight.

Thanks for the info, I understand the confusion, yeah I was only talking about the item representing the kit.

fchatterji avatar Feb 22 '23 11:02 fchatterji

This issue has been inactive for 252 hours (10.50 days) and will be automatically unassigned after 108 more hours (4.50 days).

github-actions[bot] avatar Mar 05 '23 00:03 github-actions[bot]

This issue has been inactive for 372 hours (15.50 days) and is past the limit of 360 hours (15.00 days) so is being unassigned.

github-actions[bot] avatar Mar 10 '23 00:03 github-actions[bot]

All things Kit are currently Blocked -- we are considering a redesign of the whole Kit-and-Kaboodle, and hence are putting things on hold.

cielf avatar Apr 18 '23 23:04 cielf

This was mostly resolved by #3982 - rspecs testing that active/inactive status are kept the same are missing, but that might be moot soon since I'm making good progress on #3707 and planning on tackling the rest of #3652

jimmyli97 avatar Aug 02 '24 03:08 jimmyli97

Redesign is prioritized over this interim change, which would not be needed after kit redesign.

ruestitch avatar Oct 12 '25 14:10 ruestitch