Commit 48917962 by Tuomas Riihimäki

Merge branch 'master' into 'master'

Master

autoproduct for user

See merge request !165
2 parents a392afcb 865f949a
...@@ -263,6 +263,25 @@ public class BillBean implements BillBeanLocal { ...@@ -263,6 +263,25 @@ public class BillBean implements BillBeanLocal {
loggingBean.sendMessage(MoyaEventType.BILL_ERROR, permbean.getCurrentUser(), "Not enought rights to create bill for user: ", bill.getUser()); loggingBean.sendMessage(MoyaEventType.BILL_ERROR, permbean.getCurrentUser(), "Not enought rights to create bill for user: ", bill.getUser());
throw new EJBAccessException("Could not create bill for another user"); throw new EJBAccessException("Could not create bill for another user");
} }
// if there is autoproducts, check that they exists in bill
for(Product product : productBean.listUserShoppableProducts()) {
if(product.isUsershopAutoproduct()) {
boolean containsAutoproduct = false;
for(BillLine line : bill.getBillLines()) {
if(line.getLineProduct() != null && line.getLineProduct().equals(product) && line.getQuantity().compareTo(BigDecimal.ONE) >= 0) {
containsAutoproduct = true;
}
}
if(!containsAutoproduct) {
BillLine line = new BillLine(bill, product, BigDecimal.ONE);
bill.getBillLines().add(line);
}
}
}
billFacade.create(bill); billFacade.create(bill);
generateBillNumber(bill); generateBillNumber(bill);
createPlaceslots(bill); createPlaceslots(bill);
......
...@@ -360,4 +360,9 @@ public class Product extends GenericEntity { ...@@ -360,4 +360,9 @@ public class Product extends GenericEntity {
this.licenseTargets = licenseTargets; this.licenseTargets = licenseTargets;
} }
public boolean isUsershopAutoproduct() {
return getProductFlags().contains(ProductFlag.USERSHOP_AUTOPRODUCT);
}
} }
...@@ -54,7 +54,13 @@ public enum ProductFlag { ...@@ -54,7 +54,13 @@ public enum ProductFlag {
/** /**
* Käyttäjän itse kaupasta ostettavissa oleva tuote. * Käyttäjän itse kaupasta ostettavissa oleva tuote.
*/ */
USER_SHOPPABLE; USER_SHOPPABLE,
/**
* Tuote joka lisätään jokaisen käyttäjäkaupasta tehtyyn tilaukseen automaattisesti
*/
USERSHOP_AUTOPRODUCT
;
private static final String KEY_PREFIX = "productFlag."; private static final String KEY_PREFIX = "productFlag.";
private final String key; private final String key;
...@@ -65,7 +71,6 @@ public enum ProductFlag { ...@@ -65,7 +71,6 @@ public enum ProductFlag {
public String getI18nkey() public String getI18nkey()
{ {
return key; return key;
} }
......
...@@ -23,8 +23,7 @@ ...@@ -23,8 +23,7 @@
<!-- <h:outputScript target="head" library="script" name="shopscript.js" /> --> <!-- <h:outputScript target="head" library="script" name="shopscript.js" /> -->
<h:outputScript library="primefaces" name="jquery/jquery.js" /> <h:outputScript library="primefaces" name="jquery/jquery.js" />
<p:dataTable columnClasses="nowrap,numalign,numalign,numalign,nowrap" <p:dataTable columnClasses="nowrap,numalign,numalign,numalign,nowrap" id="billcart" value="#{cc.attrs.items}" var="cart">
id="billcart" value="#{cc.attrs.items}" var="cart">
<p:column> <p:column>
<f:facet name="header"> <f:facet name="header">
<h:outputText id="name" value="${i18n['shop.product.name']}" /> <h:outputText id="name" value="${i18n['shop.product.name']}" />
...@@ -45,20 +44,26 @@ ...@@ -45,20 +44,26 @@
<h:outputText id="count" value="${i18n['product.cart.count']}" /> <h:outputText id="count" value="${i18n['product.cart.count']}" />
</f:facet> </f:facet>
<h:commandButton action="#{productShopView.addMinusOne}" <p:outputPanel rendered="#{cart.product.usershopAutoproduct}">
value="#{i18n['productshop.minusOne']}"> <h:outputText value="#{cart.count}" />
<f:ajax render="@form" /> </p:outputPanel>
</h:commandButton>
<p:inputText size="2" id="cartcount" escape="false" <p:outputPanel rendered="#{!cart.product.usershopAutoproduct}">
value="#{cart.count}"> <h:commandButton action="#{productShopView.addMinusOne}"
<f:ajax render="@form" value="#{i18n['productshop.minusOne']}">
listener="#{productShopView.countChangeListener}" /> <f:ajax render="@form" />
<f:convertNumber maxFractionDigits="2" minFractionDigits="0" /> </h:commandButton>
</p:inputText> <p:inputText size="2" id="cartcount" escape="false"
<h:commandButton action="#{productShopView.addOne}" value="#{cart.count}">
value="#{i18n['productshop.plusOne']}"> <f:ajax render="@form"
<f:ajax render="@form" /> listener="#{productShopView.countChangeListener}" />
</h:commandButton> <f:convertNumber maxFractionDigits="2" minFractionDigits="0" />
</p:inputText>
<h:commandButton action="#{productShopView.addOne}"
value="#{i18n['productshop.plusOne']}">
<f:ajax render="@form" />
</h:commandButton>
</p:outputPanel>
</p:column> </p:column>
<p:column rendered="#{productShopView.hasLimits}"> <p:column rendered="#{productShopView.hasLimits}">
<f:facet name="header"> <f:facet name="header">
...@@ -84,7 +89,7 @@ ...@@ -84,7 +89,7 @@
</p:column> </p:column>
<p:column> <p:column>
<f:facet name="header"> <f:facet name="header">
<h:outputText value="${i18n['product.totalPrice']}" /> <h:outputText value="#{i18n['product.totalPrice']}" />
</f:facet> </f:facet>
<h:outputText id="total" value="#{cart.price}"> <h:outputText id="total" value="#{cart.price}">
<f:convertNumber maxFractionDigits="2" minFractionDigits="2" currencyCode="EUR" type="currency" locale="#{sessionHandler.locale}" /> <f:convertNumber maxFractionDigits="2" minFractionDigits="2" currencyCode="EUR" type="currency" locale="#{sessionHandler.locale}" />
......
...@@ -120,9 +120,13 @@ public class ProductShopView extends GenericCDIView { ...@@ -120,9 +120,13 @@ public class ProductShopView extends GenericCDIView {
} }
public void initBillView() { public void initBillView() {
if (requirePermissions(ShopPermission.LIST_USERPRODUCTS) if (requirePermissions(ShopPermission.LIST_USERPRODUCTS) && shoppingcart == null) {
&& shoppingcart == null) {
shoppingcart = new ListDataModel<ProductShopItem>(ProductShopItem.productList(productBean.listUserShoppableProducts(), userView.getSelectedUser())); shoppingcart = new ListDataModel<ProductShopItem>(ProductShopItem.productList(productBean.listUserShoppableProducts(), userView.getSelectedUser()));
for(ProductShopItem item : shoppingcart) {
psiHelper.updateProductShopItemCount(item);
}
updateCartLimits(null); updateCartLimits(null);
logger.debug("Initialized billing shoppingcart to {}", shoppingcart); logger.debug("Initialized billing shoppingcart to {}", shoppingcart);
this.beginConversation(); this.beginConversation();
......
...@@ -24,6 +24,8 @@ import java.util.ArrayList; ...@@ -24,6 +24,8 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import fi.codecrew.moya.model.ProductFlag;
import fi.codecrew.moya.web.helper.ProductShopItemHelper;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -92,10 +94,23 @@ public class ProductShopItem { ...@@ -92,10 +94,23 @@ public class ProductShopItem {
return ret; return ret;
} }
/**
* NOTE: Remember to update count with ProductShopItemHelper afther calling this function
* (this logic really need's to be rewritten)
*
* @param products
* @param user
* @return
*/
public static List<ProductShopItem> productList(List<Product> products, EventUser user) { public static List<ProductShopItem> productList(List<Product> products, EventUser user) {
List<ProductShopItem> ret = new ArrayList<>(); List<ProductShopItem> ret = new ArrayList<>();
for (Product prod : products) { for (Product prod : products) {
ret.add(new ProductShopItem(prod, user)); ProductShopItem i = new ProductShopItem(prod, user);
if(prod.getProductFlags().contains(ProductFlag.USERSHOP_AUTOPRODUCT)) {
i.setCount(BigDecimal.ONE);
}
ret.add(i);
} }
return ret; return ret;
......
...@@ -468,3 +468,6 @@ usercart.showoverview = Vie tarkastusn\u00E4kym\u00E4\u00E4n ...@@ -468,3 +468,6 @@ usercart.showoverview = Vie tarkastusn\u00E4kym\u00E4\u00E4n
viewlectures.title = Kurssit ja luennot viewlectures.title = Kurssit ja luennot
yes = Kyll\u00E4 yes = Kyll\u00E4
productFlag.USERSHOP_AUTOPRODUCT=Tuote lis\u00E4t\u00E4\u00E4n k\u00E4ytt\u00E4j\u00E4n tilaukseen
acc_line.eventuser=
mapView.productcount.productcount=
...@@ -1674,3 +1674,4 @@ voting.create.voteEnd = Voting close ...@@ -1674,3 +1674,4 @@ voting.create.voteEnd = Voting close
voting.create.voteStart = Voting start voting.create.voteStart = Voting start
yes = Yes yes = Yes
productFlag.USERSHOP_AUTOPRODUCT=Product will be added to user order
...@@ -1656,3 +1656,4 @@ voting.create.voteEnd = \u00C4\u00E4nestys kiinni ...@@ -1656,3 +1656,4 @@ voting.create.voteEnd = \u00C4\u00E4nestys kiinni
voting.create.voteStart = \u00C4\u00E4nestys auki voting.create.voteStart = \u00C4\u00E4nestys auki
yes = Kyll\u00E4 yes = Kyll\u00E4
productFlag.USERSHOP_AUTOPRODUCT=Tuote lis\u00E4t\u00E4\u00E4n k\u00E4ytt\u00E4j\u00E4n tilaukseen
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!