Skip to content

OBPIH-5977 Display items in PO Template in the same order as entered during PO creation#4387

Merged
awalkowiak merged 3 commits intofeature/upgrade-to-grails-3.3.10from
OBPIH-5977
Nov 24, 2023
Merged

OBPIH-5977 Display items in PO Template in the same order as entered during PO creation#4387
awalkowiak merged 3 commits intofeature/upgrade-to-grails-3.3.10from
OBPIH-5977

Conversation

@alannadolny
Copy link
Collaborator

No description provided.

Copy link
Collaborator

@kchelstowski kchelstowski left a comment

Choose a reason for hiding this comment

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

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
Copy link
Member

Choose a reason for hiding this comment

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

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.

https://docs.oracle.com/javase/8/docs/api/java/util/TreeSet.html

Copy link
Member

Choose a reason for hiding this comment

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

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 ->
Copy link
Member

Choose a reason for hiding this comment

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

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')
    }
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

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">
Copy link
Member

Choose a reason for hiding this comment

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

Are there other places where we display order adjustments?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I can see them on order/print

orderInstance?.orderAdjustments.findAll { !(it.orderItem || it.canceled) }.sort { it.totalAdjustments }.reverse()

Copy link
Member

Choose a reason for hiding this comment

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

@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?

@alannadolny alannadolny requested a review from jmiranda November 22, 2023 09:20
Copy link
Member

@jmiranda jmiranda left a comment

Choose a reason for hiding this comment

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

LGTM. Please see comment below about what to add to the ticket for Manon's review.

@awalkowiak awalkowiak merged commit 97a55ed into feature/upgrade-to-grails-3.3.10 Nov 24, 2023
@awalkowiak awalkowiak deleted the OBPIH-5977 branch November 24, 2023 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants