# HG changeset patch
# User Antonio Moreno <antonio.moreno@openbravo.com>
# Date 1538651068 -7200
#      Thu Oct 04 13:04:28 2018 +0200
# Node ID cf9e4cd6a823e3ca081c0ab28232d736a295372b
# Parent  81bf973b98d47841a02daf0ba7cde3934281a1ca
Fixed issue 39401: PaymentMethodCategories will no longer be duplicated.
Before, the payment method category referenced by a payment method was always cloned. This is not correct, the payment method category should be handled like the rest of the referenced objects in the retail configuration, so that if they are still visible in the new organization (or by the new terminal in case of copy terminal process), then the new object should reference the original payment method category, but if the payment method category is not visible, then it should be cloned but only once, and then the rest should reference the cloned object. This functionality is already implemented in the getObjectInTree method, so we can just use that one to achieve it.

diff -r 81bf973b98d4 -r cf9e4cd6a823 src/org/openbravo/retail/copystore/process/CopyStoreProcess.java
--- a/src/org/openbravo/retail/copystore/process/CopyStoreProcess.java	Mon Aug 27 00:11:21 2018 -0400
+++ b/src/org/openbravo/retail/copystore/process/CopyStoreProcess.java	Thu Oct 04 13:04:28 2018 +0200
@@ -1465,7 +1465,8 @@
       // Clone payment method category
       PayMethodCategory pymtCat = pymt.getPaymentMethodCategory();
       if (pymtCat != null) {
-        newPymt.setPaymentMethodCategory(copyPayMethodCategory(pymtCat, newPymt.getOrganization()));
+        MutableBoolean isNew = new MutableBoolean();
+        newPymt.setPaymentMethodCategory((PayMethodCategory) getObjectInTree(pymtCat, isNew));
       }
       OBDal.getInstance().save(newPymt);
       newObjects.put(TerminalTypePaymentMethod.ENTITY_NAME + "-" + pymt.getId(), newPymt);
@@ -1491,21 +1492,6 @@
   }
 
   /**
-   * Copies payment method category
-   * 
-   * @param originalPayMethodCategory
-   * @param newPaymentOrganization
-   */
-  public PayMethodCategory copyPayMethodCategory(PayMethodCategory originalPayMethodCategory,
-      Organization newPaymentOrganization) {
-    PayMethodCategory newPayMethodCategory = OBProvider.getInstance().get(PayMethodCategory.class);
-    cloneObject(originalPayMethodCategory, newPayMethodCategory, false);
-    newPayMethodCategory.setOrganization(newPaymentOrganization);
-    OBDal.getInstance().save(newPayMethodCategory);
-    return newPayMethodCategory;
-  }
-
-  /**
    * Adds log if there is any error
    * 
    * @param messageCode
