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

Added #14979: add checkout to location and assets functionality to accessories #15185

Conversation

arne-kroeger
Copy link

Added #14979: add checkout functionality to accessories

Description

Currently it is just possible to checkout accessories to a user and not to a location or asset like it is possible for assets. This would cover many use cases where a workplace definition can be done with a location or an assignment of accessories to a room. There are several uses case descriptions in the linked issues (see below).

Added #14665
Added #12381
Added #12452
Added #11820
Added #10956
Added #5140 (parts of it)
Added #14979 (parts of it)

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Tests\Feature\Checkouts\Ui\AccessoryCheckoutTest::testAccessoryCanBeCheckedOutToLocationWithQuantity
  • Tests\Feature\Checkouts\Ui\AccessoryCheckoutTest::testAccessoryCanBeCheckedOutToAssetWithQuantity

Test Configuration:

  • PHP version: 8.3.9
  • MariaDB version - 10.11
  • Webserver version - php server
  • OS version - Mac OS

Checklist:

arne-kroeger added 2 commits July 29, 2024 10:54
Copy link

what-the-diff bot commented Jul 29, 2024

PR Summary

  • Refactor of Accessory Checkouts
    The main functionality this PR introduces is renaming the 'users' relationship to 'checkouts' in the accessory model. This rework improves the clarity and purpose of the relationship, making it more intuitive to understand for developers and users alike.

  • Enhancement in Accessory Controllers, Helper, and Transformers Files
    The code which used to interact with the 'users' relationship in these files is now updated to work with the new 'checkouts' relationship. This ensures that the changes in the data model maintain their consistency throughout the application.

  • Introduces 'AccessoryCheckout' Model
    A new file, 'AccessoryCheckout.php', has been added to the model folder. This model serves as the representation of a 'checkout' instance in our application and formalizes the relationship between a user and accessories.

  • Update in 'User.php' Relationship
    We also updated the user model to replace the previous relationship, 'accessories_users', to 'accessories_checkout'. This aligns with the newly introduced Accessory checkout model and maintains the coherence in the data representation.

  • Changes in 'AccessoryPresenter.php' and 'AccessoryFactory.php'
    Both of these files now refer to the updated 'checkouts' relationship and the newly named 'checkouts_count' instead of the former 'users_count'.

  • Database Migration Included
    To make the shift from 'accessories_users' to 'accessories_checkout', a new migration file has been created. This migration will rename the existing table and add a new 'assigned_type' column.

  • Changes in Views and Tests
    The views have been updated to reflect the new changes. Alongside the visualization changes, the test files have likewise been updated to ensure that they continue to validate the application correctly utilizing the new 'checkouts' relationship.

  • Improvement in Checkout Logic
    The checkout process sees significant improvements. Instead of only checking out to users, it can now handle asset and location checkouts. Also introduced are the changes in validation and assertion techniques which makes the process more agile and aligns with the introduced representation changes.

@snipe
Copy link
Owner

snipe commented Jul 29, 2024

We haven't built this functionality because we don't really want it. Our position has always been that you should be checking items out to users, since an asset or location cannot be held responsible for missing items.

@snipe
Copy link
Owner

snipe commented Jul 29, 2024

Let me spend some time looking at this and we'll consider whether we want to take this. As I mentioned, we didn't really want this functionality since it goes against the principles of what an asset system is supposed to do, but I'll consider it.

@arne-kroeger
Copy link
Author

We haven't built this functionality because we don't really want it. Our position has always been that you should be checking items out to users, since an asset or location cannot be held responsible for missing items.

As there is an option to define a manager for a location I see a good way to assign a responsiblity here.

Our use case is also important to desk sharing topics where some of the accessories are part of a bookable working place for the employees. To give these items out on a daily basis is a lot of work. The idea is to assign locations via an additional workplace booking system on a time based ticket and handle the responsibility by it.

@snipe
Copy link
Owner

snipe commented Jul 29, 2024

As there is an option to define a manager for a location I see a good way to assign a responsibility here.

Sure, but we don't have anything built in for them to be able to accept, etc. Right now it's just a field for reference, there are no controls there, and very few people use managers for locations anyway.

@snipe
Copy link
Owner

snipe commented Jul 29, 2024

To give these items out on a daily basis is a lot of work. The idea is to assign locations via an additional workplace booking system on a time based ticket and handle the responsibility by it.

I get that, but it opens the doors to people in other situations who don't use an external "responsible for" application.

As I said, let me think about it.

public function down(): void
{
if (Schema::hasTable('accessories_checkout')) {
Schema::rename('accessories_checkout', 'accessories_users');
Copy link
Owner

Choose a reason for hiding this comment

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

We probably want to drop the column created in the up migration as well, no?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, I will adjust that.

Copy link
Author

Choose a reason for hiding this comment

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

Adjusted

@snipe snipe changed the title Added #14979: add checkout functionality to accessories Added #14979: add checkout to location and assets functionality to accessories Jul 29, 2024
Copy link
Collaborator

@uberbrady uberbrady left a comment

Choose a reason for hiding this comment

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

This is some genuine good-looking code - I have a few small nits I've pointed out, but I feel like 80% of this is just handling that the table name has changed. This really does look pretty good to me. Wonderful, very well-written, tight, careful code. Thank you so much for your contribution!

@@ -316,19 +314,19 @@ public function checkout(AccessoryCheckoutRequest $request, Accessory $accessory
*/
public function checkin(Request $request, $accessoryUserId = null)
{
if (is_null($accessory_user = DB::table('accessories_users')->find($accessoryUserId))) {
if (is_null($accessory_checkout = DB::table('accessories_checkout')->find($accessoryUserId))) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since we're already modifying this line, is there maybe a way for us to not say DB::table() here? That always feels to me like a code smell. And the line's already being altered, is there a way to do this properly polymorphic and make it a little cleaner?

Copy link
Author

Choose a reason for hiding this comment

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

Adjusted

app/Http/Controllers/Api/AccessoriesController.php Outdated Show resolved Hide resolved
app/Models/Accessory.php Show resolved Hide resolved
@snipe
Copy link
Owner

snipe commented Jul 29, 2024

@arne-kroeger I'm seeing some failing tests here - do you think you can take a look at this. I'm reluctantly inclined to take this (not because your code is bad - it's great - just from a product perspective), but we do need the tests to pass.

@snipe snipe merged commit 4eccb5f into snipe:develop Jul 29, 2024
8 of 9 checks passed
Copy link

welcome bot commented Jul 29, 2024

Congrats on merging your first pull request! 🎉🎉🎉

@snipe
Copy link
Owner

snipe commented Jul 29, 2024

I think you might have missed a bit in the seeder, but I think I fixed it

DB::table('accessories_users')->truncate();

@snipe
Copy link
Owner

snipe commented Jul 29, 2024

Something still seems off here. On develop.snipeitapp.com (the live dev branch) I just checked out an accessory to a location, and now the accessories page loads with an empty table, and the location does not show any accessories assigned.

@snipe
Copy link
Owner

snipe commented Jul 29, 2024

False alarm on accessories not loading (weirdly, it was a 429 error, which probably bears investigation), but the location doesn't show anything checked out to it.

Screenshot 2024-07-29 at 8 36 10 PM Screenshot 2024-07-29 at 8 36 20 PM

@arne-kroeger
Copy link
Author

arne-kroeger commented Jul 29, 2024

False alarm on accessories not loading (weirdly, it was a 429 error, which probably bears investigation), but the location doesn't show anything checked out to it.

Thats a good point.

Currently the location would show Accessories which are placed there (in terms of the field location inside the accessory). What would be you're recommendation?

A mixed list of placed and checked out accessories?

@snipe
Copy link
Owner

snipe commented Jul 30, 2024

I think you're starting to see why we didn't build this. It's always more complicated than it seems. I suppose we should handle it the way we do locations, where there are assets that belong to that location, and then there are assets that are checked out to that location. Different tabs. I don't think there's a way to make it not-confusing.

Screenshot 2024-07-30 at 11 38 50 AM

@arne-kroeger
Copy link
Author

@snipe - Yeah, but I think in the end it will be a good enhancement. I will prepare an integration for it and prepare it.

@snipe
Copy link
Owner

snipe commented Aug 3, 2024

This also misses the "Print all assigned" views on locations, etc. We need to pull accessories into there as well.

@snipe
Copy link
Owner

snipe commented Aug 3, 2024

This may also require a rework of the locations layout altogether, as you can see adding additional tabs here causes them to wrap, and this could potentially only get much worse with other languages that use longer words.

Screenshot 2024-08-03 at 12 24 25 PM

I may have to revert this PR until it's more complete and thought through. :( Right now, letting people check things out to a location but not actually seeing them on the locations page will be a very confusing UI.

@@ -219,7 +219,7 @@ public function destroy(Request $request)

$users = User::whereIn('id', $user_raw_array)->get();
$assets = Asset::whereIn('assigned_to', $user_raw_array)->where('assigned_type', \App\Models\User::class)->get();
$accessories = DB::table('accessories_users')->whereIn('assigned_to', $user_raw_array)->get();
$accessories = DB::table('accessories_checkout')->whereIn('assigned_to', $user_raw_array)->get();
Copy link
Owner

Choose a reason for hiding this comment

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

I think this query will also not work, since it's not constraining to users. Location ID could get pulled from that list as well as User ID 4.

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

Successfully merging this pull request may close these issues.

3 participants