Skip to content

OBPIH-6341 export template for pick import#4613

Merged
awalkowiak merged 11 commits intofeature/upgrade-to-grails-3.3.10from
OBPIH-6341-export-template-for-pick-import
May 15, 2024
Merged

OBPIH-6341 export template for pick import#4613
awalkowiak merged 11 commits intofeature/upgrade-to-grails-3.3.10from
OBPIH-6341-export-template-for-pick-import

Conversation

@drodzewicz
Copy link
Collaborator

Just as we have a structure for implementing ExcelImporters I created a similar one for ExcelExporters where we can provide a set of columns and their order and other properties like translated header labels.

I hope I didn't overengineer this approach and it will be a pattern that we can follow for future exporters

@@ -341,30 +342,32 @@ class StockMovementApiController {
}

def exportPickListItems() {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

both documents are nearly identical and I wasn't sure what would be the better route, create a separate endpoint for both or parametrize the one existing endpoint.
The difference is that lot, binLocation and expirationDate are empty on the template and quantity on the template is RequsitionItem.quantity.

I chose to add a boolean parameter template for the same endpoint but I am open to your criticism if this approach is not a correct one.

Copy link
Member

Choose a reason for hiding this comment

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

I was really confused by this. I figured the template would be a completely blank template, but I went back to the ticket and now I'm understanding it a bit more. I don't think we want to pass a boolean parameter for this. This should be something derived - each line knows whether it has picklist items associated with it or not.

@drodzewicz drodzewicz requested a review from jmiranda May 8, 2024 15:08
import org.pih.warehouse.core.Person
import org.pih.warehouse.core.RoleType
import org.pih.warehouse.core.User
import org.pih.warehouse.exporter.PickListItemExcelExporter
Copy link
Member

Choose a reason for hiding this comment

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

PickList -> Picklist

Copy link
Member

Choose a reason for hiding this comment

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

I get that this might be confusing and not seem all that important. But when we're talking about a single resource, we should make sure not to over-capitalize. This goes for other WMS-specific terms like putaway as well. In case it's not clear, it should be Putaway, not PutAway. We should be consistent across the application but I'm not sure how to make it more clear and intuitive. Any thoughts on how we can do that? Maybe a glossary?

@@ -341,30 +342,32 @@ class StockMovementApiController {
}

def exportPickListItems() {
Copy link
Member

Choose a reason for hiding this comment

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

I was really confused by this. I figured the template would be a completely blank template, but I went back to the ticket and now I'm understanding it a bit more. I don't think we want to pass a boolean parameter for this. This should be something derived - each line knows whether it has picklist items associated with it or not.

@@ -341,30 +342,32 @@ class StockMovementApiController {
}

def exportPickListItems() {
Copy link
Member

Choose a reason for hiding this comment

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

As I mentioned on the call, these methods don't really belong in the API, so let's move them to StockMovementController, or probably more appropriately, to PicklistController.

result.addAll(pickPageItem.picklistItems)
result
}
List<PicklistItem> picklistItems = pickPageItems.picklistItems?.flatten()
Copy link
Member

Choose a reason for hiding this comment

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

It seems reasonable, but are we sure this is equivalent?


response.contentType = "application/vnd.ms-excel"
response.setHeader("Content-disposition", "attachment; filename=\"StockMovementItems-${params.id}.xls\"")
PickListItemExcelExporter pickListItemExcelExporter = new PickListItemExcelExporter(lineItems)
Copy link
Member

Choose a reason for hiding this comment

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

As I mentioned on the call, let's not try to do anything new here. It was a good attempt, but I would like to make sure that new things are linked to a design and design review process, which will be handled as part of the discovery tickets and design sprints that Evan and I have mentioned in the past few weeks. If there's room to do a discovery and implementation in the same sprint, then great. But I suspect we're going to want to do these as separate activities across multiple sprints.

So for now, let's follow the current convention and add a generateExcel() method to dataService and we can work on OBIG-4 separately.

https://pihemr.atlassian.net/browse/OBIG-4

For this implementation, we should try to keep the previous code as-is (maybe move the main data retrieveal to a service) and just add in a way to switch on the rendering format.

This pseudocode - write this however you see fit (conditional, switch, etc) I just wanted to explain what I was thinking. I left out the code for the empty template case, so I'll let you figure out whether that should be included.

// Retrieve (and myabe validate) the stock movement for the given ID i.e. whether there is a stock movement with that id
def stockMovement = stockMovementService.getStockMovement(params.id)

// Keep the data building block from the previous version, but move to a service method.
def lineItems = picklistOrStockMovementService.getMeSomeData(stockMovement.picklist.id)

// FIXME We should eventually also handle content negotiation via file extension, request headers 
// and request parameters
if (!params.format || params.format == "csv") { 
    String csv = dataService.generateCsv(lineItems)
    response.setHeader("Content-disposition", "attachment; filename=\"StockMovementItems-${params.id}.csv\"")
    render(contentType: "text/csv", text: data.toString(), encoding: "UTF-8")
    return
} 
else if (params.format == "xls") {
    Workbook workbook = dataService.generateExcel(lineItems) 
    response.contentType = "application/vnd.ms-excel"
    response.setHeader("Content-disposition", "attachment; filename=\"StockMovementItems-${params.id}.xls\"")
    workbook.write(response.outputStream)
    response.outputStream.flush()
}
else { 
    throw new IllegalFormatException("Unable to determine the proper rendering format for request for format ${params.format}")
}

export const STOCK_MOVEMENT_UPDATE_ITEMS = id => `${STOCK_MOVEMENT_BY_ID(id)}/updateItems`;
export const STOCK_MOVEMENT_REMOVE_ALL_ITEMS = id => `${STOCK_MOVEMENT_BY_ID(id)}/removeAllItems`;
export const STOCK_MOVEMENT_STATUS = id => `${STOCK_MOVEMENT_BY_ID(id)}/status`;
export const PICK_LIST_ITEMS_EXPORT = id => `${STOCK_MOVEMENT_API}/exportPickListItems/${id}`;
Copy link
Member

Choose a reason for hiding this comment

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

PICKLIST should be one word.

@drodzewicz drodzewicz force-pushed the OBPIH-6341-export-template-for-pick-import branch from 9ada37f to 47b77eb Compare May 10, 2024 13:17
@drodzewicz drodzewicz added the warn: do not merge Marks a pull request that is not yet ready to be merged label May 13, 2024
- rename domain variabels from pickList to picklist
- separate template export and picklistitem export
@drodzewicz drodzewicz removed the warn: do not merge Marks a pull request that is not yet ready to be merged label May 14, 2024

String fileName = "PickListItems\$-${params.id}"

switch (format) {
Copy link
Collaborator

@awalkowiak awalkowiak May 15, 2024

Choose a reason for hiding this comment

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

This switch here and in the next action looks like could be moved to one method, or sth.

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 think we can repeat ourselves at the moment until we have a design pattern to deal with exporters and importers

switch (format) {
case "csv":
OutputStream outputStream = new ByteArrayOutputStream()
DataExporter pickListItemCsvExporter = new PicklistItemCsvExporter(lineItems)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looking into Justin's comments, I thought it was meant to be moved and designed in OBIG, and here we wanted to use methods from the dataService. Let me know if I missed some discussion around it.

@drodzewicz drodzewicz force-pushed the OBPIH-6341-export-template-for-pick-import branch from e18cd07 to a5d6021 Compare May 15, 2024 11:34
@drodzewicz
Copy link
Collaborator Author

As was suggested in the comments I reverted my implementation for exporters and used our old approach until we have a pattern that we agreed on on how to deal with excels and imports

@awalkowiak awalkowiak merged commit faac16f into feature/upgrade-to-grails-3.3.10 May 15, 2024
@awalkowiak awalkowiak deleted the OBPIH-6341-export-template-for-pick-import branch May 15, 2024 11:51
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.

3 participants