Skip to content

Commit

Permalink
Merge pull request #263 from etendosoftware/hotfix/#144-EPL-549
Browse files Browse the repository at this point in the history
Issue #144: The method "getProductPrice" generates a NPE
  • Loading branch information
isaiasb-etendo authored Dec 5, 2023
2 parents 2957d61 + 85da4c1 commit de8e991
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 7 deletions.
34 changes: 34 additions & 0 deletions src-test/src/org/openbravo/financial/FinancialUtilsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.openbravo.financial;

import java.util.Date;

import org.openbravo.model.common.businesspartner.BusinessPartner;
import org.junit.Test;
import org.openbravo.base.exception.OBException;
import org.openbravo.dal.service.OBDal;
import org.openbravo.base.weld.test.WeldBaseTest;
import org.openbravo.model.pricing.pricelist.PriceList;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;


public class FinancialUtilsTest extends WeldBaseTest {
protected static final String BP_HEALTHY_FOOD = "B3ABB0B4AFEA4541AC1E29891D496079";


@Test
public void testGetProductPriceWithNullProduct() {
// Given
Date date = new Date();
BusinessPartner healthyFoodBP = OBDal.getInstance().get(BusinessPartner.class, BP_HEALTHY_FOOD);
PriceList priceList = healthyFoodBP.getPurchasePricelist();
// When
try {
FinancialUtils.getProductPrice(null, date, true, priceList);
fail("Expected an OBException to be thrown");
} catch (OBException e) {
assertEquals("@ParameterMissing@ @Product@", e.getMessage());
}
}
}
2 changes: 2 additions & 0 deletions src-test/src/org/openbravo/test/StandaloneTestSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
import org.openbravo.test.xml.EntityXMLIssues;
import org.openbravo.test.xml.UniqueConstraintImportTest;
import org.openbravo.userinterface.selectors.test.ExpressionsTest;
import org.openbravo.financial.FinancialUtilsTest;

/**
* This test class is called from the ant task run.all.tests by the CI server. It contains all the
Expand Down Expand Up @@ -355,6 +356,7 @@
// others
DocumentNumberGeneration.class, //
GridExport.class, //
FinancialUtilsTest.class, //


// Cancel and Replace Tests
Expand Down
18 changes: 11 additions & 7 deletions src/org/openbravo/financial/FinancialUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static BigDecimal getProductStdPrice(final Product product, final Date da
* ProductPrice to be used. In case a conversion is needed it uses the
* {@link #getConvertedAmount(BigDecimal, Currency, Currency, Date, Organization, String)
* getConvertedAmount()} method.
*
*
* @param product
* Product to get its ProductPrice.
* @param date
Expand Down Expand Up @@ -131,7 +131,7 @@ public static ProductPrice getProductPrice(final Product product, final Date dat
* Method to get a valid ProductPrice for the given Product. It only considers PriceList versions
* valid on the given date. If a PriceList is given it searches on that one. If PriceList null is
* passed it search on any Sales or Purchase PriceList based on the useSalesPriceList.
*
*
* @param product
* Product to get its ProductPrice.
* @param date
Expand All @@ -151,6 +151,10 @@ public static ProductPrice getProductPrice(final Product product, final Date dat
public static ProductPrice getProductPrice(final Product product, final Date date,
final boolean useSalesPriceList, final PriceList priceList, final boolean throwException,
final boolean usePriceIncludeTax) throws OBException {

if (product == null) {
throw new OBException("@ParameterMissing@ @Product@");
}
//@formatter:off
String hql =
"as pp" +
Expand Down Expand Up @@ -209,7 +213,7 @@ public static ProductPrice getProductPrice(final Product product, final Date dat
* Method to get the conversion rate defined at system level. If there is not a conversion rate
* defined on the given Organization it is searched recursively on its parent organization until
* one is found. If no conversion rate is found null is returned.
*
*
* @param date
* Date conversion is being performed.
* @param fromCurrency
Expand Down Expand Up @@ -274,7 +278,7 @@ public static BigDecimal getConvertedAmount(final BigDecimal amount, final Curre

/**
* Converts an amount.
*
*
* @param amount
* BigDecimal amount to convert.
* @param curFrom
Expand Down Expand Up @@ -343,7 +347,7 @@ public static Currency getLegalEntityCurrency(final Organization organization) {

/**
* Calculates the net unit price using the C_GET_NET_PRICE_FROM_GROSS stored procedure.
*
*
* @param strTaxId
* Tax that applies to the price.
* @param grossAmount
Expand All @@ -355,7 +359,7 @@ public static Currency getLegalEntityCurrency(final Organization organization) {
* @param quantity
* number of units to divide the amount to get the price.
* @return the net unit price
*
*
* @deprecated Use {@link #calculateNetAmtFromGross} instead
*/
@Deprecated
Expand All @@ -380,7 +384,7 @@ public static BigDecimal calculateNetFromGross(final String strTaxId,

/**
* Calculates the net unit price using the C_GET_NET_AMOUNT_FROM_GROSS stored procedure.
*
*
* @param strTaxId
* Tax that applies to the price.
* @param grossAmount
Expand Down

0 comments on commit de8e991

Please sign in to comment.