From d11eded6a34c3ca2506bb5f6998c68eec59d4e41 Mon Sep 17 00:00:00 2001 From: Parvathy Babu <102500787+parvathy00@users.noreply.github.com> Date: Tue, 2 Apr 2024 22:51:53 +0530 Subject: [PATCH] Parvathy | BAH-3738 | Fix. Handle Incorrect Syncing Of Quantity For Same Drug Orders (#104) --- .../domain/encounter/OpenERPOrders.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/encounter/OpenERPOrders.java b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/encounter/OpenERPOrders.java index 3d2f1bf..c8af6e1 100644 --- a/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/encounter/OpenERPOrders.java +++ b/openerp-atomfeed-service/src/main/java/org/bahmni/feed/openerp/domain/encounter/OpenERPOrders.java @@ -18,13 +18,23 @@ public List 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 removeDuplicateOrders(List orders) { Map 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()); }