Skip to content

OBPIH-6042 Add filter by date range to expiration reports#4487

Merged
awalkowiak merged 6 commits intofeature/upgrade-to-grails-3.3.10from
OBPIH-6042
Feb 6, 2024
Merged

OBPIH-6042 Add filter by date range to expiration reports#4487
awalkowiak merged 6 commits intofeature/upgrade-to-grails-3.3.10from
OBPIH-6042

Conversation

@alannadolny
Copy link
Collaborator

No description provided.

@awalkowiak
Copy link
Collaborator

@alannadolny there are some conflicts here

List<InventoryItem> inventoryItems = dashboardService.getExpiredStock(command.category, command.location, command.startDate, command.endDate)
List<Category> categories = inventoryItems?.collect { it.product.category }?.unique()
Map<InventoryItem, Integer> quantityMap = productAvailabilityService.getQuantityOnHandByInventoryItem(command.location)
LinkedHashMap<InventoryItem, Integer> expiredStockMap = [:]
Copy link
Collaborator

Choose a reason for hiding this comment

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

LinkedHashMap is an implementation of Map interface.
We should use interfaces as types if possible, hence Map should be the type here.
The same case as with Lists - you shouldn't define the type as ArrayList<String> list = [...], but as List<String> list = [...]


if (endDate) {
expiredStock = expiredStock.findAll { item -> item?.expirationDate <= endDate }
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

this feels odd to me - this should be probably filtered out at the query level, but I can see that you've followed the convention, so I don't have an opinion if it should be handled now or if we should treat it as a tech debt.

* @return a list of inventory items
*/
List getExpiringStock(Category category, Location location, String expirationStatus) {
List getExpiringStock(Category category, Location location, String expirationStatus, Date startDate, Date endDate) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

just a comment - 4 arguments feels a lot to me, I think in the near future, we should rely on command classes more, since they give us more flexibility and better dev experience in my opinion.

if (endDate) {
expiringStock = expiringStock.findAll { item -> item?.expirationDate <= endDate }
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

same comment as above

}

if (command.endDate) {
expiringStock = expiringStock.findAll { item -> item?.expirationDate <= command.endDate }
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm approving this one, but this needs to be refactored asap, especially if the performance is bad there.

expiredStock = expiredStock.findAll { item -> item?.product?.category == command.category }
}

if (command.startDate) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this should not work like that. IMHO this should be properly used in the findAll or in criteria as a proper date range
findAllByExpirationDateGreaterOrEqualThanAndByExpirationDateLessOrEqualThan, but this (if works) is undreadable and should include category, so I think this needs to end up in the proper criteria including all filtering properties: category, startDate and endDate. And then these results can be filtered by quantity on hand.

def today = new Date()
today.clearTime()
// Get all stock expiring ever (we'll filter later)
def expiringStock = InventoryItem.findAllByExpirationDateGreaterThanEquals(today + 1, [sort: 'expirationDate', order: 'asc'])
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same comment as above

@awalkowiak awalkowiak merged commit e9dbedc into feature/upgrade-to-grails-3.3.10 Feb 6, 2024
@awalkowiak awalkowiak deleted the OBPIH-6042 branch February 6, 2024 15:07
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.

3 participants