OBPIH-7096 force adjustment transactions to be after product inventory ones#5154
Conversation
| Instant now = Instant.now() | ||
| // -1 (instead of +1 to the adjustment transaction date) because transaction date can't be in the future. | ||
| Date productInventoryTransactionDate = DateUtil.asDate(now.minusSeconds(1)) | ||
| Date adjustmentTransactionDate = DateUtil.asDate(now) |
There was a problem hiding this comment.
FYI I'm pretty sure this all comes down to the following method call in InventoryService when compuing product availability:
List getTransactionEntriesByInventoryAndProduct(Inventory inventory, List<Product> products) {
def criteria = TransactionEntry.createCriteria()
def transactionEntries = criteria.list {
transaction {
eq("inventory", inventory)
order("transactionDate", "asc")
order("dateCreated", "asc")
}
if (products) {
inventoryItem { inList("product", products) }
}
}
return transactionEntries
}
so transactionDate is used to determine the order. It seems the order is unpredictable when there are two transactions with the same transactionDate and dateCreated. Sometimes it's correct, and other times the adjustment comes first. This change (hopefully) makes the adjustment always come second
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #5154 +/- ##
============================================
+ Coverage 8.11% 8.15% +0.04%
- Complexity 937 946 +9
============================================
Files 637 637
Lines 43137 43139 +2
Branches 10488 10488
============================================
+ Hits 3500 3519 +19
+ Misses 39100 39080 -20
- Partials 537 540 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
awalkowiak
left a comment
There was a problem hiding this comment.
Wouldn't just using a new Date() in each create method work here as well (instead of using the one assigned at the beginning)?
|
@awalkowiak I wanted to be more explicit about it. If we just do But more importantly, we use DATETIME as the field type for transaction_date, which only has precision up to seconds, so we have to explicitly set them one second apart for them to actually be different. |
✨ Description of Change
Link to GitHub issue or Jira ticket: https://pihemr.atlassian.net/browse/OBPIH-7096
Description: Force any adjustment transactions to always come after the product inventory transaction by setting the transaction date for the product inventory to be before the adjustment transaction date.
📷 Screenshots & Recordings (optional)
Before the change (adjustment comes first sometimes):

After (adjustment is always after):
