Skip to content

Commit

Permalink
Parvathy | BAH-3738 | Fix. Handle Incorrect Syncing Of Quantity For S…
Browse files Browse the repository at this point in the history
…ame Drug Orders (#104)
  • Loading branch information
parvathy00 authored Apr 2, 2024
1 parent 71ed679 commit d11eded
Showing 1 changed file with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,23 @@ public List<OpenERPOrder> getOpenERPOrders() {
//Filters orders to keep only the latest action for each product. This is necessary for ensuring consistent and accurate quotation generation, particularly when order objects may not be in chronological order.
public List<OpenERPOrder> removeDuplicateOrders(List<OpenERPOrder> orders) {
Map<String, OpenERPOrder> latestOrders = new LinkedHashMap<>();

for (OpenERPOrder order : orders) {
latestOrders.merge(order.getProductId(), order, (existingOrder, newOrder) ->
(existingOrder.getDateCreated().before(newOrder.getDateCreated())) ? newOrder : existingOrder
);
if("Drug Order".equals(order.getType())) {
String productId = order.getProductId();
if (latestOrders.containsKey(productId)) {
OpenERPOrder existingOrder = latestOrders.get(productId);
double updatedQuantity = "NEW".equals(order.getAction()) ? existingOrder.getQuantity() + order.getQuantity() : existingOrder.getQuantity() - order.getQuantity();
existingOrder.setQuantity(updatedQuantity);
latestOrders.put(productId, existingOrder);
} else {
latestOrders.put(productId, order);
}
} else {
latestOrders.merge(order.getProductId(), order, (existingOrder, newOrder) ->
(existingOrder.getDateCreated().before(newOrder.getDateCreated())) ? newOrder : existingOrder
);
}
}

return new ArrayList<>(latestOrders.values());
}

Expand Down

0 comments on commit d11eded

Please sign in to comment.