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

4158 Add validation to disallow negative quantity for kit items. #4163

Merged
merged 5 commits into from
Mar 18, 2024

Conversation

aniketpatidar
Copy link
Contributor

Resolves #4158

Description

This PR fixes the validation for the quantity of items in a kit. Previously, negative values were allowed for the quantity, which does not make sense. This change ensures that only positive values are allowed for the quantity of items in a kit.

Type of change

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

How Has This Been Tested?

To test this change:

  1. Go to Inventory > Kits
  2. Choose "New Kit"
  3. Enter a kit with an item having a negative value
  4. Save the kit

It gives you an error.

  • Negative quantities are disallowed for kit item quantities.
  • Added tests to validate the functionality.

@cielf
Copy link
Collaborator

cielf commented Mar 7, 2024

On a quick testing, I am seeing a problem -- in that if we have an error, the line items are disappearing (and they shouldn't). That's a separate, pre-existing issue, though.

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.

@aniketpatidar Thanks for the PR!

My main role is looking out for the end-user's interest, rather than making sure the technical aspects are perfect.

I'd like to see a friendlier error message here -- the person trying to enter a kit might not understand what they did wrong when they see "Line items.quantity must be a positive number, Line items is invalid," as we don't use that wording in the user interface.

For a model of friendlier errors, I recommend you look in a couple of places:
1/ On kit, If the value for kit is negative, we have a friendlier message: "Value in cents must be greater than or equal to 0",
2/ A better model for this case is on distributions. If we enter a negative item quantity there we give an error like this: "Sorry, we weren't able to save the distribution. Validation failed: Inventory Adult Briefs (Large/X-Large)'s quantity needs to be at least 1"

So, if you could, please, make the error something like "Sorry, we weren't able to save the kit. Validation failed: [Item name]'s quantity needs to be at least 1" that would be ideal.

Thanks again.

@aniketpatidar
Copy link
Contributor Author

Sure, I'll make those adjustments to the error message in the PR. Thanks for the detailed feedback! @cielf

@aniketpatidar
Copy link
Contributor Author

aniketpatidar commented Mar 10, 2024

This looks good to me What do you think about this? 'Line items are invalid' come from this line we are adding to our model kit:
validates_associated: line_items

Screenshot from 2024-03-10, 14-05-03

@cielf
Copy link
Collaborator

cielf commented Mar 10, 2024

That will be better than what you had, but I would prefer it without the "Line Items is invalid". Can you model it after how it is handled with the distributions (which, I believe, also deals with line items, but is not showing that 'line items is invalid')?

Thanks.

@aniketpatidar
Copy link
Contributor Author

I will make these changes as per your suggestion. Thanks!

@aniketpatidar
Copy link
Contributor Author

I've made the updates as per your suggestion.

@cielf
Copy link
Collaborator

cielf commented Mar 12, 2024

Looks good, functionality-wise, to me. @dorner - can you take a look from a technical p.o.v.?

@cielf cielf requested a review from dorner March 12, 2024 16:26
app/models/concerns/itemizable.rb Outdated Show resolved Hide resolved
app/models/kit.rb Outdated Show resolved Hide resolved
@aniketpatidar
Copy link
Contributor Author

I'll make those changes. Thanks!

@aniketpatidar
Copy link
Contributor Author

I've made the updates as per your suggestion.
@dorner

Copy link
Collaborator

@dorner dorner left a comment

Choose a reason for hiding this comment

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

Looks good, thanks! In the future, please don't force-push the branch (or do a sync with rebase) since it blows away the history of the review.

@aniketpatidar
Copy link
Contributor Author

Got it, noted for the future. Thanks for the heads-up! @dorner

@cielf
Copy link
Collaborator

cielf commented Mar 18, 2024

Looks good to me too. Note: I have added fixing the disappearing info on error to our long list of things to write up for people to fix.

@cielf cielf merged commit c9977f3 into rubyforgood:main Mar 18, 2024
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants