Attached Files | 31419_core.diff [^] (17,737 bytes) 2015-12-28 18:09 [Show Content] [Hide Content]diff --git a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/dao/AdvPaymentMngtDao.java b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/dao/AdvPaymentMngtDao.java
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/dao/AdvPaymentMngtDao.java
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/dao/AdvPaymentMngtDao.java
@@ -528,6 +528,13 @@
public FIN_PaymentDetail getNewPaymentDetail(FIN_Payment payment,
FIN_PaymentScheduleDetail paymentScheduleDetail, BigDecimal paymentDetailAmount,
BigDecimal writeoffAmount, boolean isRefund, GLItem glitem) {
+ return getNewPaymentDetail(payment, paymentScheduleDetail, paymentDetailAmount, writeoffAmount,
+ isRefund, glitem, true);
+ }
+
+ public FIN_PaymentDetail getNewPaymentDetail(FIN_Payment payment,
+ FIN_PaymentScheduleDetail paymentScheduleDetail, BigDecimal paymentDetailAmount,
+ BigDecimal writeoffAmount, boolean isRefund, GLItem glitem, boolean doFlush) {
try {
OBContext.setAdminMode(true);
final FIN_PaymentDetail newPaymentDetail = OBProvider.getInstance().get(
@@ -561,7 +568,9 @@
OBDal.getInstance().save(payment);
OBDal.getInstance().save(newPaymentDetail);
OBDal.getInstance().save(paymentScheduleDetail);
- OBDal.getInstance().flush();
+ if (doFlush) {
+ OBDal.getInstance().flush();
+ }
if (payment.getDocumentType().getDocumentSequence() != null) {
OBContext.getOBContext().removeWritableOrganization(
diff --git a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_AddPayment.java b/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
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_AddPayment.java
@@ -133,6 +133,8 @@
* this payment. Defaults to 1.0 if not supplied
* @param finTxnAmount
* Amount of payment in currency of financial account
+ * @param doFlush
+ * Force to flush inside the method after creating the payment
* @return The FIN_Payment OBObject containing all the Payment Details.
*/
public static FIN_Payment savePayment(FIN_Payment _payment, boolean isReceipt,
@@ -142,7 +144,7 @@
List<FIN_PaymentScheduleDetail> selectedPaymentScheduleDetails,
HashMap<String, BigDecimal> selectedPaymentScheduleDetailsAmounts, boolean isWriteoff,
boolean isRefund, Currency paymentCurrency, BigDecimal finTxnConvertRate,
- BigDecimal finTxnAmount) {
+ BigDecimal finTxnAmount, boolean doFlush) {
dao = new AdvPaymentMngtDao();
BigDecimal assignedAmount = BigDecimal.ZERO;
@@ -153,10 +155,12 @@
payment = dao.getNewPayment(isReceipt, organization, docType, strPaymentDocumentNo,
businessPartner, paymentMethod, finAccount, strPaymentAmount, paymentDate, referenceNo,
paymentCurrency, finTxnConvertRate, finTxnAmount);
- try {
- OBDal.getInstance().flush();
- } catch (Exception e) {
- throw new OBException(FIN_Utility.getExceptionMessage(e));
+ if (doFlush) {
+ try {
+ OBDal.getInstance().flush();
+ } catch (Exception e) {
+ throw new OBException(FIN_Utility.getExceptionMessage(e));
+ }
}
}
@@ -174,7 +178,7 @@
OBDal.getInstance().refresh(paymentScheduleDetail);
BigDecimal assignedAmountDiff = updatePaymentDetail(paymentScheduleDetail, payment,
- paymentDetailAmount, isWriteoff);
+ paymentDetailAmount, isWriteoff, doFlush);
assignedAmount = assignedAmount.add(assignedAmountDiff);
}
// TODO: Review this condition !=0??
@@ -194,6 +198,71 @@
return payment;
}
+ /**
+ * Saves the payment and the payment details based on the given Payment Schedule Details. If no
+ * FIN_Payment is given it creates a new one.
+ *
+ * If the Payment Scheduled Detail is not completely paid and the difference is not written a new
+ * Payment Schedule Detail is created with the difference.
+ *
+ * If a Refund Amount is given an extra Payment Detail will be created with it.
+ *
+ * @param _payment
+ * FIN_Payment where new payment details will be saved.
+ * @param isReceipt
+ * boolean to define if the Payment is a Receipt Payment (true) or a Payable Payment
+ * (false). Used when no FIN_Payment is given.
+ * @param docType
+ * DocumentType of the Payment. Used when no FIN_Payment is given.
+ * @param strPaymentDocumentNo
+ * String with the Document Number of the new payment. Used when no FIN_Payment is given.
+ * @param businessPartner
+ * BusinessPartner of the new Payment. Used when no FIN_Payment is given.
+ * @param paymentMethod
+ * FIN_PaymentMethod of the new Payment. Used when no FIN_Payment is given.
+ * @param finAccount
+ * FIN_FinancialAccount of the new Payment. Used when no FIN_Payment is given.
+ * @param strPaymentAmount
+ * String with the Payment Amount of the new Payment. Used when no FIN_Payment is given.
+ * @param paymentDate
+ * Date when the Payment is done. Used when no FIN_Payment is given.
+ * @param organization
+ * Organization of the new Payment. Used when no FIN_Payment is given.
+ * @param selectedPaymentScheduleDetails
+ * List of FIN_PaymentScheduleDetail to be included in the Payment. If one of the items
+ * is contained in other payment the method will throw an exception. Prevent
+ * invoice/order to be paid several times.
+ * @param selectedPaymentScheduleDetailsAmounts
+ * HashMap with the Amount to be paid for each Scheduled Payment Detail.
+ * @param isWriteoff
+ * Boolean to write off the difference when the payment amount is lower than the Payment
+ * Scheduled PAyment Detail amount.
+ * @param isRefund
+ * Not used.
+ * @param paymentCurrency
+ * The currency that the payment is being made in. Will default to financial account
+ * currency if not specified
+ * @param finTxnConvertRate
+ * Exchange rate to convert between payment currency and financial account currency for
+ * this payment. Defaults to 1.0 if not supplied
+ * @param finTxnAmount
+ * Amount of payment in currency of financial account
+ * @return The FIN_Payment OBObject containing all the Payment Details.
+ */
+ public static FIN_Payment savePayment(FIN_Payment _payment, boolean isReceipt,
+ DocumentType docType, String strPaymentDocumentNo, BusinessPartner businessPartner,
+ FIN_PaymentMethod paymentMethod, FIN_FinancialAccount finAccount, String strPaymentAmount,
+ Date paymentDate, Organization organization, String referenceNo,
+ List<FIN_PaymentScheduleDetail> selectedPaymentScheduleDetails,
+ HashMap<String, BigDecimal> selectedPaymentScheduleDetailsAmounts, boolean isWriteoff,
+ boolean isRefund, Currency paymentCurrency, BigDecimal finTxnConvertRate,
+ BigDecimal finTxnAmount) {
+ return savePayment(_payment, isReceipt, docType, strPaymentDocumentNo, businessPartner,
+ paymentMethod, finAccount, strPaymentAmount, paymentDate, organization, referenceNo,
+ selectedPaymentScheduleDetails, selectedPaymentScheduleDetailsAmounts, isWriteoff,
+ isRefund, paymentCurrency, finTxnConvertRate, finTxnAmount, true);
+ }
+
/*
* Temporary method to supply defaults for exchange Rate and converted amount
*/
@@ -207,7 +276,65 @@
return savePayment(_payment, isReceipt, docType, strPaymentDocumentNo, businessPartner,
paymentMethod, finAccount, strPaymentAmount, paymentDate, organization, referenceNo,
selectedPaymentScheduleDetails, selectedPaymentScheduleDetailsAmounts, isWriteoff,
- isRefund, null, null, null);
+ isRefund, null, null, null, true);
+ }
+
+ /**
+ * Saves the payment and the payment details based on the given Payment Schedule Details. If no
+ * FIN_Payment is given it creates a new one.
+ *
+ * If the Payment Scheduled Detail is not completely paid and the difference is not written a new
+ * Payment Schedule Detail is created with the difference.
+ *
+ * If a Refund Amount is given an extra Payment Detail will be created with it.
+ *
+ * @param _payment
+ * FIN_Payment where new payment details will be saved.
+ * @param isReceipt
+ * boolean to define if the Payment is a Receipt Payment (true) or a Payable Payment
+ * (false). Used when no FIN_Payment is given.
+ * @param docType
+ * DocumentType of the Payment. Used when no FIN_Payment is given.
+ * @param strPaymentDocumentNo
+ * String with the Document Number of the new payment. Used when no FIN_Payment is given.
+ * @param businessPartner
+ * BusinessPartner of the new Payment. Used when no FIN_Payment is given.
+ * @param paymentMethod
+ * FIN_PaymentMethod of the new Payment. Used when no FIN_Payment is given.
+ * @param finAccount
+ * FIN_FinancialAccount of the new Payment. Used when no FIN_Payment is given.
+ * @param strPaymentAmount
+ * String with the Payment Amount of the new Payment. Used when no FIN_Payment is given.
+ * @param paymentDate
+ * Date when the Payment is done. Used when no FIN_Payment is given.
+ * @param organization
+ * Organization of the new Payment. Used when no FIN_Payment is given.
+ * @param selectedPaymentScheduleDetails
+ * List of FIN_PaymentScheduleDetail to be included in the Payment. If one of the items
+ * is contained in other payment the method will throw an exception. Prevent
+ * invoice/order to be paid several times.
+ * @param selectedPaymentScheduleDetailsAmounts
+ * HashMap with the Amount to be paid for each Scheduled Payment Detail.
+ * @param isWriteoff
+ * Boolean to write off the difference when the payment amount is lower than the Payment
+ * Scheduled PAyment Detail amount.
+ * @param isRefund
+ * Not used.
+ * @param doFlush
+ * Force to flush inside the method after creating the payment
+ * @return The FIN_Payment OBObject containing all the Payment Details.
+ */
+ public static FIN_Payment savePayment(FIN_Payment _payment, boolean isReceipt,
+ DocumentType docType, String strPaymentDocumentNo, BusinessPartner businessPartner,
+ FIN_PaymentMethod paymentMethod, FIN_FinancialAccount finAccount, String strPaymentAmount,
+ Date paymentDate, Organization organization, String referenceNo,
+ List<FIN_PaymentScheduleDetail> selectedPaymentScheduleDetails,
+ HashMap<String, BigDecimal> selectedPaymentScheduleDetailsAmounts, boolean isWriteoff,
+ boolean isRefund, boolean doFlush) {
+ return savePayment(_payment, isReceipt, docType, strPaymentDocumentNo, businessPartner,
+ paymentMethod, finAccount, strPaymentAmount, paymentDate, organization, referenceNo,
+ selectedPaymentScheduleDetails, selectedPaymentScheduleDetailsAmounts, isWriteoff,
+ isRefund, null, null, null, doFlush);
}
/**
@@ -231,6 +358,34 @@
*/
public static BigDecimal updatePaymentDetail(FIN_PaymentScheduleDetail paymentScheduleDetail,
FIN_Payment payment, BigDecimal paymentDetailAmount, boolean isWriteoff) throws OBException {
+ return updatePaymentDetail(paymentScheduleDetail, payment, paymentDetailAmount, isWriteoff,
+ true);
+ }
+
+ /**
+ * Updates the paymentScheduleDetail with the paymentDetailAmount. If it is not related to the
+ * Payment a new Payment Detail is created. If isWriteoff is true and the amount is different to
+ * the outstanding amount the difference is written off.
+ *
+ * @param paymentScheduleDetail
+ * the Payment Schedule Detail to be assigned to the Payment
+ * @param payment
+ * the FIN_Payment that it is being paid
+ * @param paymentDetailAmount
+ * the amount of this paymentScheduleDetail that it is being paid
+ * @param isWriteoff
+ * flag to write off the difference when there is an outstanding amount remaining to pay
+ * @param doFlush
+ * Force to flush inside the method
+ * @return a BigDecimal with the amount newly assigned to the payment. For example, when the
+ * paymentScheduleDetail is already related to the payment and its amount is not changed
+ * BigDecimal.ZERO is returned.
+ * @throws OBException
+ * when the paymentDetailAmount is related to a different payment.
+ */
+ public static BigDecimal updatePaymentDetail(FIN_PaymentScheduleDetail paymentScheduleDetail,
+ FIN_Payment payment, BigDecimal paymentDetailAmount, boolean isWriteoff, boolean doFlush)
+ throws OBException {
BigDecimal assignedAmount = paymentDetailAmount;
if (paymentScheduleDetail.getPaymentDetails() != null) {
if (!paymentScheduleDetail.getPaymentDetails().getFinPayment().getId()
@@ -365,7 +520,7 @@
OBDal.getInstance().save(paymentScheduleDetail);
}
dao.getNewPaymentDetail(payment, paymentScheduleDetail, paymentDetailAmount,
- amountDifference, false, null);
+ amountDifference, false, null, doFlush);
}
return assignedAmount;
}
@@ -1422,6 +1577,38 @@
}
/**
+ * It calls the Payment Process using the given ProcessBundle
+ *
+ * @param pb
+ * ProcessBundle already created and initialized. This improves the performance when
+ * calling this method in a loop
+ * @param payment
+ * FIN_Payment that needs to be processed.
+ * @param comingFrom
+ * Origin where the process is invoked
+ * @param selectedCreditLineIds
+ * Id's of selected lines in Credit to Use grid
+ * @param doFlush
+ * Force to flush inside the method
+ * @return a OBError with the result message of the process.
+ * @throws Exception
+ */
+ public static OBError processPayment(ProcessBundle pb, String strAction, FIN_Payment payment,
+ String comingFrom, String selectedCreditLineIds, boolean doFlush) throws Exception {
+ HashMap<String, Object> parameters = new HashMap<String, Object>();
+ parameters.put("action", strAction);
+ parameters.put("Fin_Payment_ID", payment.getId());
+ parameters.put("comingFrom", comingFrom);
+ parameters.put("selectedCreditLineIds", selectedCreditLineIds);
+ parameters.put("doFlush", doFlush);
+ pb.setParams(parameters);
+ OBError myMessage = null;
+ new FIN_PaymentProcess().execute(pb);
+ myMessage = (OBError) pb.getResult();
+ return myMessage;
+ }
+
+ /**
* It calls the Payment Proposal Process for the given payment proposal and action.
*
* @param vars
diff --git a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_PaymentProcess.java b/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
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_PaymentProcess.java
@@ -94,7 +94,10 @@
isPosOrder = bundle.getParams().get("isPOSOrder").equals("Y");
}
final String paymentDate = (String) bundle.getParams().get("paymentdate");
- processPayment(payment, strAction, isPosOrder, paymentDate, comingFrom, selectedCreditLineIds);
+ final boolean doFlush = bundle.getParams().get("doFlush") != null ? (Boolean) bundle
+ .getParams().get("doFlush") : true;
+ processPayment(payment, strAction, isPosOrder, paymentDate, comingFrom,
+ selectedCreditLineIds, doFlush);
bundle.setResult(msg);
} catch (Exception e) {
log4j.error(e.getMessage());
@@ -110,11 +113,12 @@
public static void doProcessPayment(FIN_Payment payment, String strAction, Boolean isPosOrder,
String paymentDate, String comingFrom) throws OBException {
FIN_PaymentProcess fpp = WeldUtils.getInstanceFromStaticBeanManager(FIN_PaymentProcess.class);
- fpp.processPayment(payment, strAction, isPosOrder, paymentDate, comingFrom, null);
+ fpp.processPayment(payment, strAction, isPosOrder, paymentDate, comingFrom, null, true);
}
private void processPayment(FIN_Payment payment, String strAction, Boolean isPosOrder,
- String paymentDate, String comingFrom, String selectedCreditLineIds) throws OBException {
+ String paymentDate, String comingFrom, String selectedCreditLineIds, boolean doFlush)
+ throws OBException {
dao = new AdvPaymentMngtDao();
String msg = "";
try {
@@ -484,7 +488,7 @@
flushDone = true;
}
} finally {
- if (!flushDone) {
+ if (!flushDone && doFlush) {
OBDal.getInstance().flush();
}
OBContext.restorePreviousMode();
@@ -655,7 +659,7 @@
FIN_PaymentProcess fpp = WeldUtils
.getInstanceFromStaticBeanManager(FIN_PaymentProcess.class);
fpp.processPayment(reversedPayment, newStrAction, isPosOrder, paymentDate, comingFrom,
- selectedCreditLineIds);
+ selectedCreditLineIds, true);
return;
31419_remittance_1.diff [^] (6,447 bytes) 2015-12-28 18:09 [Show Content] [Hide Content]# HG changeset patch
# User Alvaro Ferraz <alvaro.ferraz@openbravo.com>
# Date 1449080087 -3600
# Wed Dec 02 19:14:47 2015 +0100
# Node ID ab29069d423fb0d3c24156f780e47192d10f696c
# Parent 1b7ed6f76806ac1e6fad1f4358d3564aec492d44
Fixes issue 31419: Processing a remittance with many lines is slow
Modify getRemittanceLines method and create a new one in REM_RemittanceProcess to retrieve only remittance line ids and do not load many entities in memory.
Modify existLineInSettledRemittance method in REM_AddRemittance to retrieve only one object.
diff --git a/src/org/openbravo/module/remittance/process/REM_AddRemittance.java b/src/org/openbravo/module/remittance/process/REM_AddRemittance.java
--- a/src/org/openbravo/module/remittance/process/REM_AddRemittance.java
+++ b/src/org/openbravo/module/remittance/process/REM_AddRemittance.java
@@ -817,11 +817,12 @@
OBCriteria<RemittanceLineCancel> remlc = OBDal.getInstance().createCriteria(
RemittanceLineCancel.class);
remlc.add(Restrictions.eq(Remittance.PROPERTY_PAYMENT, payment));
- List<RemittanceLineCancel> settledLines = remlc.list();
+ remlc.setMaxResults(1);
+ RemittanceLineCancel settledLine = (RemittanceLineCancel) remlc.uniqueResult();
HashMap<String, String> result = new HashMap<String, String>();
- if (settledLines.size() > 0) {
- result.put("documentno", settledLines.get(0).getRemittance().getDocumentNo());
- result.put("lineno", String.valueOf(settledLines.get(0).getLineNo()));
+ if (settledLine != null) {
+ result.put("documentno", settledLine.getRemittance().getDocumentNo());
+ result.put("lineno", String.valueOf(settledLine.getLineNo()));
}
return result;
}
diff --git a/src/org/openbravo/module/remittance/process/REM_RemittanceProcess.java b/src/org/openbravo/module/remittance/process/REM_RemittanceProcess.java
--- a/src/org/openbravo/module/remittance/process/REM_RemittanceProcess.java
+++ b/src/org/openbravo/module/remittance/process/REM_RemittanceProcess.java
@@ -290,8 +290,9 @@
}
paymentIdToRemove.add(payment.getId()); // To be removed later
// Clean all lines which point to this payment
- List<RemittanceLine> relatedLines = getRemittanceLines(payment, remittance);
- for (RemittanceLine relatedLine : relatedLines) {
+ for (String relatedLineId : getRemittanceLines(payment.getId(), remittance.getId())) {
+ RemittanceLine relatedLine = OBDal.getInstance().get(RemittanceLine.class,
+ relatedLineId);
relatedLine.setPayment(null);
OBDal.getInstance().save(relatedLine);
OBDal.getInstance().flush();
@@ -367,7 +368,8 @@
// Remittance lines of payments cannot be grouped
// Create new bank instruction line for each one
- for (RemittanceLine line : remittance.getREMRemittanceLineList()) {
+ for (String lineId : getRemittanceLines(remittance.getId())) {
+ RemittanceLine line = OBDal.getInstance().get(RemittanceLine.class, lineId);
FIN_Payment payment = line.getPayment();
if (payment != null) {
HashMap<String, String> rem = REM_AddRemittance.existLineInSettledRemittance(payment);
@@ -617,8 +619,10 @@
private void createPayments(Remittance remittance) throws Exception {
FIN_PaymentMethod pm = remittance.getRemittanceType().getPaymentMethod();
Currency faCurrency = remittance.getFinancialAccount().getCurrency();
- List<RemittanceLine> lines = remittance.getREMRemittanceLineList();
- for (RemittanceLine line : lines) {
+
+ for (String lineId : getRemittanceLines(remittance.getId())) {
+ RemittanceLine line = OBDal.getInstance().get(RemittanceLine.class, lineId);
+
if (line.getPayment() != null) {
FIN_Payment payment = line.getPayment();
HashMap<String, String> rem = REM_AddRemittance.existLineInSettledRemittance(payment);
@@ -1107,20 +1111,23 @@
}
}
- private List<RemittanceLine> getRemittanceLines(FIN_Payment payment, Remittance remittance) {
- List<RemittanceLine> list = new ArrayList<RemittanceLine>();
+ @SuppressWarnings("unchecked")
+ private List<String> getRemittanceLines(String paymentId, String remittanceId) {
OBContext.setAdminMode();
try {
- OBCriteria<RemittanceLine> obcRL = OBDal.getInstance().createCriteria(RemittanceLine.class);
- obcRL.setFilterOnReadableClients(false);
- obcRL.setFilterOnReadableOrganization(false);
- obcRL.add(Restrictions.eq(RemittanceLine.PROPERTY_PAYMENT, payment));
- obcRL.add(Restrictions.eq(RemittanceLine.PROPERTY_REMITTANCE, remittance));
- list = obcRL.list();
+ final StringBuilder whereClause = new StringBuilder();
+ whereClause.append(" select rl." + RemittanceLine.PROPERTY_ID);
+ whereClause.append(" from " + RemittanceLine.ENTITY_NAME + " as rl");
+ whereClause.append(" where rl." + RemittanceLine.PROPERTY_PAYMENT + ".id = :paymentId");
+ whereClause.append(" and rl." + RemittanceLine.PROPERTY_REMITTANCE + ".id = :remittanceId");
+ whereClause.append(" and rl." + RemittanceLine.PROPERTY_ACTIVE + " = true");
+ Query query = OBDal.getInstance().getSession().createQuery(whereClause.toString());
+ query.setParameter("paymentId", paymentId);
+ query.setParameter("remittanceId", remittanceId);
+ return query.list();
} finally {
OBContext.restorePreviousMode();
}
- return list;
}
private boolean isWrongRemTypePayMethodConfig(Remittance remittance) {
@@ -1240,4 +1247,21 @@
return "00000000000000000000";
}
}
+
+ @SuppressWarnings("unchecked")
+ private List<String> getRemittanceLines(String remittanceId) {
+ OBContext.setAdminMode();
+ try {
+ final StringBuilder whereClause = new StringBuilder();
+ whereClause.append(" select rl." + RemittanceLine.PROPERTY_ID);
+ whereClause.append(" from " + RemittanceLine.ENTITY_NAME + " as rl");
+ whereClause.append(" where rl." + RemittanceLine.PROPERTY_REMITTANCE + ".id = :remittanceId");
+ whereClause.append(" and rl." + RemittanceLine.PROPERTY_ACTIVE + " = true");
+ Query query = OBDal.getInstance().getSession().createQuery(whereClause.toString());
+ query.setParameter("remittanceId", remittanceId);
+ return query.list();
+ } finally {
+ OBContext.restorePreviousMode();
+ }
+ }
}
31419_remittance_2.diff [^] (8,065 bytes) 2015-12-28 18:09 [Show Content] [Hide Content]diff --git a/src/org/openbravo/module/remittance/process/REM_RemittanceProcess.java b/src/org/openbravo/module/remittance/process/REM_RemittanceProcess.java
--- a/src/org/openbravo/module/remittance/process/REM_RemittanceProcess.java
+++ b/src/org/openbravo/module/remittance/process/REM_RemittanceProcess.java
@@ -76,6 +76,8 @@
private OBError error = new OBError();
+ private long line = 0l;
+
public void execute(ProcessBundle bundle) throws Exception {
dao = new AdvPaymentMngtDao();
OBError msg = new OBError();
@@ -177,7 +179,7 @@
}
if (strAction.equals(GENERATE_PAYMENT)) {
- createPayments(remittance);
+ createPayments(remittance, bundle);
} else if (strAction.equals(GENERATE_GROUPED_PAYMENT)) {
createGroupedPayments(remittance, false, false);
} else if (strAction.equals(GENERATED_GROUPED_PAYMENT_DUEDATE)) {
@@ -547,11 +549,11 @@
payment = FIN_AddPayment.savePayment(null, isReceipt, docType, strPaymentDocumentNo,
currentbp, pm, remittance.getFinancialAccount(), currentPaymentTotal.toString(),
expectedDate, line.getOrganization(), "", psdList, hm, false, false,
- currentCurrency, txnConvRate, txnConvAmount);
+ currentCurrency, txnConvRate, txnConvAmount, false);
} else {
payment = FIN_AddPayment.savePayment(null, isReceipt, docType, strPaymentDocumentNo,
currentbp, pm, remittance.getFinancialAccount(), currentPaymentTotal.toString(),
- expectedDate, line.getOrganization(), "", psdList, hm, false, false);
+ expectedDate, line.getOrganization(), "", psdList, hm, false, false, false);
}
OBDal.getInstance().save(payment);
OBDal.getInstance().flush();
@@ -616,9 +618,12 @@
}
}
- private void createPayments(Remittance remittance) throws Exception {
+ private void createPayments(Remittance remittance, ProcessBundle bundle) throws Exception {
FIN_PaymentMethod pm = remittance.getRemittanceType().getPaymentMethod();
Currency faCurrency = remittance.getFinancialAccount().getCurrency();
+ final ProcessBundle pb = new ProcessBundle("6255BE488882480599C81284B70CD9B3", bundle
+ .getContext().toVars()).init(bundle.getConnection());
+ int i = 0;
for (String lineId : getRemittanceLines(remittance.getId())) {
RemittanceLine line = OBDal.getInstance().get(RemittanceLine.class, lineId);
@@ -633,16 +638,16 @@
}
payment.setStatus(STATUS_SENT);
// Associate to remittance payment method
- payment.setProcessed(false);
- OBDal.getInstance().save(payment);
- OBDal.getInstance().flush();
if (!STATUS_RECEIVED.equals(line.getOrigstatus())) {
+ payment.setProcessed(false);
+ OBDal.getInstance().save(payment);
+ OBDal.getInstance().flush(); // FIXME needed?
payment.setPaymentMethod(remittance.getRemittanceType().getPaymentMethod());
payment.setAccount(remittance.getFinancialAccount());
+ payment.setProcessed(true);
+ OBDal.getInstance().flush(); // FIXME needed?
}
- payment.setProcessed(true);
- OBDal.getInstance().save(payment);
- OBDal.getInstance().flush();
+
Instruction instruction = addRemittanceBankInstruction(remittance, payment);
instruction.setPayment(payment);
OBDal.getInstance().save(instruction);
@@ -650,6 +655,7 @@
}
Instruction instruction = addRemittanceBankInstruction(remittance,
line.getPaymentScheduleDetail(), line.getAmount());
+
if (!remittance.isSinglePayment()) {
boolean isReceipt = line.getPaymentScheduleDetail().getInvoicePaymentSchedule() != null ? line
.getPaymentScheduleDetail().getInvoicePaymentSchedule().getInvoice()
@@ -717,37 +723,39 @@
if (!line.getAmount().equals(new BigDecimal(0))) {
txnConvRate = txnConvAmount.divide(line.getAmount(), 6, BigDecimal.ROUND_HALF_UP);
}
+
payment = FIN_AddPayment.savePayment(null, isReceipt, docType, strPaymentDocumentNo, bp,
pm, remittance.getFinancialAccount(), line.getAmount().toString(), expectedDate,
line.getOrganization(), "", psdList, hm, false, false, currency, txnConvRate,
- txnConvAmount);
+ txnConvAmount, false);
} else {
payment = FIN_AddPayment.savePayment(null, isReceipt, docType, strPaymentDocumentNo, bp,
pm, remittance.getFinancialAccount(), line.getAmount().toString(), expectedDate,
- line.getOrganization(), "", psdList, hm, false, false);
+ line.getOrganization(), "", psdList, hm, false, false, false);
}
OBDal.getInstance().save(payment);
- OBDal.getInstance().flush();
instruction.setPayment(payment);
OBDal.getInstance().save(instruction);
- ConnectionProvider conn = new DalConnectionProvider();
- OBError error = FIN_AddPayment.processPayment(new VariablesSecureApp(OBContext
- .getOBContext().getUser().getId(), OBContext.getOBContext().getCurrentClient().getId(),
- OBContext.getOBContext().getCurrentOrganization().getId(), OBContext.getOBContext()
- .getRole().getId()), conn, isReceipt ? (!pm.isAutomaticDeposit() ? "P" : "D")
- : (!pm.isAutomaticWithdrawn() ? "P" : "D"), payment);
+ OBError error = FIN_AddPayment.processPayment(pb,
+ isReceipt ? (!pm.isAutomaticDeposit() ? "P" : "D") : (!pm.isAutomaticWithdrawn() ? "P"
+ : "D"), payment, null, null, false);
if ("Error".equals(error.getType())) {
throw new OBException(error.getMessage());
}
payment.setStatus(STATUS_SENT);
- OBDal.getInstance().save(payment);
line.setPayment(payment);
- OBDal.getInstance().save(payment);
- OBDal.getInstance().flush();
+
+ i++;
+ if (i % 100 == 0) {
+ OBDal.getInstance().flush();
+ }
}
+
}
+ // Flush last lines
+ OBDal.getInstance().flush();
if (remittance.isSinglePayment()) {
createSinglePayment(remittance);
}
@@ -908,12 +916,12 @@
payment = FIN_AddPayment.savePayment(null, isReceipt, docType, strPaymentDocumentNo, null,
remittance.getRemittanceType().getPaymentMethod(), remittance.getFinancialAccount(),
amount.toString(), remittance.getDueDate(), remittance.getOrganization(), "", psdList,
- hm, false, false, currency, txnConvRate, txnConvAmount);
+ hm, false, false, currency, txnConvRate, txnConvAmount, false);
} else {
payment = FIN_AddPayment.savePayment(null, isReceipt, docType, strPaymentDocumentNo, null,
remittance.getRemittanceType().getPaymentMethod(), remittance.getFinancialAccount(),
amount.toString(), remittance.getDueDate(), remittance.getOrganization(), "", psdList,
- hm, false, false);
+ hm, false, false, false);
}
OBDal.getInstance().save(payment);
ConnectionProvider conn = new DalConnectionProvider();
@@ -974,7 +982,6 @@
bankInstruction.setPayment(payment);
}
OBDal.getInstance().save(bankInstruction);
- OBDal.getInstance().flush();
return bankInstruction;
}
@@ -1099,16 +1106,8 @@
}
private long getNextInstructionLineNo(Remittance remittance) {
- OBCriteria<Instruction> obc = OBDal.getInstance().createCriteria(Instruction.class);
- obc.add(Restrictions.eq(Instruction.PROPERTY_REMITTANCE, remittance));
- obc.addOrderBy(Instruction.PROPERTY_LINENO, false);
- obc.setMaxResults(1);
- List<Instruction> instructions = obc.list();
- if (instructions.isEmpty()) {
- return 10l;
- } else {
- return instructions.get(0).getLineNo() + 10l;
- }
+ line = line + 10l;
+ return line;
}
@SuppressWarnings("unchecked")
31419_final_remittance.diff [^] (2,577 bytes) 2016-02-16 19:10 [Show Content] [Hide Content]# HG changeset patch
# User Víctor Martínez Romanos <victor.martinez@openbravo.com>
# Date 1455644245 -3600
# Tue Feb 16 18:37:25 2016 +0100
# Branch 16Q2
# Node ID f76791c88d48152c29f37a8eb890bbd008d3c906
# Parent a2cce8a0ec6e7727078c5d5be18e1f626fdc58c1
Related to issue 32044: Support for paymentId parameter
diff --git a/src/org/openbravo/module/remittance/process/REM_RemittanceProcess.java b/src/org/openbravo/module/remittance/process/REM_RemittanceProcess.java
--- a/src/org/openbravo/module/remittance/process/REM_RemittanceProcess.java
+++ b/src/org/openbravo/module/remittance/process/REM_RemittanceProcess.java
@@ -549,7 +549,7 @@
payment = FIN_AddPayment.savePayment(null, isReceipt, docType, strPaymentDocumentNo,
currentbp, pm, remittance.getFinancialAccount(), currentPaymentTotal.toString(),
expectedDate, line.getOrganization(), "", psdList, hm, false, false,
- currentCurrency, txnConvRate, txnConvAmount, false);
+ currentCurrency, txnConvRate, txnConvAmount, false, null);
} else {
payment = FIN_AddPayment.savePayment(null, isReceipt, docType, strPaymentDocumentNo,
currentbp, pm, remittance.getFinancialAccount(), currentPaymentTotal.toString(),
@@ -727,7 +727,7 @@
payment = FIN_AddPayment.savePayment(null, isReceipt, docType, strPaymentDocumentNo, bp,
pm, remittance.getFinancialAccount(), line.getAmount().toString(), expectedDate,
line.getOrganization(), "", psdList, hm, false, false, currency, txnConvRate,
- txnConvAmount, false);
+ txnConvAmount, false, null);
} else {
payment = FIN_AddPayment.savePayment(null, isReceipt, docType, strPaymentDocumentNo, bp,
pm, remittance.getFinancialAccount(), line.getAmount().toString(), expectedDate,
@@ -916,7 +916,7 @@
payment = FIN_AddPayment.savePayment(null, isReceipt, docType, strPaymentDocumentNo, null,
remittance.getRemittanceType().getPaymentMethod(), remittance.getFinancialAccount(),
amount.toString(), remittance.getDueDate(), remittance.getOrganization(), "", psdList,
- hm, false, false, currency, txnConvRate, txnConvAmount, false);
+ hm, false, false, currency, txnConvRate, txnConvAmount, false, null);
} else {
payment = FIN_AddPayment.savePayment(null, isReceipt, docType, strPaymentDocumentNo, null,
remittance.getRemittanceType().getPaymentMethod(), remittance.getFinancialAccount(),
|