feat: maximumx order quantity for order article#1201
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
lentschi
left a comment
There was a problem hiding this comment.
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_quantityand the second user tries the same but it's exceedingmaximum_order_quantitywhen 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_quantityis 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.
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.
Method seems to be unused - AI slop?
| /** | ||
| * Hides all validation messages | ||
| */ | ||
| static hideAllValidationMessages() { |
There was a problem hiding this comment.
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.
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.
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.
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:
There was a problem hiding this comment.
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:
<- @yksflip As there hasn't been any activity on this PR for a while, I have closed my PR on top of this. But I can reopen as soon as you or someone else wants pick up on it.
|
thanks for your comments and your approach to the client-validations! I should have better checked the generated stuff... I'll integrate your PR next and then tackle your comments :)
so this is the server side validation that doesn't return a nice error message right? I'll try to fix it.
I think this shouldn't happen as long as minimum < maximum, as you can't order more than the minimum with the tolerance field. But I'll give this a few more testcases just to be sure |
Yes, exactly. 👍
Okay, great - just checking :)
👍 |


implements #1007