Skip to content

OBPIH-7184 fix2. properly save 0 qty items in stock movements and dis…#5604

Merged
kchelstowski merged 6 commits intodevelopfrom
bug/OBPIH-7184-2
Nov 7, 2025
Merged

OBPIH-7184 fix2. properly save 0 qty items in stock movements and dis…#5604
kchelstowski merged 6 commits intodevelopfrom
bug/OBPIH-7184-2

Conversation

@ewaterman
Copy link
Member

…play warning on proceeding

✨ Description of Change

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

Description: Please see ticket for details.

Fixes include:

  1. On outbounds we can easily navigate back and forth between the edit and add items step. As such, if SM status != CREATED (meaning we've advanced to the next step), we should always remove zero items, even when saving without clicking next
  2. For all SM, if you add a new line with quantity 0, clicking save (or save and quit or previous) was not triggering a save items call
  3. Requests from wards no longer need custom logic. When use previous, save, save and exit buttons we don't need to display the warning but we do when clicking next

@ewaterman ewaterman self-assigned this Nov 5, 2025
@github-actions github-actions bot added type: bug Addresses unintended behaviours of the app domain: frontend Changes or discussions relating to the frontend UI labels Nov 5, 2025
@codecov
Copy link

codecov bot commented Nov 5, 2025

Codecov Report

❌ Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 8.52%. Comparing base (1bb7314) to head (60465fb).
⚠️ Report is 181 commits behind head on develop.

Files with missing lines Patch % Lines
...ovy/org/pih/warehouse/api/StockMovementItem.groovy 0.00% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             develop   #5604      +/-   ##
============================================
- Coverage       9.12%   8.52%   -0.60%     
+ Complexity      1170    1127      -43     
============================================
  Files            701     712      +11     
  Lines          45281   45618     +337     
  Branches       10851   10914      +63     
============================================
- Hits            4131    3890     -241     
- Misses         40497   41149     +652     
+ Partials         653     579      -74     

☔ 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
Member Author

@ewaterman ewaterman left a comment

Choose a reason for hiding this comment

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

Again I haven't had time to do as thorough as a test as I would have hoped but I tested a little on all three flows and things do appear to be working. I'd like to do some more testing on this tomorrow but if it's easier to merge and get QA to test it again then lets do it

getLineItemsToBeSaved(lineItems) {
const lineItemsToBeAdded = _.filter(lineItems, (item) =>
!item.statusCode && item.quantityRequested && item.quantityRequested !== '0' && item.product);
!item.statusCode && item.quantityRequested && item.product);
Copy link
Member Author

Choose a reason for hiding this comment

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

fix 2. We now want new items to be saved if they have a 0 quantity

const lineItemsToBeAdded = _.filter(lineItems, (item) =>
!item.statusCode
&& parseInt(item.quantityRequested, 10) > 0
&& parseInt(item.quantityRequested, 10) >= 0
Copy link
Member Author

Choose a reason for hiding this comment

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

fix 2. We now want new items to be saved if they have a 0 quantity

// First find items that are new and should be added (don't have status code)
const lineItemsToBeAdded = _.filter(lineItems, (item) =>
!item.statusCode && item.quantityRequested && item.quantityRequested !== '0' && item.product);
!item.statusCode && item.quantityRequested && item.product);
Copy link
Member Author

Choose a reason for hiding this comment

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

fix 2. We now want new items to be saved if they have a 0 quantity

this.transitionToNextStep(RequisitionStatus.REQUESTED);
}
});
}
Copy link
Member Author

Choose a reason for hiding this comment

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

this isn't removed, just merged up into the saveAndTransitionToNextStep method. After talking with Kacper, we realized that my above TODO was correct and that flow was unreacheable so this is just a cleanup of that by removing the unused logic.

} else {
this.saveItems(lineItems);
}
this.saveItems(lineItems);
Copy link
Member Author

Choose a reason for hiding this comment

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

fix 3 (and the two changes below are the same). We don't need this special case for wards. All requests should be able to save 0 quantity rows

itemCandidatesToSave,
removeEmptyItems,
withStateChange = true,
) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Adding in removeEmptyItems is fix 1. We now remove empty/zero rows when saving, saving and quitting, and clicking "previous" if we've already proceeded to the next step for the outbound (and so SM status is no longer CREATED)

async saveRequisitionItemsInCurrentStep(itemCandidatesToSave, withStateChange = true) {
async saveRequisitionItemsInCurrentStep(
itemCandidatesToSave,
removeEmptyItems,
Copy link
Collaborator

Choose a reason for hiding this comment

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

if you add a new argument, do it at the end. Currently this might break a few places where this method is used.
One of them is line 410th where the saveRequisitionItemsInCurrentStep is called like:

this.debouncedSave = _.debounce(() => {
      this.saveRequisitionItemsInCurrentStep(this.state.values.lineItems, false);
    }, 1000);

Now, instead of withStateChange being false, it will be removeEmptyItems that is false, and withStateChange will become true as its the default argument.

BTW. This is why I'm often against default arguments as it might cause unnecessary behaviors and I opt for having an object based argument so that you can't make a mistake, like:

async saveRequisitionItemsInCurrentStep({ itemCandidatesToSave, withStateChange, removeEmptyItems }) {...}

and then you have to explicitly pass:

this.saveRequisitionItemsInCurrentStep({
  removeEmptyItems: true,
  withStateChange: false,
  itemCandidatesToSave: [...]
})

see that I switched the order and it would still work.

@SebastianLib
Copy link
Collaborator

@ewaterman , you probably didn’t fix the last point that Kasia mentioned yesterday in her comment. I found this issue see:

2025-11-06.13-44-14.mp4

Please check the cases for ward and depot that Kasia mentioned and verify if I correctly changed the code to use an object for the method arguments in the saveRequisitionItemsInCurrentStep method.

@SebastianLib
Copy link
Collaborator

@ewaterman also noticed that in inbound/AddItemsPage.jsx you accidentally used the wrong URL instead of updateInventoryItems you used updateItems, so it saves incorrectly now.

655e4c1#diff-2c450d4da2b4f9fcfbcd2ebd3a282596a88f8906b868fe6c066789c00a8e11eeL672-R675

image

I’ll fix this in my latest PR since I need to fix it in my reopen anyway, but you might want to fix it locally too in case it causes any issues.

You can add this to file urls.js:

export const STOCK_MOVEMENT_UPDATE_INVENTORY_ITEMS = (id) => ${STOCK_MOVEMENT_BY_ID(id)}/updateInventoryItems;

@github-actions github-actions bot added the domain: backend Changes or discussions relating to the backend server label Nov 6, 2025
@kchelstowski kchelstowski merged commit 0e0ce04 into develop Nov 7, 2025
7 checks passed
@kchelstowski kchelstowski deleted the bug/OBPIH-7184-2 branch November 7, 2025 08:58
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 domain: frontend Changes or discussions relating to the frontend UI type: bug Addresses unintended behaviours of the app

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants