Skip to content

Comments

(fix)O3-5249 : Quantity field validation is inconsistent between different billing items#100

Open
sourav-jyoti wants to merge 4 commits intoopenmrs:mainfrom
sourav-jyoti:fix/O3-5249
Open

(fix)O3-5249 : Quantity field validation is inconsistent between different billing items#100
sourav-jyoti wants to merge 4 commits intoopenmrs:mainfrom
sourav-jyoti:fix/O3-5249

Conversation

@sourav-jyoti
Copy link

@sourav-jyoti sourav-jyoti commented Feb 4, 2026

Issue

while entering a new item, the field doesn't enforces any limit of 1 - 100 .
while editing the item, the field doesn't allow quantity greater than 100 or less than 1,

This creates inconsistent behaviour in the billing workflow and can lead to incorrect quantity being submitted.
Also, there is no backend check , the check that is applied in the edit modal is only " frontend ".

image image

Fix:

applied a check in the BillResource.java in

@PropertySetter("lineItems") -> setBillLineItems

related issue:

issue

@sourav-jyoti
Copy link
Author

@dkayiwa could you pls review this pr

@dkayiwa
Copy link
Member

dkayiwa commented Feb 4, 2026

Can i have a link to the JIRA ticket?

@sourav-jyoti
Copy link
Author

Can i have a link to the JIRA ticket?

https://openmrs.atlassian.net/browse/O3-5249

@dkayiwa
Copy link
Member

dkayiwa commented Feb 4, 2026

How about the link in the pull request description?

}
for (BillLineItem item : lineItems) {
if (item.getQuantity() <= 1 || item.getQuantity() > 100) {
throw new IllegalArgumentException("Quantity can't be less than 1 or exceed 100");
Copy link
Member

Choose a reason for hiding this comment

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

Can i take a look at where the requirements of 1 to 100 came from?

Copy link
Author

Choose a reason for hiding this comment

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

https://github.com/openmrs/openmrs-esm-billing-app/blob/6f16ddc63abf9c2259e9aa9b52bc205bc7dd27f2/src/bill-item-actions/edit-bill-item.modal.tsx#L39

the frontend contains a zod validation

    () =>
      z.object({
        // NOTE: Frontend-only validation - quantities <1 or >100 can still be submitted via API.
        // Backend (BillServiceImpl.java:100) has empty validate() method.
        // TODO: Add server-side validation to enforce data integrity
        quantity: z.coerce
          .number({
            required_error: t('quantityRequired', 'Quantity is required'),
            invalid_type_error: t('quantityMustBeNumber', 'Quantity must be a valid number'),
          })
          .int(t('quantityMustBeInteger', 'Quantity must be a whole number'))
          .min(1, t('quantityMustBeAtLeastOne', 'Quantity must be at least 1'))
          .max(100, t('quantityCannotExceed100', 'Quantity cannot exceed 100')),
        price: z.coerce
          .number({
            required_error: t('priceIsRequired', 'Price is required'),
            invalid_type_error: t('priceMustBeNumber', 'Price must be a valid number'),
          })
          .positive(t('priceMustBePositive', 'Price must be greater than 0')),
      }),
    [t],
  );

@sourav-jyoti
Copy link
Author

How about the link in the pull request description?

i updated the link, previously i pasted the link with a custom zira filter of mine by mistake

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