Skip to content

OBPIH-6636 Trigger order summary refresh after editing existing item quantity#4824

Merged
kchelstowski merged 1 commit intofeature/OBPIH-6398-partial-invoices-for-prepaid-pofrom
OBPIH-6636
Sep 3, 2024
Merged

OBPIH-6636 Trigger order summary refresh after editing existing item quantity#4824
kchelstowski merged 1 commit intofeature/OBPIH-6398-partial-invoices-for-prepaid-pofrom
OBPIH-6636

Conversation

@awalkowiak
Copy link
Collaborator

✨ Description of Change

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

Description:
The order summary materialized view was not refreshing when the order items quantity was edited.


📈 Test Plan

  • Frontend automation tests (unit)
  • Backend automation tests (unit, API, smoke)
  • End-to-end tests (Playwright)
  • Manual tests (please describe below)
  • Not Applicable

Description of test plan (if applicable):
According to the reproduction steps


✅ Quality Checks

  • The pull request title is prefixed with the issue/ticket number (Ex: [OBS-123] for Jira, [#0000] for GitHub, or [OBS-123, OBPIH-123] if there are multiple), or with [N/A] if not applicable
  • The pull request description has enough information for someone without context to be able to understand the change and why it is needed
  • The change has tests that prove the issue is fixed / the feature works as intended

@github-actions github-actions bot added the domain: backend Changes or discussions relating to the backend server label Sep 3, 2024
if (!orderService.isOrderEditable(orderItem.order, session.user)) {
throw new UnsupportedOperationException("${warehouse.message(code: 'errors.noPermissions.label')}")
}
if (params.quantity && orderItem.quantity != (params.quantity as Integer)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe use params.int('quantity')?

}
if (params.quantity && orderItem.quantity != (params.quantity as Integer)) {
// if existing item's quantity is edited we have to trigger the order summary refresh
orderItem.disableRefresh = false
Copy link
Member

Choose a reason for hiding this comment

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

can you explain why this is needed? Instinctively, I'd assume that if the orderItem's quantity is updated, the view would know that it'd need to be refreshed because a field is changing. Why does quantity need a special check here? If other params (ie not quantity) are updated, does the view get refreshed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the view would know that it'd need to be refreshed because a field is changing.

That's correct for the view, but we have a materialized view for storing order summary (effectively a table in db).
Refreshing order summary for order items changes is disabled by default. It's refreshed only when a new item is added to the order. Item's quantity edit here did not trigger refresh on the order itself. In a result, the view has/calculates proper values, but the materialized view has old data, hence need to trigger this one at this level.

Why does quantity need a special check here? If other params (ie not quantity) are updated, does the view get refreshed?

Only quantity matters for the order summary. Hence no need to trigger it after editing other properties

if (!orderService.isOrderEditable(orderItem.order, session.user)) {
throw new UnsupportedOperationException("${warehouse.message(code: 'errors.noPermissions.label')}")
}
if (params.quantity && orderItem.quantity != (params.quantity as Integer)) {
Copy link
Collaborator

@kchelstowski kchelstowski Sep 3, 2024

Choose a reason for hiding this comment

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

titbit: you could use orderItem.isDirty('quantity'), but then, this if block should be placed below the binding. I'm fine with the current solution though.

@kchelstowski kchelstowski merged commit 28f95f5 into feature/OBPIH-6398-partial-invoices-for-prepaid-po Sep 3, 2024
@kchelstowski kchelstowski deleted the OBPIH-6636 branch September 3, 2024 20:30
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants