OBPIH-5977 Display items in PO Template in the same order as entered during PO creation#4387
Conversation
There was a problem hiding this comment.
a question - what makes it sorted in the view? I expected you to change it in two places, but I see that you've changed it only for the template.
If it is sorted "by hand" in the view comparing the dates, this could be also shortened there to .sort() as you've overwritten the compareTo method.
|
|
||
| @Override | ||
| int compareTo(OrderAdjustment o) { | ||
| return dateCreated <=> o.dateCreated |
There was a problem hiding this comment.
Careful with this. This would disappear adjustments with the same dateCreated that are added to a TreeSet or TreeMap.
Note that the ordering maintained by a set (whether or not an explicit comparator is provided) must be consistent with equals if it is to correctly implement the Set interface. (See Comparable or Comparator for a precise definition of consistent with equals.) This is so because the Set interface is defined in terms of the equals operation, but a TreeSet instance performs all element comparisons using its compareTo (or compare) method, so two elements that are deemed equal by this method are, from the standpoint of the set, equal. The behavior of a set is well-defined even if its ordering is inconsistent with equals; it just fails to obey the general contract of the Set interface.
There was a problem hiding this comment.
I usually do something like this
@Override
int compareTo(OrderAdjustment obj) {
return dateCreated <=> obj?.dateCreated ?:
lastUpdated <=> obj?.lastUpdated ?:
id <=> party.id
}
| ] | ||
| } | ||
| def orderAdjustments = orderInstance?.orderAdjustments?.findAll { !it.canceled }?.collect { OrderAdjustment orderAdjustment -> | ||
| def orderAdjustments = orderInstance?.orderAdjustments?.findAll { !it.canceled }?.sort()?.collect { OrderAdjustment orderAdjustment -> |
There was a problem hiding this comment.
This feels like a case where the default sort order of the association would make sense.
Either in the domain class
class OrderAdjustment {
static mapping = {
sort dateCreated : "desc"
}
}
Or in the association on Order
class Order {
static mapping = {
orderAdjustments(sort:'dateCreated', order:'desc')
}
}
There was a problem hiding this comment.
I followed your solution with compareTo with fallbacks
| </thead> | ||
| <tbody> | ||
| <g:each var="orderAdjustment" in="${orderInstance.orderAdjustments?.sort { it.dateCreated }}" status="status"> | ||
| <g:each var="orderAdjustment" in="${orderInstance.orderAdjustments?.sort()}" status="status"> |
There was a problem hiding this comment.
Are there other places where we display order adjustments?
There was a problem hiding this comment.
I can see them on order/print
orderInstance?.orderAdjustments.findAll { !(it.orderItem || it.canceled) }.sort { it.totalAdjustments }.reverse()
There was a problem hiding this comment.
@alannadolny Ok cool. Can you include that in the ticket (@ Manon) with 1) a brief description of what is happening in that code 2) question on whether these need to be sorted as well?
jmiranda
left a comment
There was a problem hiding this comment.
LGTM. Please see comment below about what to add to the ticket for Manon's review.
No description provided.