OBPIH-6636 Trigger order summary refresh after editing existing item quantity#4824
Conversation
| 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)) { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
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.
28f95f5
into
feature/OBPIH-6398-partial-invoices-for-prepaid-po
✨ 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
Description of test plan (if applicable):
According to the reproduction steps
✅ Quality Checks
[OBS-123]for Jira,[#0000]for GitHub, or[OBS-123, OBPIH-123]if there are multiple), or with[N/A]if not applicable