Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #144: The method "getProductPrice" generates a NPE #263

Merged
merged 6 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading