details: https://code.openbravo.com/erp/devel/pi/rev/7aa612d3e36d changeset: 16818:7aa612d3e36d user: Antonio Moreno <antonio.moreno <at> openbravo.com> date: Tue Jun 12 16:03:03 2012 +0200 summary: Related to issue 19915. Initialized more entities for increased safeness.
details: https://code.openbravo.com/erp/devel/pi/rev/b6f4ca5411d2 changeset: 16819:b6f4ca5411d2 user: Antonio Moreno <antonio.moreno <at> openbravo.com> date: Tue Jun 12 18:58:59 2012 +0200 summary: Fixed issue 20739. Changes done to improve the Save and Process payment processes: - An index has been added. - Instead of reading the organization information list from the organization, a direct query to the orginfo using the org id is done. - Some flushes (particularly those related to 'processing' columns) have been removed. - The description of the payment, and the method which updates the editable payment plan, have been disabled in case the order comes from the POS. - The query to find the maximum line number in the Financial transaction table has been improved. diffstat: modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/dao/TransactionsDao.java | 27 +- modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_AddPayment.java | 54 +++-- modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_PaymentProcess.java | 98 +++++---- modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_TransactionProcess.java | 14 +- modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/utility/FIN_Utility.java | 5 +- modules/org.openbravo.client.application/src/org/openbravo/client/application/window/ApplicationDictionaryCachedStructures.java | 3 + src-db/database/model/tables/FIN_FINACC_TRANSACTION.xml | 4 + 7 files changed, 113 insertions(+), 92 deletions(-) diffs (truncated from 423 to 300 lines): diff -r f35c55cdedf5 -r b6f4ca5411d2 modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/dao/TransactionsDao.java --- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/dao/TransactionsDao.java Tue Jun 12 18:59:06 2012 +0200 +++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/dao/TransactionsDao.java Tue Jun 12 18:58:59 2012 +0200 @@ -33,6 +33,7 @@ import org.openbravo.base.provider.OBProvider; import org.openbravo.base.secureApp.VariablesSecureApp; import org.openbravo.base.session.OBPropertiesProvider; +import org.openbravo.dal.core.DalUtil; import org.openbravo.dal.core.OBContext; import org.openbravo.dal.service.OBCriteria; import org.openbravo.dal.service.OBDal; @@ -128,7 +129,7 @@ newTransaction.setForeignAmount(payment.getAmount()); } OBDal.getInstance().save(newTransaction); - OBDal.getInstance().flush(); + // OBDal.getInstance().flush(); } finally { OBContext.restorePreviousMode(); } @@ -136,22 +137,16 @@ } public static Long getTransactionMaxLineNo(FIN_FinancialAccount financialAccount) { - OBContext.setAdminMode(); - Long maxLine = 0l; - try { - final OBCriteria<FIN_FinaccTransaction> obc = OBDal.getInstance().createCriteria( - FIN_FinaccTransaction.class); - obc.add(Restrictions.eq(FIN_FinaccTransaction.PROPERTY_ACCOUNT, financialAccount)); - obc.addOrderBy(FIN_FinaccTransaction.PROPERTY_LINENO, false); - obc.setMaxResults(1); - final List<FIN_FinaccTransaction> fat = obc.list(); - if (fat.size() == 0) - return 0l; - maxLine = fat.get(0).getLineNo(); - } finally { - OBContext.restorePreviousMode(); + Query query = OBDal + .getInstance() + .getSession() + .createQuery( + "select max(f.lineNo) as maxLineno from FIN_Finacc_Transaction as f where account.id=?"); + query.setString(0, (String) DalUtil.getId(financialAccount)); + for (Object obj : query.list()) { + return (Long) obj; } - return maxLine; + return 0l; } @Deprecated diff -r f35c55cdedf5 -r b6f4ca5411d2 modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_AddPayment.java --- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_AddPayment.java Tue Jun 12 18:59:06 2012 +0200 +++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_AddPayment.java Tue Jun 12 18:58:59 2012 +0200 @@ -186,10 +186,10 @@ amountDifference, false, null); } if (assignedAmount.compareTo(payment.getAmount()) == -1) { - FIN_PaymentScheduleDetail refundScheduleDetail = dao.getNewPaymentScheduleDetail(payment - .getOrganization(), payment.getAmount().subtract(assignedAmount)); - dao.getNewPaymentDetail(payment, refundScheduleDetail, payment.getAmount().subtract( - assignedAmount), BigDecimal.ZERO, false, null); + FIN_PaymentScheduleDetail refundScheduleDetail = dao.getNewPaymentScheduleDetail( + payment.getOrganization(), payment.getAmount().subtract(assignedAmount)); + dao.getNewPaymentDetail(payment, refundScheduleDetail, + payment.getAmount().subtract(assignedAmount), BigDecimal.ZERO, false, null); } } catch (final Exception e) { e.printStackTrace(System.err); @@ -258,8 +258,8 @@ refundPayment = payment; else { refundPayment = (FIN_Payment) DalUtil.copy(payment, false); - String strDescription = Utility.messageBD(conProvider, "APRM_RefundPayment", vars - .getLanguage()); + String strDescription = Utility.messageBD(conProvider, "APRM_RefundPayment", + vars.getLanguage()); strDescription += ": " + payment.getDocumentNo(); refundPayment.setDescription(strDescription); refundPayment.setGeneratedCredit(BigDecimal.ZERO); @@ -276,8 +276,8 @@ setFinancialTransactionAmountAndRate(refundPayment, conversionRate, null); - FIN_PaymentScheduleDetail refundScheduleDetail = dao.getNewPaymentScheduleDetail(payment - .getOrganization(), refundAmount); + FIN_PaymentScheduleDetail refundScheduleDetail = dao.getNewPaymentScheduleDetail( + payment.getOrganization(), refundAmount); dao.getNewPaymentDetail(refundPayment, refundScheduleDetail, refundAmount, BigDecimal.ZERO, true, null); @@ -323,8 +323,9 @@ selectedPaymentScheduleDetailAmounts.get(paymentScheduleDetail.getId())); dao.getNewPaymentProposalDetail(paymentProposal.getOrganization(), paymentProposal, - paymentScheduleDetail, selectedPaymentScheduleDetailAmounts.get(paymentScheduleDetail - .getId()), detailWriteOffAmt, null); + paymentScheduleDetail, + selectedPaymentScheduleDetailAmounts.get(paymentScheduleDetail.getId()), + detailWriteOffAmt, null); } } @@ -592,8 +593,8 @@ FIN_PaymentScheduleDetail[] FIN_PaymentScheduleDetails = new FIN_PaymentScheduleDetail[0]; FIN_PaymentScheduleDetails = shownScheduledPaymentDetails.toArray(FIN_PaymentScheduleDetails); FieldProvider[] data = FieldProviderFactory.getFieldProviderArray(shownScheduledPaymentDetails); - String dateFormat = OBPropertiesProvider.getInstance().getOpenbravoProperties().getProperty( - "dateFormat.java"); + String dateFormat = OBPropertiesProvider.getInstance().getOpenbravoProperties() + .getProperty("dateFormat.java"); SimpleDateFormat dateFormater = new SimpleDateFormat(dateFormat); // FIXME: added to access the FIN_PaymentSchedule and FIN_PaymentScheduleDetail tables to be // removed when new security implementation is done @@ -712,11 +713,18 @@ .getInvoicePaymentSchedule().getFINPaymentPriority().getColor()); } } else { - FieldProviderFactory.setField(data[i], "dueDate", dateFormater.format( - FIN_PaymentScheduleDetails[i].getOrderPaymentSchedule().getDueDate()).toString()); - FieldProviderFactory.setField(data[i], "transactionDate", dateFormater.format( - FIN_PaymentScheduleDetails[i].getOrderPaymentSchedule().getOrder().getOrderDate()) - .toString()); + FieldProviderFactory.setField( + data[i], + "dueDate", + dateFormater.format( + FIN_PaymentScheduleDetails[i].getOrderPaymentSchedule().getDueDate()).toString()); + FieldProviderFactory.setField( + data[i], + "transactionDate", + dateFormater + .format( + FIN_PaymentScheduleDetails[i].getOrderPaymentSchedule().getOrder() + .getOrderDate()).toString()); FieldProviderFactory.setField(data[i], "invoicedAmount", ""); FieldProviderFactory.setField(data[i], "expectedAmount", FIN_PaymentScheduleDetails[i] .getOrderPaymentSchedule().getAmount().toString()); @@ -810,14 +818,14 @@ OBCriteria<FIN_PaymentScheduleDetail> psdFilter = OBDal.getInstance().createCriteria( FIN_PaymentScheduleDetail.class); psdFilter.add(Restrictions.eq(FIN_PaymentScheduleDetail.PROPERTY_CLIENT, psd.getClient())); - psdFilter.add(Restrictions.eq(FIN_PaymentScheduleDetail.PROPERTY_ORGANIZATION, psd - .getOrganization())); + psdFilter.add(Restrictions.eq(FIN_PaymentScheduleDetail.PROPERTY_ORGANIZATION, + psd.getOrganization())); psdFilter.add(Restrictions.isNull(FIN_PaymentScheduleDetail.PROPERTY_PAYMENTDETAILS)); if (psd.getOrderPaymentSchedule() == null) psdFilter.add(Restrictions.isNull(FIN_PaymentScheduleDetail.PROPERTY_ORDERPAYMENTSCHEDULE)); else - psdFilter.add(Restrictions.eq(FIN_PaymentScheduleDetail.PROPERTY_ORDERPAYMENTSCHEDULE, psd - .getOrderPaymentSchedule())); + psdFilter.add(Restrictions.eq(FIN_PaymentScheduleDetail.PROPERTY_ORDERPAYMENTSCHEDULE, + psd.getOrderPaymentSchedule())); if (psd.getInvoicePaymentSchedule() == null) psdFilter.add(Restrictions .isNull(FIN_PaymentScheduleDetail.PROPERTY_INVOICEPAYMENTSCHEDULE)); @@ -941,8 +949,8 @@ OBCriteria<FinAccPaymentMethod> psdFilter = OBDal.getInstance().createCriteria( FinAccPaymentMethod.class); psdFilter.add(Restrictions.eq(FinAccPaymentMethod.PROPERTY_ACCOUNT, payment.getAccount())); - psdFilter.add(Restrictions.eq(FinAccPaymentMethod.PROPERTY_PAYMENTMETHOD, payment - .getPaymentMethod())); + psdFilter.add(Restrictions.eq(FinAccPaymentMethod.PROPERTY_PAYMENTMETHOD, + payment.getPaymentMethod())); for (FinAccPaymentMethod paymentMethod : psdFilter.list()) { return payment.isReceipt() ? paymentMethod.isAutomaticDeposit() : paymentMethod .isAutomaticWithdrawn(); diff -r f35c55cdedf5 -r b6f4ca5411d2 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 Tue Jun 12 18:59:06 2012 +0200 +++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_PaymentProcess.java Tue Jun 12 18:58:59 2012 +0200 @@ -83,13 +83,13 @@ final ConnectionProvider conProvider = bundle.getConnection(); final boolean isReceipt = payment.isReceipt(); - payment.setProcessNow(true); - OBDal.getInstance().save(payment); - OBDal.getInstance().flush(); + // payment.setProcessNow(true); + // OBDal.getInstance().save(payment); + // OBDal.getInstance().flush(); if (strAction.equals("P") || strAction.equals("D")) { // Set APRM_Ready preference - if (!dao.existsAPRMReadyPreference() - && vars.getSessionValue("APRMT_MigrationToolRunning", "N").equals("Y")) { + if (vars.getSessionValue("APRMT_MigrationToolRunning", "N").equals("Y") + && !dao.existsAPRMReadyPreference()) { dao.createAPRMReadyPreference(); } @@ -163,33 +163,37 @@ glitems.add(paymentDetail.getGLItem().getName()); } // Set description - StringBuffer description = new StringBuffer(); - if (payment.getDescription() != null && !payment.getDescription().equals("")) - description.append(payment.getDescription()).append("\n"); - if (!invoiceDocNos.isEmpty()) { - description.append(Utility.messageBD(conProvider, "InvoiceDocumentno", language)); - description.append(": ").append( - invoiceDocNos.toString().substring(1, invoiceDocNos.toString().length() - 1)); - description.append("\n"); + if (bundle.getParams().get("isPOSOrder") == null + || !bundle.getParams().get("isPOSOrder").equals("Y")) { + StringBuffer description = new StringBuffer(); + + if (payment.getDescription() != null && !payment.getDescription().equals("")) + description.append(payment.getDescription()).append("\n"); + if (!invoiceDocNos.isEmpty()) { + description.append(Utility.messageBD(conProvider, "InvoiceDocumentno", language)); + description.append(": ").append( + invoiceDocNos.toString().substring(1, invoiceDocNos.toString().length() - 1)); + description.append("\n"); + } + if (!orderDocNos.isEmpty()) { + description.append(Utility.messageBD(conProvider, "OrderDocumentno", language)); + description.append(": ").append( + orderDocNos.toString().substring(1, orderDocNos.toString().length() - 1)); + description.append("\n"); + } + if (!glitems.isEmpty()) { + description.append(Utility.messageBD(conProvider, "APRM_GLItem", language)); + description.append(": ").append( + glitems.toString().substring(1, glitems.toString().length() - 1)); + description.append("\n"); + } + if (!"".equals(strRefundCredit)) + description.append(strRefundCredit).append("\n"); + + String truncateDescription = (description.length() > 255) ? description + .substring(0, 252).concat("...").toString() : description.toString(); + payment.setDescription(truncateDescription); } - if (!orderDocNos.isEmpty()) { - description.append(Utility.messageBD(conProvider, "OrderDocumentno", language)); - description.append(": ").append( - orderDocNos.toString().substring(1, orderDocNos.toString().length() - 1)); - description.append("\n"); - } - if (!glitems.isEmpty()) { - description.append(Utility.messageBD(conProvider, "APRM_GLItem", language)); - description.append(": ").append( - glitems.toString().substring(1, glitems.toString().length() - 1)); - description.append("\n"); - } - if (!"".equals(strRefundCredit)) - description.append(strRefundCredit).append("\n"); - - String truncateDescription = (description.length() > 255) ? description.substring(0, 252) - .concat("...").toString() : description.toString(); - payment.setDescription(truncateDescription); if (paymentAmount.compareTo(payment.getAmount()) != 0) { payment.setUsedCredit(paymentAmount.subtract(payment.getAmount())); @@ -237,9 +241,9 @@ payment.isReceipt())) { try { payment.setStatus("RPAE"); - payment.setProcessNow(false); - OBDal.getInstance().save(payment); - OBDal.getInstance().flush(); + // payment.setProcessNow(false); + // OBDal.getInstance().save(payment); + // OBDal.getInstance().flush(); if (dao.hasNotDeferredExecutionProcess(payment.getAccount(), payment.getPaymentMethod(), payment.isReceipt())) { @@ -338,7 +342,7 @@ } } payment.setStatus(isReceipt ? "RPR" : "PPM"); - if ((FIN_Utility.isAutomaticDepositWithdrawn(payment) || strAction.equals("D")) + if ((strAction.equals("D") || FIN_Utility.isAutomaticDepositWithdrawn(payment)) && payment.getAmount().compareTo(BigDecimal.ZERO) != 0) triggerAutomaticFinancialAccountTransaction(vars, conProvider, payment); } @@ -897,20 +901,23 @@ } } - payment.setProcessNow(false); - OBDal.getInstance().save(payment); - OBDal.getInstance().flush(); + // payment.setProcessNow(false); + // OBDal.getInstance().save(payment); + // OBDal.getInstance().flush(); // When payment is reversed, original payment plan is updated to reverse a particular original // payment plan details (the ones related with payment which is reverted) so this step can be // skipped - if (!"Y".equals(isReversedPayment) && !updateOriginalPaymentPlanInformation(payment)) { - msg.setType("Error"); - msg.setMessage(Utility.parseTranslation(conProvider, vars, language, - "@CouldNotUpdateOriginalPaymentPlan@")); - bundle.setResult(msg); - OBDal.getInstance().rollbackAndClose(); - return; + if (bundle.getParams().get("isPOSOrder") == null + || !bundle.getParams().get("isPOSOrder").equals("Y")) { ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ Openbravo-commits mailing list Openbravo-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbravo-commits