Commit c918e798 by Tuomas Riihimäki

Merge branch 'shopzerofix' into 'master'

Shopzerofix

Alennuksiin nollatuki

See merge request !136
2 parents e6406f46 ca833596
......@@ -108,9 +108,9 @@ public class ProductPBean {
List<Discount> discounts = new ArrayList<>();
if (overriddenUnitPrice != null && BigDecimal.ZERO.compareTo(overriddenUnitPrice) < 0) {
if (overriddenUnitPrice != null && BigDecimal.ZERO.compareTo(overriddenUnitPrice) <= 0) {
unitPrice = overriddenUnitPrice;
unitPrice = overriddenUnitPrice.negate();
lbean.sendMessage(MoyaEventType.ACCOUNTEVENT_INFO, permbean.getCurrentUser(), "User creating accountevent with discount");
// lbean.logMessage(SecurityLogType.accountEvent, permbean.getCurrentUser(), "User creating accountevent with discount");
} else {
......
......@@ -365,7 +365,11 @@ public class ProductShopView extends GenericCDIView {
for (ProductShopItem shopitem : shoppingcart) {
if (shopitem.getCount().compareTo(BigDecimal.ZERO) > 0) {
retuser = productBean.createAccountEvent(shopitem.getProduct(), shopitem.getCount(), shopitem.getOverriddenUnitPrice(), userView.getSelectedUser()).getUser();
// retuser = productBean.createAccountEvent(shopitem.getProduct(), shopitem.getCount(), shopitem.getOverriddenUnitPrice(), userView.getSelectedUser()).getUser();
BigDecimal overriddenPrice = (shopitem.isOverrideUnitPrice()) ? shopitem.getOverriddenUnitPrice() : null;
retuser = productBean.createAccountEvent(shopitem.getProduct(), shopitem.getCount(), overriddenPrice, userView.getSelectedUser()).getUser();
}
}
......
......@@ -46,7 +46,7 @@ public class ProductShopItemHelper extends GenericCDIView {
public void updateProductShopItemCount(ProductShopItem item) {
// Discounts or overridden price, you cannot get both
if(item.isPriceOverridden()) {
if(item.isOverrideUnitPrice()) {
item.setInternalPrice(item.getOverriddenUnitPrice().multiply(item.getCount()));
} else {
item.setInternalPrice(item.getProduct().getPrice().abs().multiply(item.getCount()));
......
......@@ -46,6 +46,7 @@ public class ProductShopItem {
private BigDecimal overriddenUnitPrice = BigDecimal.ZERO;
private boolean overrideUnitPrice = false;
......@@ -78,12 +79,10 @@ public class ProductShopItem {
/**
* Return products that
*
* @param findForStaffshop
* @return
*
*/
public static List<ProductShopItem> productGTList(List<Product> products, EventUser user) {
List<ProductShopItem> ret = new ArrayList<ProductShopItem>();
List<ProductShopItem> ret = new ArrayList<>();
for (Product prod : products) {
if (prod.getPrice().compareTo(BigDecimal.ZERO) >= 0) {
ret.add(new ProductShopItem(prod, user));
......@@ -94,7 +93,7 @@ public class ProductShopItem {
}
public static List<ProductShopItem> productList(List<Product> products, EventUser user) {
List<ProductShopItem> ret = new ArrayList<ProductShopItem>();
List<ProductShopItem> ret = new ArrayList<>();
for (Product prod : products) {
ret.add(new ProductShopItem(prod, user));
}
......@@ -124,7 +123,6 @@ public class ProductShopItem {
/**
* Price and discounts are only stored so we can show them to user, changing there does not change end price of card
* @param discounts
*/
public void setInternalPrice(BigDecimal price) {
this.price = price;
......@@ -195,8 +193,13 @@ public class ProductShopItem {
public BigDecimal getOverriddenUnitPrice() {
if(overriddenUnitPrice == null)
overriddenUnitPrice = BigDecimal.ZERO;
if(!isOverrideUnitPrice())
return getPrice().divide(getCount());
// isOverrideUnitPrice shout also check this, but just in case..
if(overriddenUnitPrice == null || overriddenUnitPrice.compareTo(BigDecimal.ZERO) < 0)
overriddenUnitPrice = getPrice().divide(getCount());
return overriddenUnitPrice;
}
......@@ -209,16 +212,35 @@ public class ProductShopItem {
* @param overrideUnitPrice
*/
public void setOverriddenUnitPrice(BigDecimal overrideUnitPrice) {
this.overriddenUnitPrice = overrideUnitPrice;
}
public boolean isPriceOverridden() {
return (getOverriddenUnitPrice() != null && getOverriddenUnitPrice().compareTo(BigDecimal.ZERO) > 0);
if(overrideUnitPrice != getPrice().divide(getCount())) {
setOverrideUnitPrice(true);
this.overriddenUnitPrice = overrideUnitPrice;
} else {
setOverrideUnitPrice(false);
this.overriddenUnitPrice = null;
}
}
public BigDecimal getUnitDiscount() {
return getPrice().divide(getCount()).subtract(getProduct().getPrice());
}
public boolean isOverrideUnitPrice() {
if(overrideUnitPrice && (overriddenUnitPrice == null || overriddenUnitPrice.compareTo(BigDecimal.ZERO) < 0)) {
return false;
}
return overrideUnitPrice;
}
public void setOverrideUnitPrice(boolean overrideUnitPrice) {
this.overrideUnitPrice = overrideUnitPrice;
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!