Skip to content

OBPIH-7512 replace string key with AvailableItemKey when working with product av…#5504

Merged
ewaterman merged 4 commits intodevelopfrom
bug/OBPIH-7512-null-lot-migration
Sep 26, 2025
Merged

OBPIH-7512 replace string key with AvailableItemKey when working with product av…#5504
ewaterman merged 4 commits intodevelopfrom
bug/OBPIH-7512-null-lot-migration

Conversation

@ewaterman
Copy link
Member

@ewaterman ewaterman commented Sep 22, 2025

…ailability

✨ Description of Change

Link to GitHub issue or Jira ticket: https://pihemr.atlassian.net/browse/OBPIH-7512

Description:

When calculating QoH, we construct a map of available items that is keyed on a string value that is constructed from product code, bin location name, and lot number:

static String constructAvailableItemKey(Location binLocation, InventoryItem inventoryItem) {
    return "${inventoryItem.product.productCode}-${binLocation?.name}-${inventoryItem?.lotNumber}"
}

https://github.com/openboxes/openboxes/blob/release/0.9.5-hotfix2/grails-app/services/org/pih/warehouse/inventory/ProductAvailabilityService.groovy

This is problematic however because it results in both the null lot and a lot with string "null" resolving to the same key:

String lotNumber = 'null'
println "${lotNumber}"          -> "null"
println "${lotNumber}" == null  -> false

lotNumber = null
println "${lotNumber}"          -> "null"
println "${lotNumber}" == null  -> false

I changed this logic to use an actual object as the key: AvailableItemKey. AvailableItemKey still uses bin location name and lot, but it keeps them as separate String fields, which should resolve the issue of null vs 'null'. Using a proper key class also means we don't need to pass around magic strings and unlabelled keys. I also introduced the AvailableItemMap as a convenience wrapper on the map so that it'd be easier to work with.

@ewaterman ewaterman self-assigned this Sep 22, 2025
@ewaterman ewaterman added the warn: do not merge Marks a pull request that is not yet ready to be merged label Sep 22, 2025
@github-actions github-actions bot added type: bug Addresses unintended behaviours of the app domain: backend Changes or discussions relating to the backend server labels Sep 22, 2025

Date previousTransactionDate = null
transactions.each { Transaction it ->
for (Transaction it in transactions) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Debugging was really difficult when this was in an "each" closure because intellij debug fields get all messed up. More importantly, stack traces get really garbled inside closures so I generally prefer to use regular loops unless it's a really simple operation

@ewaterman ewaterman removed the warn: do not merge Marks a pull request that is not yet ready to be merged label Sep 25, 2025
@ewaterman ewaterman merged commit 825f3e9 into develop Sep 26, 2025
2 of 5 checks passed
@ewaterman ewaterman deleted the bug/OBPIH-7512-null-lot-migration branch September 26, 2025 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

domain: backend Changes or discussions relating to the backend server type: bug Addresses unintended behaviours of the app

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants