details: https://code.openbravo.com/erp/devel/pi/rev/fcdcb8232dfb changeset: 27535:fcdcb8232dfb user: Víctor Martínez Romanos <victor.martinez <at> openbravo.com> date: Thu Sep 03 17:13:57 2015 +0200 summary: Fixed bug 30685 Fixed bug 30686 Fixed bug 30751: Several Payment Proposal issues
This changeset includes the fixes for several issues related to the Payment Proposal flow: # 30685: Error when reactivating payment proposal related with a closed order Cause: The payment schedule detail was deleted as part of the reactivation process, however DAL wasn't aware of it: when trying to delete the associated payment proposal line, DAL tried first to set proposal line's PSD to null, creating a database constraint violation in the flush. # 30686: It is not possible to process payment related with a closed order and generated from payment proposal window. Cause: The payment detail associated to the closed order remained in the system and it couldn't be deleted neither manually nor automatically because it was linked to the payment proposal line # 30751: Lines deleted each time you reactivate a payment proposal Cause: The code in charge of deleting the payment proposal lines was deleting only the lines linked to the last set of processed payment schedule details, instead of doing for all of them. This code worked fine when the payment was reactivated from the Payment window, but not when it was called from the Payment Proposal window, wrongly removing payment proposal lines. The solution for all these issues is the following: 1. The payment proposal is set to processed=N before calling the payment process. This avoids the need of running flushes in the payment process to unprocess and process the payment proposal. That fixes the flush issues and increases the general performance of the process. 2. The code in charge of deleting the linked payment proposal lines is executed: 2.1 when a PSD is deleted because the amount is 0 (for example in the scenario where we close the order), or 2.2 when we are reactivating a payment (deleting lines only) and we don't come from payment proposal reactivation process. Now when calling the payment process from the Payment proposal, we pass a new parameter comingFrom to the payment process. 2.3 In Add Payment, when we are removing a line (for example while reactivating a payment deleting the lines) diffstat: modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/actionHandler/AddPaymentActionHandler.java | 2 + modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_PaymentProcess.java | 67 +++++++-- modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_PaymentProposalProcess.java | 9 +- 3 files changed, 61 insertions(+), 17 deletions(-) diffs (162 lines): diff -r dc8f878ff592 -r fcdcb8232dfb modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/actionHandler/AddPaymentActionHandler.java --- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/actionHandler/AddPaymentActionHandler.java Fri Sep 04 13:44:36 2015 +0000 +++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/actionHandler/AddPaymentActionHandler.java Thu Sep 03 17:13:57 2015 +0200 @@ -509,6 +509,8 @@ } } + FIN_PaymentProcess.removePaymentProposalLines(psd); + pd.getFINPaymentScheduleDetailList().remove(psd); OBDal.getInstance().save(pd); OBDal.getInstance().remove(psd); diff -r dc8f878ff592 -r fcdcb8232dfb modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_PaymentProcess.java --- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_PaymentProcess.java Fri Sep 04 13:44:36 2015 +0000 +++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_PaymentProcess.java Thu Sep 03 17:13:57 2015 +0200 @@ -29,6 +29,7 @@ import java.util.Set; import java.util.TreeSet; +import org.apache.commons.lang.StringUtils; import org.hibernate.criterion.Restrictions; import org.openbravo.advpaymentmngt.dao.AdvPaymentMngtDao; import org.openbravo.advpaymentmngt.dao.TransactionsDao; @@ -877,7 +878,12 @@ OBDal.getInstance().getSession().refresh(paymentDetail); } // If there is any schedule detail with amount zero, those are deleted + // Besides it removes the payment proposal lines linked to the PSD when + // a) we are removing the PSD and + // b) if we are reactivating a payment (deleting lines only) and we don't come from + // payment proposal reactivation process for (FIN_PaymentScheduleDetail psd : removedPDS) { + int proposalLinesRemoved = 0; if (BigDecimal.ZERO.compareTo(psd.getAmount()) == 0 && BigDecimal.ZERO.compareTo(psd.getWriteoffAmount()) == 0) { paymentDetail.getFINPaymentScheduleDetailList().remove(psd); @@ -890,8 +896,22 @@ psd.getOrderPaymentSchedule() .getFINPaymentScheduleDetailOrderPaymentScheduleList().remove(psd); } + + // Before deleting the PSD, we must delete any payment proposal line linked to it + proposalLinesRemoved = removePaymentProposalLines(psd); + OBDal.getInstance().remove(psd); } + + // Delete any payment proposal line linked to the PSD if we are reactivating a payment + // (deleting lines only), we haven't removed it in a previous step and we don't come + // from payment proposal reactivation process + if (strAction.equals("R") + && proposalLinesRemoved == 0 + && !StringUtils.equals(comingFrom, + FIN_PaymentProposalProcess.COMINGFROM_PAYMENTPROPOSALPROCESS)) { + removePaymentProposalLines(psd); + } } if (paymentDetail.getFINPaymentScheduleDetailList().size() == 0) { removedPD.add(paymentDetail); @@ -955,20 +975,6 @@ } if (strAction.equals("R")) { payment.setUsedCredit(BigDecimal.ZERO); - for (FIN_PaymentScheduleDetail psd : removedPDS) { - List<FIN_PaymentPropDetail> ppds = psd.getFINPaymentPropDetailList(); - if (ppds.size() > 0) { - for (FIN_PaymentPropDetail ppd : ppds) { - FIN_PaymentProposal paymentProposal = OBDal.getInstance().get( - FIN_PaymentProposal.class, ppd.getFinPaymentProposal().getId()); - paymentProposal.setProcessed(false); - OBDal.getInstance().save(paymentProposal); - OBDal.getInstance().remove(ppd); - OBDal.getInstance().flush(); - paymentProposal.setProcessed(true); - } - } - } } } finally { OBDal.getInstance().flush(); @@ -1408,4 +1414,37 @@ return exchangeRate; } + /** + * Removes the Payment Proposal Lines linked to the Payment Schedule Detail. If the payment + * proposal is already processed, the record is unprocessed first, then affected lines are + * deleted, and finally it gets back to processed status. This is done to avoid trigger validation + * errors. + * + * A common scenario where you want to delete a payment proposal line is when the payment schedule + * detail has been deleted + * + * @param psd + * Payment Schedule Detail + * @return number of Payment Proposal Lines removed + */ + public static int removePaymentProposalLines(FIN_PaymentScheduleDetail psd) { + int proposalLinesRemoved = 0; + for (FIN_PaymentPropDetail ppd : psd.getFINPaymentPropDetailList()) { + final FIN_PaymentProposal paymentProposal = ppd.getFinPaymentProposal(); + if (paymentProposal.isProcessed()) { + // Hack to delete Payment Proposal lines when you reactivate a payment linked to + // a processed payment proposal. + paymentProposal.setProcessed(false); + OBDal.getInstance().save(paymentProposal); + OBDal.getInstance().remove(ppd); + OBDal.getInstance().flush(); + paymentProposal.setProcessed(true); + } else { + OBDal.getInstance().remove(ppd); + } + proposalLinesRemoved++; + } + return proposalLinesRemoved; + } + } diff -r dc8f878ff592 -r fcdcb8232dfb modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_PaymentProposalProcess.java --- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_PaymentProposalProcess.java Fri Sep 04 13:44:36 2015 +0000 +++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_PaymentProposalProcess.java Thu Sep 03 17:13:57 2015 +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) 2010-2013 Openbravo SLU + * All portions are Copyright (C) 2010-2015 Openbravo SLU * All Rights Reserved. * Contributor(s): ______________________________________. ************************************************************************* @@ -51,6 +51,8 @@ public class FIN_PaymentProposalProcess implements org.openbravo.scheduling.Process { private static AdvPaymentMngtDao dao; + public static final String COMINGFROM_PAYMENTPROPOSALPROCESS = "PAYMENT_PROPOSAL"; + @Override public void execute(ProcessBundle bundle) throws Exception { final Logger log4j = Logger.getLogger(this.getClass()); @@ -231,11 +233,13 @@ } else if (strAction.equals("RE")) { // REACTIVATE paymentProposal.setProcessNow(true); + paymentProposal.setProcessed(false); // Needed to set it here: used by processPayment() List<String> paymentIdList = FIN_AddPayment.getPaymentFromPaymentProposal(paymentProposal); for (String id : paymentIdList) { FIN_Payment payment = OBDal.getInstance().get(FIN_Payment.class, id); - message = FIN_AddPayment.processPayment(vars, conProvider, "R", payment); + message = FIN_AddPayment.processPayment(vars, conProvider, "R", payment, + COMINGFROM_PAYMENTPROPOSALPROCESS); if (message.getType().equals("Error")) { bundle.setResult(message); return; @@ -247,7 +251,6 @@ OBDal.getInstance().remove(OBDal.getInstance().get(FIN_Payment.class, id)); } paymentProposal.setStatus("RPAP"); - paymentProposal.setProcessed(false); paymentProposal.setAPRMProcessProposal("G"); } ------------------------------------------------------------------------------ _______________________________________________ Openbravo-commits mailing list Openbravo-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbravo-commits