Skip to content

fix(OLMIS-8249): require positive adjustment quantities - #88

Merged
denys1204 merged 1 commit into
masterfrom
OLMIS-8249-implement-changes-from-OE-206-to-Core
Jul 17, 2026
Merged

fix(OLMIS-8249): require positive adjustment quantities#88
denys1204 merged 1 commit into
masterfrom
OLMIS-8249-implement-changes-from-OE-206-to-Core

Conversation

@denys1204

Copy link
Copy Markdown
Contributor

Summary

Adds validation to the adjustments modal so that a stock adjustment cannot be added or saved with a non-positive quantity. Previously an empty, zero, negative, or non-numeric quantity could be entered and saved, producing invalid adjustments.

Ported from OpenLMIS-Eswatini (OE-206) into core so the guard applies everywhere, not only in the Eswatini overlay.

Changes

  • Inject alertService into AdjustmentsModalController.
  • On Add (addAdjustment): reject the new reason if its quantity is not greater than 0 and show openlmisAdjustments.quantityGreaterThanZero.
  • On Update/Save (save): reject submission if any adjustment has an invalid quantity and show the same message.
  • Add helpers hasInvalidAdjustments() / hasValidQuantity() and expose vm.hasInvalidAdjustments.
  • A quantity is valid only if it is defined, non-empty, numeric, and > 0.
  • Add the openlmisAdjustments.quantityGreaterThanZero message key.

Testing

  • Added unit tests in adjustments-modal.controller.spec.js covering the guard on Add and Save for zero, empty and negative quantities, plus positive-path controls.
  • Full suite passes: 954/954 SUCCESS, no build errors.

Files changed

  • src/openlmis-adjustments/adjustments-modal.controller.js
  • src/openlmis-adjustments/adjustments-modal.controller.spec.js
  • src/openlmis-adjustments/messages_en.json

Notes

This PR intentionally contains only the adjustment-quantity validation. The other part of OE-206 (default-language fallback in messageService) was evaluated but deliberately left out of core: moving it here changes a relied-upon contract (get() returning the raw key when no locale is set) and breaks 22 tests across other UI repositories. Details in the ticket.

@mgrochalskisoldevelo mgrochalskisoldevelo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

One small change request. Please remove the four OE-206 comments - this is a community core repo; references to an Eswatini-internal ticket may confuse every future reader, and the rationale already lives in the PR body.

Once this is done, the ticket is good to be merged.

Reject stock adjustments whose quantity is not greater than zero, both when adding a new reason and when submitting the modal. Previously an empty, zero, or non-numeric quantity could be saved, producing invalid adjustments.

- inject alertService into the adjustments modal controller
- validate newAdjustment on Add; reject if quantity is not > 0
- validate all adjustments on Update; reject if any is invalid
- add hasInvalidAdjustments() / hasValidQuantity() helpers and expose vm.hasInvalidAdjustments
- add "openlmisAdjustments.quantityGreaterThanZero" message

Ported from OpenLMIS-Eswatini (OE-206) into core so the guard applies everywhere instead of only in the Eswatini overlay.
@denys1204
denys1204 force-pushed the OLMIS-8249-implement-changes-from-OE-206-to-Core branch from 76a5072 to f2c91d7 Compare July 17, 2026 14:50
@sonarqubecloud

Copy link
Copy Markdown

@denys1204
denys1204 merged commit 4dfb96f into master Jul 17, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants