This is an automated email from the ASF dual-hosted git repository. jleroux pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git
The following commit(s) were added to refs/heads/trunk by this push: new 6b57e35dbc fixed: PartyFinancialHistory throws an error (OFBIZ-13099) 6b57e35dbc is described below commit 6b57e35dbc25d32fdaff8b956fe8eb22a3ed5bf7 Author: Jacques Le Roux <jacques.le.r...@les7arts.com> AuthorDate: Fri May 24 20:33:36 2024 +0200 fixed: PartyFinancialHistory throws an error (OFBIZ-13099) This is a rewrite for different reasons. The queryIterators were called twice, for instance while (invIterator.next()) { invoice = nvIterator.next() They are now called only once, else an instance would be lost while (invoice = invIterator.next()) { The expression above raises the CodeNarc rule AssignmentInConditional So I had to locally bypass it using comments I have added a warning in EntityListIterator::hasNext about that. Also the queryIterators must be closed as documented in EntityQuery::queryIterator: NOTE: THAT THIS MUST BE CLOSED (preferably in a finally block) WHEN YOU ARE DONE WITH IT, AND DON'T LEAVE IT OPEN TOO LONG BEACUSE IT WILL MAINTAIN A DATABASE CONNECTION. It could be possible to implements AutoCloseable in the call stack but not evident... EntityListIterator implements it... --- .../apache/ofbiz/party/party/PartyFinancialHistory.groovy | 13 +++++++++---- .../ofbiz/party/party/UnAppliedInvoicesForParty.groovy | 7 +++++-- .../ofbiz/party/party/UnAppliedPaymentsForParty.groovy | 6 ++++-- .../org/apache/ofbiz/entity/util/EntityListIterator.java | 6 ++++-- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/applications/party/src/main/groovy/org/apache/ofbiz/party/party/PartyFinancialHistory.groovy b/applications/party/src/main/groovy/org/apache/ofbiz/party/party/PartyFinancialHistory.groovy index a07be54e2d..278d1ee0b5 100644 --- a/applications/party/src/main/groovy/org/apache/ofbiz/party/party/PartyFinancialHistory.groovy +++ b/applications/party/src/main/groovy/org/apache/ofbiz/party/party/PartyFinancialHistory.groovy @@ -56,8 +56,9 @@ invExprs = invIterator = from('InvoiceAndType').where(invExprs).cursorScrollInsensitive().distinct().queryIterator() -while (invIterator.next()) { - invoice = nvIterator.next() +/* codenarc-disable */ +while (invoice = invIterator.next()) { +/* codenarc-enable */ Boolean isPurchaseInvoice = EntityTypeUtil.hasParentType(delegator, 'InvoiceType', 'invoiceTypeId', invoice.getString('invoiceTypeId'), 'parentTypeId', 'PURCHASE_INVOICE') Boolean isSalesInvoice = EntityTypeUtil.hasParentType(delegator, 'InvoiceType', 'invoiceTypeId', (String) invoice.getString('invoiceTypeId'), @@ -76,6 +77,8 @@ while (invIterator.next()) { } } +invIterator.close() + //get total/unapplied/applied payment in/out total amount: totalPayInApplied = BigDecimal.ZERO totalPayInNotApplied = BigDecimal.ZERO @@ -100,8 +103,9 @@ payExprs = payIterator = from('PaymentAndType').where(payExprs).cursorScrollInsensitive().distinct().queryIterator() -while (payIterator.next()) { - payment = payIterator.next() +/* codenarc-disable */ +while (payment = payIterator.next()) { +/* codenarc-enable */ if (payment.parentTypeId == 'DISBURSEMENT' || payment.parentTypeId == 'TAX_PAYMENT') { totalPayOutApplied += PaymentWorker.getPaymentApplied(payment, actualCurrency).setScale(2, RoundingMode.HALF_UP) totalPayOutNotApplied += PaymentWorker.getPaymentNotApplied(payment, actualCurrency).setScale(2, RoundingMode.HALF_UP) @@ -115,6 +119,7 @@ while (payIterator.next()) { + ' !!!! Should be either DISBURSEMENT, TAX_PAYMENT or RECEIPT') } } +payIterator.close() context.finanSummary = [:] context.finanSummary.totalSalesInvoice = totalSalesInvoice = totalInvSaApplied.add(totalInvSaNotApplied) diff --git a/applications/party/src/main/groovy/org/apache/ofbiz/party/party/UnAppliedInvoicesForParty.groovy b/applications/party/src/main/groovy/org/apache/ofbiz/party/party/UnAppliedInvoicesForParty.groovy index 5173c693a4..f4c23c5f4e 100644 --- a/applications/party/src/main/groovy/org/apache/ofbiz/party/party/UnAppliedInvoicesForParty.groovy +++ b/applications/party/src/main/groovy/org/apache/ofbiz/party/party/UnAppliedInvoicesForParty.groovy @@ -48,8 +48,10 @@ invExprs = invIterator = from('InvoiceAndType').where(invExprs).cursorScrollInsensitive().distinct().queryIterator() invoiceList = [] -while (invIterator.next()) { - invoice = invIterator.next() + +/* codenarc-disable */ +while (invoice = invIterator.next()) { +/* codenarc-enable */ unAppliedAmount = InvoiceWorker.getInvoiceNotApplied(invoice, actualCurrency).setScale(2, RoundingMode.HALF_UP) if (unAppliedAmount.signum() == 1) { if (actualCurrency == true) { @@ -66,5 +68,6 @@ while (invIterator.next()) { invoiceParentTypeId: invoice.parentTypeId]) } } +invIterator.close() context.ListUnAppliedInvoices = invoiceList diff --git a/applications/party/src/main/groovy/org/apache/ofbiz/party/party/UnAppliedPaymentsForParty.groovy b/applications/party/src/main/groovy/org/apache/ofbiz/party/party/UnAppliedPaymentsForParty.groovy index fb1773554b..51605bd171 100644 --- a/applications/party/src/main/groovy/org/apache/ofbiz/party/party/UnAppliedPaymentsForParty.groovy +++ b/applications/party/src/main/groovy/org/apache/ofbiz/party/party/UnAppliedPaymentsForParty.groovy @@ -50,8 +50,9 @@ payExprs = paymentList = [] payIterator = from('PaymentAndType').where(payExprs).cursorScrollInsensitive().distinct().queryIterator() -while (payIterator.next()) { - payment = payIterator.next() +/* codenarc-disable */ +while (payment = payIterator.next()) { +/* codenarc-enable */ unAppliedAmount = PaymentWorker.getPaymentNotApplied(payment, actualCurrency).setScale(2, RoundingMode.HALF_UP) if (unAppliedAmount.signum() == 1) { if (actualCurrency == true && payment.actualCurrencyAmount && payment.actualCurrencyUomId) { @@ -70,5 +71,6 @@ while (payIterator.next()) { paymentParentTypeId: payment.parentTypeId]) } } +payIterator.close() context.paymentList = paymentList diff --git a/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityListIterator.java b/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityListIterator.java index bebb3ef973..f79c4ebd07 100644 --- a/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityListIterator.java +++ b/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityListIterator.java @@ -273,8 +273,10 @@ public class EntityListIterator implements AutoCloseable, ListIterator<GenericVa * It is much better to just use next() until it returns null * For example, you could use the following to iterate through the results in an EntityListIterator: * GenericValue nextValue = null; - * while ((nextValue = (GenericValue) - * this.next()) != null) { ... } + * while ((nextValue = (GenericValue) this.next()) != null) { ... } + * Remember to not use next 2 times, in a while loop for instance... + * For Groovy you can use something like while (instance = Iterator.next()) + * but you need to surround it with codenarc disable/enable comments because of the AssignmentInConditional rule */ @Override public boolean hasNext() {