-
Notifications
You must be signed in to change notification settings - Fork 150
feat: maximumx order quantity for order article #1201
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
base: master
Are you sure you want to change the base?
Conversation
fb2f5d6
to
2f32e39
Compare
@yksflip Just to make sure before looking at it in depth - is this ready for review? (If not, please mark the PR as draft. 😉 ) I tried it out locally and got an unhandled error right away:
All I did to get there was create a new order including an article with a Also, I think there's (at least) some logic missing in |
thanks lentschi! I thought it would be ready, but there are few loops to take. I'll mark it a draft and ping you again once I'm ready :) |
2f32e39
to
b48c721
Compare
I fixed it by adding a null check.
Indeed! I've added it almost identitcal to max-quantity ..
I think that is not needed as I used the |
Ah, right, seems to work now 👍 But maybe we should also change the error message when entering an invalid value manually (exceeding max): I know, you could argue, that this has never been in there, but |
👍 |
a02df13
to
a00843d
Compare
a00843d
to
8f043e4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added backend and client side validations for this now.
The javascript client-side validation were quite complicated, good old friend ai helped a little bit out here. Not sure if it needs to be a custom validation like this. see app/assets/javascripts/validation-utils.js
maybe there is a better / more idiomatic way to do this?
I've added some code comments.
In addition, two general issues I'd like to throw in:
- Currently when two users open the group order form at the same time, then one adds a quantity that is below
maximum_order_quantity
and the second user tries the same but it's exceedingmaximum_order_quantity
when combined with the first user's quantity, the second user just gets a "The order couldn’t be updated due to a bug." So maybe add some custom error flash here if themaximum_order_quantity
is exceeded? (It would be better to have the form error inside the form, but I guess that's more difficult to implement.) - I haven't tried, but have you checked, if "using up" tolerance, can't be causing to somehow exceed
maximum_order_quantity
?
this.onSupplierUnitChanged(); | ||
|
||
// Add validation for minimum/maximum order quantity | ||
this.initializeOrderQuantityValidation(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you add client side validation to this form? I think, since other form fields are validated by the backend, this makes this kind of inconsistent. If I remove that line, it works just as fine - after clicking "Update article", I see the following error:

Of course frontend validation is always a nice-to-have in terms of usability, as the users can be made aware as soon as they blur the erroneous field. But I was hoping to only add this when finally building a PWA style client and not to further complicate the already ugly jquery code. What do you think?
* @param {jQuery} input$ - The input element | ||
* @param {Object} options - Validation options | ||
*/ | ||
static setupInputValidation(input$, options = {}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Method seems to be unused - AI slop?
/** | ||
* Hides all validation messages | ||
*/ | ||
static hideAllValidationMessages() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Method seems to be unused - AI slop?
|
||
validates :maximum_order_quantity, numericality: { allow_nil: true } | ||
# validates_uniqueness_of :name, :scope => [:supplier_id, :deleted_at, :type], if: Proc.new {|a| a.supplier.shared_sync_method.blank? or a.supplier.shared_sync_method == 'import' } | ||
# validates_uniqueness_of :name, :scope => [:supplier_id, :deleted_at, :type, :unit, :unit_quantity] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's odd that this is shown as part of a change although it's the same as in the current master - maybe due to a faulty rebase...?
- quantity_data['used_quantity'] = @ordering_data[:order_articles][order_article.id][:used_quantity] | ||
- quantity_data['price'] = @ordering_data[:order_articles][order_article.id][:price] | ||
- quantity_data['minimum_order_quantity'] = @ordering_data[:order_articles][order_article.id][:minimum_order_quantity] unless @ordering_data[:order_articles][order_article.id][:minimum_order_quantity].nil? | ||
- quantity_data['maximum_order_quantity'] = @ordering_data[:order_articles][order_article.id][:maximum_order_quantity] unless @ordering_data[:order_articles][order_article.id][:maximum_order_quantity].nil? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I'm not mistaken, @ordering_data[:order_articles][order_article.id][:maximum_order_quantity]
is never set, right? (At least the above fields are all set in GroupOrder.load_data, but maximum_order_quantity isn't.)
Anyhow - quantity_available
seems sufficient, right?
//= require_self | ||
//= require big | ||
//= require units-converter | ||
//= require validation-utils |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the AI added some unused methods for these validation-utils (I added review comments for where I seem to have found dead code) and also the solution it provided supersedes some old logic, which it also failed to remove (e.g. the %span.numeric-step-error
in the group order form template no longer seems to be required).
Instead of reviewing the AI code in depth (which seems cumbersome, as I think there's quite some AI slop), here's my quick go on this:
implements #1007