OBGM-554 Unable to save adjustments when add them to PO #4133
OBGM-554 Unable to save adjustments when add them to PO #4133awalkowiak merged 2 commits intofeature/upgrade-to-grails-3.3.10from
Conversation
| || order?.status == OrderStatus.PENDING)}"/> | ||
| <g:set | ||
| var="canManageAdjustments" | ||
| value="${(order?.status >= OrderStatus.PLACED && isApprover) || (order?.status == OrderStatus.PENDING)}" |
There was a problem hiding this comment.
I don't know the context, but it feels like this order?.status only works "by a fortune". It seems to be comparing statuses by alphabetic order, not by the sortOrder as it was probably meant to be.
Could you double check that?
In my opinion it works by a fortune, but in general it should be written using:
OrderStatus.compare(order?.status, OrderStatus.PLACED)Be aware, that by using the compare method, a NullPointerException might be thrown if order.status is null, because we don't have null safe operators there:
openboxes/src/groovy/org/pih/warehouse/order/OrderStatus.groovy
Lines 33 to 35 in 1e77b28
There was a problem hiding this comment.
Yes, it was compared by alphabetical order (>= placed was returning correct values -> placed, received, rejected). I changed it as you suggested to avoid future problems connected to the order of those statuses.
There was a problem hiding this comment.
It seems to be comparing statuses by alphabetic order, not by the sortOrder as it was probably meant to be.
I don't think this is true. Or at least it was not true in Grails 1.
The only reason it might be true is if within a GSP the order.status is somehow not being coerced into an OrderStatus enum and Grails thinks it's a String, forcing the OrderStatus.PLACED and OrderStatus.PENDING to be compared as Strings.
jmiranda
left a comment
There was a problem hiding this comment.
I'd like for someone to review this and confirm the "enums compared as strings" behavior. We have enum comparisons all over the place so it would be annoying to have to change this everywhere if it's not necessary.
|
In Java 7, the following is true regarding enum compareTo.
That means the order defined in the OrderStatus enum is the natural order. So this change was unnecessary since the order is correct here. Incidentally, this is also true for Java 8. There might be something fishy going on with how the <g:set> tag is evaluating the expression, but comparing enums using relational operators (>, >=, ==, <=, <) is not the problem. |
|
@jmiranda that's very interesting. Thanks for pointing that out. I checked it in a console and it seems to be true what you've written. I remember we had a problem in some Anyway to be always safe (e.g. accidentally we don't follow the |
No description provided.