How-to/How to Create Order Preparation Implementation
Contents |
Introduction
Order preparation module allows to prepare sales order lines in order to be delivered using the external WMS desired. To do this, a new module must be created and the order preparation flows implemented as explained in the following document.
Define implementation
Create a new list reference in Order Preparation Implementation reference.
Configure implementation
In organization select the implementation created.
Implementation
The module has two main flows:
- Preparing the order lines to be delivered
- Processing the pickings
Preparing the order lines to be delivered
To implement the process of "Preparing the order lines to be delivered" it is necessary to create a new java class that extends PreparedOrderHook
public class AWOPreparedOrderLoader extends PreparedOrderHook { private static final Logger log = LogManager.getLogger(); @Inject @Any private Instance<PreparedOrderLoaderHook> preparedOrderLoaderHook; @Override public JSONObject exec(JSONObject json) throws Exception { final JSONObject jsonResponse = new JSONObject(); JSONObject jsonData = new JSONObject(); OBContext.setAdminMode(true); try { JSONArray ordersFromJson = json.getJSONArray("orders"); List<String> pickingListDocumentNo = new ArrayList<>(); Map<String, BigDecimal> qtyPendingToPickByLines = new HashMap<>(); for (int i = 0; i < ordersFromJson.length(); i++) { JSONArray linesFromJson = ((JSONObject) ordersFromJson.get(i)).getJSONArray("lines"); List<SalesOrderLineToGeneratePicking> salesOrderLinesToGeneratePicking = new ArrayList<>(); String warehouseId = null; for (int j = 0; j < linesFromJson.length(); j++) { JSONObject jsonLine = linesFromJson.getJSONObject(j); if (jsonLine.optString("toPrepare") != "") { warehouseId = jsonLine.optString("warehouseId"); salesOrderLinesToGeneratePicking.add(new SalesOrderLineToGeneratePicking( ((JSONObject) ordersFromJson.get(i)).getString("id"), jsonLine.getString("id"), new BigDecimal(jsonLine.getString("toPrepare")))); qtyPendingToPickByLines.put(jsonLine.getString("id"), BigDecimal.ZERO); } } GroupOfSalesOrderLineToGeneratePicking groupOfLinesToGeneratePicking = new GroupOfSalesOrderLineToGeneratePicking( salesOrderLinesToGeneratePicking); groupOfLinesToGeneratePicking.setWarehouseId(warehouseId); CentralBrokerParameterMaps salesOrderLineParameter = new CentralBrokerParameterMaps( groupOfLinesToGeneratePicking); final OBAWO_BatchOfTasks batchOfTasks = CentralBroker.getNewInstance() .doTheStuff(Order.class, salesOrderLineParameter.getOrdersMap(), OBAWO_Constants.ACTION_PICKING, null, null, salesOrderLineParameter.getExtraParamsMap()); if (batchOfTasks != null) { getPickingListDocumentNo(batchOfTasks).ifPresent(pickingListDocumentNo::add); updateQytPendingToPickByLines(qtyPendingToPickByLines); } } executeHooks(preparedOrderLoaderHook, json); jsonResponse.put(JsonConstants.RESPONSE_STATUS, JsonConstants.RPCREQUEST_STATUS_SUCCESS); if (!pickingListDocumentNo.isEmpty()) { jsonData.put("pickingListDocumentNo", String.format("%s:%s", OBMessageUtils.messageBD("OBORPRE_CreatedDocNo"), pickingListDocumentNo.toString())); jsonData.put("qtyPendingToPickByLines", qtyPendingToPickByLines); } else { jsonData.put("pickingListDocumentNo", OBMessageUtils.messageBD("OBORPRE_NoDocumentCreated")); jsonData.put("qtyPendingToPickByLines", new HashMap<>()); } jsonData.put("showPickingListDocumentNo", true); jsonResponse.put(JsonConstants.RESPONSE_DATA, jsonData); } catch (Exception e) { try { jsonResponse.put(JsonConstants.RESPONSE_STATUS, JsonConstants.RPCREQUEST_STATUS_FAILURE); jsonResponse.put(JsonConstants.RESPONSE_ERROR, e.getMessage()); } catch (JSONException e1) { log.error(e1.getMessage()); } } finally { OBContext.restorePreviousMode(); } return jsonResponse; } @Override protected String getImplementation() { return "OBOPAWO_OPAWO"; } }
Processing the pickings
For the processing and status of the pickings we have two possibilities. Configure the "URL to show Picking Status Window with External Picking" preference and WMS system take care of displaying in an iframe, or implementing each of the picking states.
To implement each picking states, the corresponding hook must be extended. Such as the assign picking shown below.
public class AWOAssignPicking extends AssignPickingHook { @Override public JSONObject exec(JSONObject jsonData) throws Exception { final JSONObject result = new JSONObject(); OBContext.setAdminMode(true); try { final String pickingListId = jsonData.getString("pickingId"); final String loggedUserId = jsonData.getString("loggedUserId"); final JSONArray pickingTasks = PickingOperationsUtils .getUnconfirmedTaskIdsFromPickingList(pickingListId); OBAWOUserContactUtils.assignUserInSelectedTasks( OBDal.getInstance().get(User.class, loggedUserId), pickingTasks, true); result.put("status", JsonConstants.RPCREQUEST_STATUS_SUCCESS); } catch (JSONException e) { throw new OBException("Error while assigning picking", e); } finally { OBDal.getInstance().flush(); OBContext.restorePreviousMode(); } return result; } @Override protected String getImplementation() { return "OBOPAWO_OPAWO"; } }