Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OBPIH-6215 Refactor returns statuses (both inbound and outbound) and … #4586

Closed
wants to merge 1 commit into from

Conversation

kchelstowski
Copy link
Collaborator

…align them on list page<->view page

Copy link
Collaborator

@awalkowiak awalkowiak left a comment

Choose a reason for hiding this comment

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

I am not sure if this is change request or comment

@@ -63,6 +63,7 @@ class StockMovement implements Validateable{

StockMovementDirection stockMovementDirection
StockMovementStatusCode stockMovementStatusCode
StockMovementType stockMovementType
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why this was added here if it is not populated (keep in mind this StockMovement is not backed by the stock-movement view)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It has been added in case we returned the StockMovement to the show.gsp, not the OutboundStockMovement.
Since this property was missing in the StockMovement, I would get an exception when trying to evaluate this part of the code:

 <g:if test="${stockMovement?.stockMovementType == StockMovementType.RETURN_ORDER && isInbound}">

because either StockMovement or OutboundStockMovement might hide under the stockMovement.

I know it is not populated and it would return null for any case, we don't set it explicitly, but in this case we would want it to just evaluate to false, instead of throwing the exception about the missing method.

@@ -130,7 +130,14 @@
<g:message code="stockMovement.status.label"/>
</td>
<td class="value">
<format:metadata obj="${stockMovement?.status ?: (stockMovement?.shipment?.status?.code ?: stockMovement?.statusCode)}"/>
<g:set var="isInbound" value="${stockMovement?.destination == currentLocation}" />
%{-- If it's an inbound return, we want to display a shipment status--}%
Copy link
Collaborator

Choose a reason for hiding this comment

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

I feel like this should not be here because we wanted to move away from this type of logic in templates. Hopefully, this won't have to be drastically changed, after getting the results of the spike that @drodzewicz is working on.

Copy link
Collaborator Author

@kchelstowski kchelstowski Apr 17, 2024

Choose a reason for hiding this comment

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

I couldn't find an easier way to do it, as we have a generic view for both outbound and inbound returns and we have one single method (def show) for every SM we have in the system (regular inbound/outbound, PO shipments, returns, requests), so either I'd have to make mess there, or add this simple if statement here.
We'll see what @drodzewicz comes up with, but I suppose deeper refactors could be done when we refactor the SM API 🤔

@@ -130,7 +130,14 @@
<g:message code="stockMovement.status.label"/>
</td>
<td class="value">
<format:metadata obj="${stockMovement?.status ?: (stockMovement?.shipment?.status?.code ?: stockMovement?.statusCode)}"/>
<g:set var="isInbound" value="${stockMovement?.destination == currentLocation}" />
Copy link
Collaborator

Choose a reason for hiding this comment

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

You could (should) use a stockMovementDirection here (but first look at the comment from the line below)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I could for the StockMovement, but could not for the OutboundStockMovement, as this property/method is missing there.

@@ -51,29 +51,29 @@ CREATE OR REPLACE VIEW stock_movement_list_item AS
s.id AS shipment_id,
s.current_status AS shipment_status,
CASE
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if we should not move away from this part and move it to the StockMovement/OutboundStockMovement/StockMovementListItem classes, but I think this is part of @drodzewicz spike

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For now I just went with what was requested in the ticket, so to map the order statuses to different statuses than to what they were mapped until now.

WHEN o.status = 'COMPLETED' THEN 'DISPATCHED'
WHEN o.status = 'PARTIALLY_RECEIVED' THEN 'ISSUED'
WHEN o.status = 'RECEIVED' THEN 'ISSUED'
WHEN o.status = 'COMPLETED' THEN 'ISSUED'
WHEN o.status = 'REJECTED' THEN 'CANCELED'
ELSE 'PENDING'
END AS status_code,
NULL AS requisition_id,
CASE
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same comment as above

Copy link
Member

Choose a reason for hiding this comment

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

Holy shit. This makes me very nervous and is the antithesis of what I wanted to do with these tickets. This is "possible long-term" refactor, not "just get it working" refactor.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As for this change I’m pretty confident, since this part of the code is responsible only for returns.

@@ -77,27 +77,27 @@ CREATE OR REPLACE VIEW stock_movement AS
s.current_status AS shipment_status,
rn.identifier AS tracking_number,
CASE
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same comment as above

WHEN o.status = 'COMPLETED' THEN 'DISPATCHED'
WHEN o.status = 'PARTIALLY_RECEIVED' THEN 'ISSUED'
WHEN o.status = 'RECEIVED' THEN 'ISSUED'
WHEN o.status = 'COMPLETED' THEN 'ISSUED'
WHEN o.status = 'REJECTED' THEN 'CANCELED'
ELSE 'PENDING'
END AS status_code,
NULL AS requisition_id,
CASE
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same comment as above

Copy link
Member

@jmiranda jmiranda left a comment

Choose a reason for hiding this comment

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

Aside: The Tech Hurdle: State Machine document that I'm drafting is going to propose a change that will allow us to (hopefully) represent all of the state machines in the system using a library like Spring Statemachine https://docs.spring.io/spring-statemachine/docs/4.0.0/reference/index.html#crashcourse. We might keep the enums, but this will allow us to define all of the states and transitions of each state machine. That means we'll be calling the state machine API to check whether we can transition to the next state rather than implementing that using a switch statement.

WHEN o.status = 'COMPLETED' THEN 'DISPATCHED'
WHEN o.status = 'PARTIALLY_RECEIVED' THEN 'ISSUED'
WHEN o.status = 'RECEIVED' THEN 'ISSUED'
WHEN o.status = 'COMPLETED' THEN 'ISSUED'
WHEN o.status = 'REJECTED' THEN 'CANCELED'
ELSE 'PENDING'
END AS status_code,
NULL AS requisition_id,
CASE
Copy link
Member

Choose a reason for hiding this comment

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

Holy shit. This makes me very nervous and is the antithesis of what I wanted to do with these tickets. This is "possible long-term" refactor, not "just get it working" refactor.

@@ -29,8 +29,9 @@ enum StockMovementStatusCode {
PACKED(7, PENDING),
REVIEWING(8, PENDING),
DISPATCHED(9),
ISSUED(9),
Copy link
Member

Choose a reason for hiding this comment

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

I don't really understand why we're replacing DISPATCHED, but if you're going to replace DISPATCHED with ISSUED then you need to go 💯. DISPATCHED was the name of the status I gave for the stock movement state machine to differentiate it from the requisition. A requisition is ISSUED. In the case of an outbound shipment when the requisition is ISSUED it's also DISPATCHED as part of a shipment. We could have also used SHIPPED but I wanted to be generic in case we were dispatching to a ward or pharmacy within the hospital, in which case there isn't a need for shipment metadata.

Copy link
Member

Choose a reason for hiding this comment

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

What is the reasoning behind adding an ISSUED enum here? Would this be rectified by changing the localized message rendered for DISPATCHED state? If not, can you elaborate on what we're trying to accomplish.

Reminder: We want to change as little as possible.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It was a request in the ticket, that they want a different mapping for particular order statuses. Manon has provided me a table with exact statuses we want to display for a particular order status. If you read the comments in the ticket and also the description, everything should be self-explanatory.
Why I added the ISSUED to the enum is because of the fact, that I was getting an exception on the list page when trying to sort, and where eventually one of the 10 items has the ISSUED status. The exception was „No enum value [ISSUED] for StockMovementStatusCode”

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.

None yet

3 participants