Skip to content

OBPIH-7096 force adjustment transactions to be after product inventory ones#5154

Merged
awalkowiak merged 1 commit intodevelopfrom
bug/OBPIH-7096-cycle-count-transaction-order
Mar 24, 2025
Merged

OBPIH-7096 force adjustment transactions to be after product inventory ones#5154
awalkowiak merged 1 commit intodevelopfrom
bug/OBPIH-7096-cycle-count-transaction-order

Conversation

@ewaterman
Copy link
Member

✨ 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):
image

After (adjustment is always after):
image

@ewaterman ewaterman self-assigned this Mar 20, 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 Mar 20, 2025
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)
Copy link
Member Author

Choose a reason for hiding this comment

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

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

codecov bot commented Mar 20, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 8.15%. Comparing base (87f0120) to head (4ce4894).
Report is 153 commits behind head on develop.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Collaborator

@awalkowiak awalkowiak left a comment

Choose a reason for hiding this comment

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

Wouldn't just using a new Date() in each create method work here as well (instead of using the one assigned at the beginning)?

@ewaterman
Copy link
Member Author

@awalkowiak I wanted to be more explicit about it. If we just do new Date() then if it all happens within the same millisecond, we have the same problem (they'll be the same date).

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.

@awalkowiak awalkowiak merged commit 4777662 into develop Mar 24, 2025
9 checks passed
@awalkowiak awalkowiak deleted the bug/OBPIH-7096-cycle-count-transaction-order branch March 24, 2025 13:53
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.

3 participants