details: https://code.openbravo.com/erp/devel/pi/rev/5e48183608e8 changeset: 33017:5e48183608e8 user: Atul Gaware <atul.gaware <at> openbravo.com> date: Thu Nov 09 06:16:13 2017 +0530 summary: Fixes Issue 37209, Fixes Issue 37244: Used credit field is not updated when credit is used in the same payment other credit is generated and Credit information do not updated if a payment containing credit info is reactivated.
** Reset usedCredit when traversing through the selected credit payment Whenever there is sufficient payment amount to fully pay the invoice and user still selects credit payments, discard the selection of credit payment in such cases as credit is not actually being used. ** Set credit payment description only in case it is actually consumed diffstat: modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/actionHandler/AddPaymentActionHandler.java | 36 +++++---- 1 files changed, 19 insertions(+), 17 deletions(-) diffs (51 lines): diff -r 9dee13d93441 -r 5e48183608e8 modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/actionHandler/AddPaymentActionHandler.java --- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/actionHandler/AddPaymentActionHandler.java Fri Nov 17 12:43:21 2017 +0100 +++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/actionHandler/AddPaymentActionHandler.java Thu Nov 09 06:16:13 2017 +0530 @@ -382,28 +382,30 @@ businessPartner.getCurrency().getISOCode())); } BigDecimal usedCreditAmt = selectedCreditPaymentAmounts.get(creditPayment.getId()); - if (strDifferenceAction.equals("refund")) { - if (remainingRefundAmt.compareTo(usedCreditAmt) > 0) { - remainingRefundAmt = remainingRefundAmt.subtract(usedCreditAmt); - usedCreditAmt = BigDecimal.ZERO; - } else { - usedCreditAmt = usedCreditAmt.subtract(remainingRefundAmt); - remainingRefundAmt = BigDecimal.ZERO; - } + + // Reset usedCredit by traversing through each credit payment + if (remainingRefundAmt.compareTo(usedCreditAmt) > 0) { + remainingRefundAmt = remainingRefundAmt.subtract(usedCreditAmt); + usedCreditAmt = BigDecimal.ZERO; + } else { + usedCreditAmt = usedCreditAmt.subtract(remainingRefundAmt); + remainingRefundAmt = BigDecimal.ZERO; } - final StringBuffer description = new StringBuffer(); - if (creditPayment.getDescription() != null && !creditPayment.getDescription().equals("")) { - description.append(creditPayment.getDescription()).append("\n"); - } - description.append(String.format(OBMessageUtils.messageBD("APRM_CreditUsedPayment"), - payment.getDocumentNo())); - String truncateDescription = (description.length() > 255) ? description.substring(0, 251) - .concat("...").toString() : description.toString(); - creditPayment.setDescription(truncateDescription); + // Set Used Credit = Amount + Previous used credit introduced by the user creditPayment.setUsedCredit(usedCreditAmt.add(creditPayment.getUsedCredit())); if (usedCreditAmt.compareTo(BigDecimal.ZERO) > 0) { + // Set Credit description only when it is actually used + final StringBuffer description = new StringBuffer(); + if (creditPayment.getDescription() != null && !creditPayment.getDescription().equals("")) { + description.append(creditPayment.getDescription()).append("\n"); + } + description.append(String.format(OBMessageUtils.messageBD("APRM_CreditUsedPayment"), + payment.getDocumentNo())); + String truncateDescription = (description.length() > 255) ? description.substring(0, 251) + .concat("...").toString() : description.toString(); + creditPayment.setDescription(truncateDescription); FIN_PaymentProcess.linkCreditPayment(payment, usedCreditAmt, creditPayment); } OBDal.getInstance().save(creditPayment); ------------------------------------------------------------------------------ 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