details: https://code.openbravo.com/erp/devel/pi/rev/88e59255b367 changeset: 18232:88e59255b367 user: Pandeeswari Ramakrishnan <pandeeswari.ramakrishnan <at> openbravo.com> date: Mon Oct 15 16:47:29 2012 +0200 summary: Fixes Issue 21800 : Not convertible(no rate) error during posting
details: https://code.openbravo.com/erp/devel/pi/rev/f35b24a7ba04 changeset: 18233:f35b24a7ba04 user: Pandeeswari Ramakrishnan <pandeeswari.ramakrishnan <at> openbravo.com> date: Tue Oct 09 16:41:12 2012 +0200 summary: Fixes Issue 21841: Payment In - Value change in amount affects mutiple invoices diffstat: modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddOrderOrInvoice.html | 9 +- src/org/openbravo/erpCommon/ad_forms/AcctServer.java | 41 +++++++++- 2 files changed, 44 insertions(+), 6 deletions(-) diffs (88 lines): diff -r cf5827841b25 -r f35b24a7ba04 modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddOrderOrInvoice.html --- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddOrderOrInvoice.html Wed Oct 17 08:57:02 2012 +0200 +++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/AddOrderOrInvoice.html Tue Oct 09 16:41:12 2012 +0200 @@ -98,11 +98,14 @@ keepSelection = true; } for (i = 0; i < total; i++) { - if (chk[i].checked && keepSelection) { - continue; - } scheduledPaymentDetailId = frm.elements["inpRecordId" + i].value; outstandingAmount = frm.elements["inpRecordAmt" + scheduledPaymentDetailId].value; + if (chk[i].checked && keepSelection) { + if(compare(outstandingAmount, '<', amount) && compare(distributedAmount, '==', outstandingAmount)) + continue; + else + amount = add(amount, frm.elements["inpPaymentAmount" + chk[i].value].value); + } if ( compare(outstandingAmount, '>', amount) ) { outstandingAmount = amount; } diff -r cf5827841b25 -r f35b24a7ba04 src/org/openbravo/erpCommon/ad_forms/AcctServer.java --- a/src/org/openbravo/erpCommon/ad_forms/AcctServer.java Wed Oct 17 08:57:02 2012 +0200 +++ b/src/org/openbravo/erpCommon/ad_forms/AcctServer.java Tue Oct 09 16:41:12 2012 +0200 @@ -19,6 +19,7 @@ import java.io.IOException; import java.math.BigDecimal; import java.math.MathContext; +import java.math.RoundingMode; import java.sql.Connection; import java.sql.SQLException; import java.text.ParseException; @@ -34,6 +35,7 @@ import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; +import org.hibernate.criterion.Projections; import org.hibernate.criterion.Restrictions; import org.openbravo.advpaymentmngt.APRM_FinaccTransactionV; import org.openbravo.base.secureApp.VariablesSecureApp; @@ -1182,11 +1184,44 @@ if (!currency.equals(acctSchema.m_C_Currency_ID)) { // if (log4j.isDebugEnabled()) log4j.debug // ("AcctServer - get converted amount (init)"); - String amt = getConvertedAmt("1", currency, acctSchema.m_C_Currency_ID, DateAcct, - acctSchema.m_CurrencyRateType, AD_Client_ID, AD_Org_ID, conn); + String amt = ""; + OBQuery<ConversionRateDoc> conversionQuery = null; + if (AD_Table_ID.equals(TABLEID_Invoice)) { + conversionQuery = OBDal.getInstance().createQuery( + ConversionRateDoc.class, + "invoice = '" + Record_ID + "' and currency='" + currency + "' and toCurrency='" + + acctSchema.m_C_Currency_ID + "'"); + } else if (AD_Table_ID.equals(TABLEID_Payment)) { + conversionQuery = OBDal.getInstance().createQuery( + ConversionRateDoc.class, + "payment = '" + Record_ID + "' and currency='" + currency + "' and toCurrency='" + + acctSchema.m_C_Currency_ID + "'"); + } else if (AD_Table_ID.equals(TABLEID_Transaction)) { + conversionQuery = OBDal.getInstance().createQuery( + ConversionRateDoc.class, + "financialAccountTransaction = '" + Record_ID + "' and currency='" + currency + + "' and toCurrency='" + acctSchema.m_C_Currency_ID + "'"); + } + if (conversionQuery.count() > 0) { + List<ConversionRateDoc> conversionRate = conversionQuery.list(); + OBCriteria<Currency> currencyCrit = OBDal.getInstance().createCriteria(Currency.class); + currencyCrit.add(Restrictions.eq(Currency.PROPERTY_ID, acctSchema.m_C_Currency_ID)); + currencyCrit.setProjection(Projections.max(Currency.PROPERTY_STANDARDPRECISION)); + Long precision = 0L; + if (currencyCrit.count() > 0) { + List<Currency> toCurrency = currencyCrit.list(); + precision = toCurrency.get(0).getStandardPrecision(); + } + BigDecimal convertedAmount = new BigDecimal("1") + .multiply(conversionRate.get(0).getRate()); + amt = convertedAmount.setScale(precision.intValue(), RoundingMode.HALF_UP).toString(); + } + if (("").equals(amt) || amt == null) + amt = getConvertedAmt("1", currency, acctSchema.m_C_Currency_ID, DateAcct, + acctSchema.m_CurrencyRateType, AD_Client_ID, AD_Org_ID, conn); // if (log4j.isDebugEnabled()) log4j.debug // ("get converted amount (end)"); - if (amt == null || amt.equals("")) { + if (amt == null || ("").equals(amt)) { convertible = false; log4j.warn("AcctServer - isConvertible NOT from " + currency + " - " + DocumentNo); } else if (log4j.isDebugEnabled()) ------------------------------------------------------------------------------ Everyone hates slow websites. So do we. Make your web apps faster with AppDynamics Download AppDynamics Lite for free today: http://p.sf.net/sfu/appdyn_sfd2d_oct _______________________________________________ Openbravo-commits mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openbravo-commits
