OBPIH-7184 fix2. properly save 0 qty items in stock movements and dis…#5604
OBPIH-7184 fix2. properly save 0 qty items in stock movements and dis…#5604kchelstowski merged 6 commits intodevelopfrom
Conversation
…play warning on proceeding
Codecov Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
ewaterman
left a comment
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
fix 2. We now want new items to be saved if they have a 0 quantity
| this.transitionToNextStep(RequisitionStatus.REQUESTED); | ||
| } | ||
| }); | ||
| } |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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, | ||
| ) { |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
|
@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.mp4Please 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 |
|
@ewaterman also noticed that in 655e4c1#diff-2c450d4da2b4f9fcfbcd2ebd3a282596a88f8906b868fe6c066789c00a8e11eeL672-R675
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
|

…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: