Skip to content

OBPIH-7184 fix1. only remove 0 quantity lines on SMs when proceeding#5601

Merged
alannadolny merged 2 commits intodevelopfrom
bug/OBPIH-7184-1
Nov 5, 2025
Merged

OBPIH-7184 fix1. only remove 0 quantity lines on SMs when proceeding#5601
alannadolny merged 2 commits intodevelopfrom
bug/OBPIH-7184-1

Conversation

@ewaterman
Copy link
Member

✨ Description of Change

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

Description: Original PR: #5570

When you click the "next" or "submit request" buttons on the add items step of request/inbound/outbound two things happen:

  • we call /stockMovements/${id}/updateItems to save the items. This is just a generic save items endpoint so there's no way to know the context in which we're saving (ex: we don't know when we're saving a draft via the "save" / "save and exit" button vs saving before proceeding to the next step via "next" button).
  • we call /stockMovements/${id}/updateStatus to change the status. This is also a generic status change endpoint and has a bunch of "if status is changing to X, do Y" logic.

I like that the save is generic (and don't especially like that the status change isn't), however the "delete requisition item if quantity == 0" logic was existing there (before I removed it in my last PR), so in this PR I needed to either:

  1. move that logic to the update status step
  2. modify the update items logic to only delete zero items when we're told to (via a boolean API param)

I initially tried to implement 1 because that felt more proper to me. The frontend should just say "I want to go to state X" and the backend should be able to handle that (which would involve removing empty items). This would save us from needing to depend on the frontend to decide when a row is removed or not, which can get us into bad states if we're not careful. However it got too complex for me since the update logic itself is really complex and it seemed like we already rely quite heavily on the frontend knowing when to update items. A refactor of that was looking to be quite unfun.

So I went for solution 2, which felt easier...

@ewaterman ewaterman self-assigned this Nov 4, 2025
@ewaterman ewaterman added the warn: do not merge Marks a pull request that is not yet ready to be merged label Nov 4, 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 domain: backend Changes or discussions relating to the backend server labels Nov 4, 2025
// TODO: This is pre-existing code but why are we using 'VERIFYING' here for non-suppliers?
// It's not a valid StockMovementStatusCode value. Should this be 'VALIDATED'??
const status = (formValues.origin.type === 'SUPPLIER' || !formValues.hasManageInventory)
? 'CHECKING' : 'VERIFYING';
Copy link
Member Author

Choose a reason for hiding this comment

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

?? I don't get how this is working when we set status to 'VERIFYING'

Copy link
Collaborator

Choose a reason for hiding this comment

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

@ewaterman I briefly checked that and you are right this shouldn't work. But from what I can see this code is never executed. Probably after adding approval workflow, we now rely on the submitRequest method that executes saveRequisitionItems and transitionToNextStep, while the saveAndTransitionToNextStep is not used now.

requisitionItem.lotNumber = stockMovementItem.lotNumber
requisitionItem.expirationDate = stockMovementItem.expirationDate
requisitionItem.comment = stockMovementItem.comments
}
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 whole code change is just adding back in what I removed in https://github.com/openboxes/openboxes/pull/5570/files.

The only difference is the removeEmptyItems boolean

@codecov
Copy link

codecov bot commented Nov 4, 2025

Codecov Report

❌ Patch coverage is 0% with 23 lines in your changes missing coverage. Please review.
✅ Project coverage is 8.49%. Comparing base (1bb7314) to head (07aa453).
⚠️ Report is 178 commits behind head on develop.

Files with missing lines Patch % Lines
...ih/warehouse/inventory/StockMovementService.groovy 0.00% 20 Missing ⚠️
...ih/warehouse/api/StockMovementApiController.groovy 0.00% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             develop   #5601      +/-   ##
============================================
- Coverage       9.12%   8.49%   -0.63%     
+ Complexity      1170    1116      -54     
============================================
  Files            701     711      +10     
  Lines          45281   45591     +310     
  Branches       10851   10909      +58     
============================================
- Hits            4131    3875     -256     
- Misses         40497   41142     +645     
+ Partials         653     574      -79     

☔ 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

@kchelstowski kchelstowski left a comment

Choose a reason for hiding this comment

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

From the code perspective it looks good to me.

// TODO: This is pre-existing code but why are we using 'VERIFYING' here for non-suppliers?
// It's not a valid StockMovementStatusCode value. Should this be 'VALIDATED'??
const status = (formValues.origin.type === 'SUPPLIER' || !formValues.hasManageInventory)
? 'CHECKING' : 'VERIFYING';
Copy link
Collaborator

Choose a reason for hiding this comment

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

@ewaterman I briefly checked that and you are right this shouldn't work. But from what I can see this code is never executed. Probably after adding approval workflow, we now rely on the submitRequest method that executes saveRequisitionItems and transitionToNextStep, while the saveAndTransitionToNextStep is not used now.

@alannadolny alannadolny merged commit 655e4c1 into develop Nov 5, 2025
7 checks passed
@alannadolny alannadolny deleted the bug/OBPIH-7184-1 branch November 5, 2025 09:54
@sentry
Copy link

sentry bot commented Nov 7, 2025

Issues attributed to commits in this pull request

This pull request was merged and Sentry observed the following issues:

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 warn: do not merge Marks a pull request that is not yet ready to be merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants