details: https://code.openbravo.com/erp/devel/pi/rev/a1caffd894bb changeset: 26314:a1caffd894bb user: Unai Martirena <unai.martirena <at> openbravo.com> date: Wed Apr 08 16:42:45 2015 +0200 summary: Fixes bug 29273: Payment Out can be reactivated without bp purchase pricelist
The problem is that the method 'getConversionRateDocumentForInvoice' tries to get a conversion using the currency of Purchase PriceList of the business partner, and it could happen to be empty, so it fails. Starting from 3.0PR14Q4 the Currency field in the business partner is mandatory, so it can be used for Sales/Purchase flow. It could be that at this point while reactivating the Payment to be the Currency of the Business Partner null, because it was created long time ago and no currency set yet, so, if this is the case an error will be raised to the user in order to fix this. A last change has been made in 'OBMessageUtils.messageBD' method, adding an extra parameter when it is wanted to avoid doing escape of '\n' and doublequotes characters. In this case it is needed because the message that needs to be displayed needs to maintain them because contains a link. This implementation is similar to the one found in BasicUtility.messageBD. details: https://code.openbravo.com/erp/devel/pi/rev/a6642e0e5f0c changeset: 26315:a6642e0e5f0c user: Alvaro Ferraz <alvaro.ferraz <at> openbravo.com> date: Mon Apr 13 12:29:01 2015 +0200 summary: Related to issue 29273: Removed unused parameter Removed unused parameter in getConversionRateDocumentForInvoice method diffstat: modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_PaymentProcess.java | 22 +++++----- src/org/openbravo/erpCommon/utility/OBMessageUtils.java | 22 ++++++++- 2 files changed, 30 insertions(+), 14 deletions(-) diffs (111 lines): diff -r 801202997fd1 -r a6642e0e5f0c 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 Mar 13 14:51:22 2015 +0100 +++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_PaymentProcess.java Mon Apr 13 12:29:01 2015 +0200 @@ -391,7 +391,7 @@ paidAmount = BigDecimal.ZERO; String fromCurrency = payment.getCurrency().getId(); if (businessPartner.getCurrency() == null) { - String errorMSG = OBMessageUtils.messageBD("InitBPCurrencyLnk"); + String errorMSG = OBMessageUtils.messageBD("InitBPCurrencyLnk", false); msg = String.format(errorMSG, businessPartner.getId(), businessPartner.getName()); throw new OBException(msg); @@ -400,8 +400,7 @@ if (!fromCurrency.equals(toCurrency)) { BigDecimal exchangeRate = BigDecimal.ZERO; // check at invoice document level - List<ConversionRateDoc> conversionRateDocumentForInvoice = getConversionRateDocumentForInvoice( - invoiceForConversion, isReceipt); + List<ConversionRateDoc> conversionRateDocumentForInvoice = getConversionRateDocumentForInvoice(invoiceForConversion); if (conversionRateDocumentForInvoice.size() > 0) { exchangeRate = conversionRateDocumentForInvoice.get(0).getRate(); } else { @@ -783,15 +782,18 @@ paidAmount = BigDecimal.ZERO; if (!(businessPartner == null)) { final Currency fromCurrency = payment.getCurrency(); - // At this point the BP must have a currency, because it is set when - // processing the payment associated to the invoice + if (businessPartner.getCurrency() == null) { + String errorMSG = OBMessageUtils.messageBD("InitBPCurrencyLnk", false); + msg = String.format(errorMSG, businessPartner.getId(), + businessPartner.getName()); + throw new OBException(msg); + } final Currency toCurrency = businessPartner.getCurrency(); if (fromCurrency != null && toCurrency != null && !fromCurrency.getId().equals(toCurrency.getId())) { BigDecimal exchangeRate = BigDecimal.ZERO; // check at invoice document level - List<ConversionRateDoc> conversionRateDocumentForInvoice = getConversionRateDocumentForInvoice( - invoiceForConversion, isReceipt); + List<ConversionRateDoc> conversionRateDocumentForInvoice = getConversionRateDocumentForInvoice(invoiceForConversion); if (conversionRateDocumentForInvoice.size() > 0) { exchangeRate = conversionRateDocumentForInvoice.get(0).getRate(); } else { @@ -1255,15 +1257,13 @@ } } - private List<ConversionRateDoc> getConversionRateDocumentForInvoice(Invoice invoice, - boolean isReceipt) { + private List<ConversionRateDoc> getConversionRateDocumentForInvoice(Invoice invoice) { OBContext.setAdminMode(true); try { OBCriteria<ConversionRateDoc> obc = OBDal.getInstance().createCriteria( ConversionRateDoc.class); obc.add(Restrictions.eq(ConversionRateDoc.PROPERTY_CURRENCY, invoice.getCurrency())); - obc.add(Restrictions.eq(ConversionRateDoc.PROPERTY_TOCURRENCY, isReceipt ? invoice - .getBusinessPartner().getCurrency() : invoice.getBusinessPartner().getPurchasePricelist() + obc.add(Restrictions.eq(ConversionRateDoc.PROPERTY_TOCURRENCY, invoice.getBusinessPartner() .getCurrency())); obc.add(Restrictions.eq(ConversionRateDoc.PROPERTY_INVOICE, invoice)); return obc.list(); diff -r 801202997fd1 -r a6642e0e5f0c src/org/openbravo/erpCommon/utility/OBMessageUtils.java --- a/src/org/openbravo/erpCommon/utility/OBMessageUtils.java Fri Mar 13 14:51:22 2015 +0100 +++ b/src/org/openbravo/erpCommon/utility/OBMessageUtils.java Mon Apr 13 12:29:01 2015 +0200 @@ -43,6 +43,10 @@ public class OBMessageUtils { static Logger log4j = Logger.getLogger(OBMessageUtils.class); + public static String messageBD(String strCode, boolean escape) { + return messageBD(strCode, true, escape); + } + /** * Translate the given code into some message from the application dictionary. It searches first * in AD_Message table and if there are not matchings then in AD_Element table. @@ -53,10 +57,20 @@ */ public static String messageBD(String strCode) { - return messageBD(strCode, true); + return messageBD(strCode, true, true); } - public static String messageBD(String strCode, boolean ignoreCase) { + /** + * @param strCode + * String with the search key to search. + * @param ignoreCase + * Ignore Case while finding message. + * @param escape + * Escape \n and " characters + * @return String with the translated message. + */ + + public static String messageBD(String strCode, boolean ignoreCase, boolean escape) { String strMessage = ""; final String strLanguageId = OBContext.getOBContext().getLanguage().getId(); // Search strCode in AD_Message table. @@ -113,7 +127,9 @@ if ("".equals(strMessage)) { strMessage = strCode; } - strMessage = Replace.replace(Replace.replace(strMessage, "\n", "\\n"), "\"", """); + if (escape) { + strMessage = Replace.replace(Replace.replace(strMessage, "\n", "\\n"), "\"", """); + } return strMessage; } ------------------------------------------------------------------------------ BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT Develop your own process in accordance with the BPMN 2 standard Learn Process modeling best practices with Bonita BPM through live exercises http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_ source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF _______________________________________________ Openbravo-commits mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openbravo-commits
