details: https://code.openbravo.com/erp/devel/pi/rev/f6bccb4de4db changeset: 33850:f6bccb4de4db user: Armaignac <collazoandy4 <at> gmail.com> date: Mon Apr 09 17:16:08 2018 -0400 summary: Fixes issue 38280:Relation between product and services is not copied when cloning a sales order
Relation between product and services is not copied by Copy Record process of Sales Order window The Copy Record process now take into account the relation between product and services details: https://code.openbravo.com/erp/devel/pi/rev/0d6f2565e5fc changeset: 33851:0d6f2565e5fc user: David Miguelez <david.miguelez <at> openbravo.com> date: Tue Apr 17 15:59:58 2018 +0200 summary: Related to issue 38280. Code Review changes * Removed unnecessary save, flush, refresh * Changed variable name * Formatted code diffstat: modules/org.openbravo.client.application/src/org/openbravo/client/application/businesslogic/CloneOrderActionHandler.java | 40 +++++++++- 1 files changed, 38 insertions(+), 2 deletions(-) diffs (88 lines): diff -r c322c0c311ea -r 0d6f2565e5fc modules/org.openbravo.client.application/src/org/openbravo/client/application/businesslogic/CloneOrderActionHandler.java --- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/businesslogic/CloneOrderActionHandler.java Wed Apr 18 09:53:28 2018 +0200 +++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/businesslogic/CloneOrderActionHandler.java Tue Apr 17 15:59:58 2018 +0200 @@ -11,7 +11,7 @@ * under the License. * The Original Code is Openbravo ERP. * The Initial Developer of the Original Code is Openbravo SLU - * All portions are Copyright (C) 2011-2016 Openbravo SLU + * All portions are Copyright (C) 2011-2018 Openbravo SLU * All Rights Reserved. * Contributor(s): Mallikarjun M ************************************************************************ @@ -22,6 +22,7 @@ import java.util.ArrayList; import java.util.Calendar; import java.util.Date; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -38,6 +39,7 @@ import org.openbravo.model.ad.access.User; import org.openbravo.model.common.order.Order; import org.openbravo.model.common.order.OrderLine; +import org.openbravo.model.common.order.OrderlineServiceRelation; import org.openbravo.model.pricing.pricelist.PriceListVersion; import org.openbravo.service.db.CallStoredProcedure; import org.openbravo.service.json.DataResolvingMode; @@ -98,6 +100,8 @@ // save the cloned order object OBDal.getInstance().save(objCloneOrder); + Map<String, OrderLine> mapOriginalOrderLineWithCloneOrderLine = new HashMap<>(); + List<OrderlineServiceRelation> orderLinesServiceRelation = new ArrayList<>(); // get the lines associated with the order and clone them to the new // order line. for (OrderLine ordLine : objOrder.getOrderLineList()) { @@ -120,10 +124,24 @@ objCloneOrder.getOrderLineList().add(objCloneOrdLine); objCloneOrdLine.setSalesOrder(objCloneOrder); objCloneOrdLine.setReservationStatus(null); + + mapOriginalOrderLineWithCloneOrderLine.put(ordLine.getId(), objCloneOrdLine); + List<OrderlineServiceRelation> lineServiceRelation = cloneProductServiceRelation(ordLine, + objCloneOrdLine); + orderLinesServiceRelation.addAll(lineServiceRelation); } + for (OrderlineServiceRelation lineServiceRelation : orderLinesServiceRelation) { + OrderLine clonedOrderLine = mapOriginalOrderLineWithCloneOrderLine.get(lineServiceRelation + .getOrderlineRelated().getId()); + lineServiceRelation.setOrderlineRelated(clonedOrderLine); + OBDal.getInstance().save(lineServiceRelation); + } + + mapOriginalOrderLineWithCloneOrderLine.clear(); + orderLinesServiceRelation.clear(); + OBDal.getInstance().save(objCloneOrder); - OBDal.getInstance().flush(); OBDal.getInstance().refresh(objCloneOrder); json = jsonConverter.toJsonObject(objCloneOrder, DataResolvingMode.FULL); @@ -134,6 +152,24 @@ } } + private List<OrderlineServiceRelation> cloneProductServiceRelation(OrderLine ordLine, + OrderLine objCloneOrdLine) { + + List<OrderlineServiceRelation> cloneServiceRelation = new ArrayList<>(ordLine + .getOrderlineServiceRelationList().size()); + for (OrderlineServiceRelation orderLineServiceRelation : ordLine + .getOrderlineServiceRelationList()) { + OrderlineServiceRelation lineServiceRelation = (OrderlineServiceRelation) DalUtil.copy( + orderLineServiceRelation, false); + lineServiceRelation.setOrderlineRelated(orderLineServiceRelation.getOrderlineRelated()); + lineServiceRelation.setSalesOrderLine(objCloneOrdLine); + cloneServiceRelation.add(lineServiceRelation); + } + objCloneOrdLine.setOrderlineServiceRelationList(cloneServiceRelation); + + return cloneServiceRelation; + } + private String getPriceListVersion(String priceList, String clientId) { try { String whereClause = " as plv left outer join plv.priceList pl where plv.active='Y' and plv.active='Y' and " ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ Openbravo-commits mailing list Openbravo-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbravo-commits