Author: bleny Date: 2013-04-17 15:27:17 +0200 (Wed, 17 Apr 2013) New Revision: 105 Url: http://forge.codelutin.com/projects/franciaflex-magalie/repository/revisions... Log: ask for quantity in kanban when necessary Modified: trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/FulfilKanbanService.java trunk/magalie-web/src/main/java/com/franciaflex/magalie/web/action/FulfilKanbanAction.java trunk/magalie-web/src/main/webapp/WEB-INF/content/fulfil-kanban-input.jsp Modified: trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/FulfilKanbanService.java =================================================================== --- trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/FulfilKanbanService.java 2013-04-17 10:35:44 UTC (rev 104) +++ trunk/magalie-services/src/main/java/com/franciaflex/magalie/services/service/FulfilKanbanService.java 2013-04-17 13:27:17 UTC (rev 105) @@ -12,6 +12,7 @@ import com.franciaflex.magalie.services.MagalieService; import com.franciaflex.magalie.services.MagalieServiceContext; import com.franciaflex.magalie.services.exception.InvalidMagalieBarcodeException; +import com.google.common.base.Preconditions; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -40,29 +41,43 @@ } + public double getDefinedQuantity( + Article article, + Warehouse destinationStore) { + + double quantityInKanban = article.getQuantityInKanban(); + + // TODO brendan 17/04/13 consider destination store + + return quantityInKanban; + + } + public BookArticleResult fulfilKanbanTask( - String articleBarcode, + Article article, MagalieUser magalieUser, - String destinationStoreId) throws InvalidMagalieBarcodeException { + Warehouse destinationStore) { - if (log.isInfoEnabled()) { - log.info(magalieUser + " requested fulfil kanban with barcode " + articleBarcode); - } - MagalieBarcodeService magalieBarcodeService = serviceContext.newService(MagalieBarcodeService.class); - Article article = magalieBarcodeService.getArticle(articleBarcode); - double quantityInKanban = article.getQuantityInKanban(); + Preconditions.checkArgument(quantityInKanban > 0); + + return fulfilKanbanTask(article, magalieUser, destinationStore, quantityInKanban); + + } + + public BookArticleResult fulfilKanbanTask( + Article article, + MagalieUser magalieUser, + Warehouse destinationWarehouse, + double quantityInKanban) { + ArticleStorageService articleStorageService = serviceContext.newService(ArticleStorageService.class); - WarehouseDao warehouseDao = serviceContext.getPersistenceContext().getWarehouseDao(); - - Warehouse destinationWarehouse = warehouseDao.findById(destinationStoreId); - Building building = destinationWarehouse.getBuilding(); Location destinationLocation = getDestinationLocation(destinationWarehouse); @@ -102,4 +117,15 @@ return destinationWarehouses; } + + public Article getArticle(String articleBarcode) throws InvalidMagalieBarcodeException { + + MagalieBarcodeService magalieBarcodeService = + serviceContext.newService(MagalieBarcodeService.class); + + Article article = magalieBarcodeService.getArticle(articleBarcode); + + return article; + + } } Modified: trunk/magalie-web/src/main/java/com/franciaflex/magalie/web/action/FulfilKanbanAction.java =================================================================== --- trunk/magalie-web/src/main/java/com/franciaflex/magalie/web/action/FulfilKanbanAction.java 2013-04-17 10:35:44 UTC (rev 104) +++ trunk/magalie-web/src/main/java/com/franciaflex/magalie/web/action/FulfilKanbanAction.java 2013-04-17 13:27:17 UTC (rev 105) @@ -1,5 +1,6 @@ package com.franciaflex.magalie.web.action; +import com.franciaflex.magalie.persistence.entity.Article; import com.franciaflex.magalie.persistence.entity.Building; import com.franciaflex.magalie.persistence.entity.MagalieUser; import com.franciaflex.magalie.persistence.entity.StorageMovementOrder; @@ -10,6 +11,7 @@ import com.franciaflex.magalie.web.Activity; import com.franciaflex.magalie.web.MagalieActionSupport; import com.franciaflex.magalie.web.MagalieSession; +import com.opensymphony.xwork2.Preparable; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.struts2.convention.annotation.Result; @@ -21,7 +23,7 @@ @Results({ @Result(name="success", type="redirectAction", params = { "actionName", "withdraw-item!input", "storageMovementOrderId", "${storageMovementOrderId}" }) }) -public class FulfilKanbanAction extends MagalieActionSupport { +public class FulfilKanbanAction extends MagalieActionSupport implements Preparable { private static final Log log = LogFactory.getLog(FulfilKanbanAction.class); @@ -37,6 +39,14 @@ protected String destinationWarehouseId; + protected Double quantity; + + protected boolean askQuantity; + + protected Article article; + + protected Warehouse destinationWarehouse; + public void setService(FulfilKanbanService service) { this.service = service; } @@ -46,7 +56,7 @@ } @Override - public String input() { + public void prepare() { session.setActivity(Activity.KANBANS); @@ -64,8 +74,10 @@ } - return INPUT; + } + public boolean isAskQuantity() { + return askQuantity; } public String getDestinationWarehouseId() { @@ -84,6 +96,10 @@ this.destinationWarehouseId = destinationWarehouseId; } + public void setQuantity(Double quantity) { + this.quantity = quantity; + } + @Override public String execute() { @@ -95,16 +111,14 @@ MagalieUser magalieUser = session.getMagalieUser(); - Warehouse destinationWarehouse = service.getStore(destinationWarehouseId); + destinationWarehouse = service.getStore(destinationWarehouseId); // save used destination warehouse to propose it by default on next kanban session.setLastUsedDestinationWarehouseForKanbans(destinationWarehouse); - BookArticleResult bookArticleResult; - try { - bookArticleResult = service.fulfilKanbanTask(articleBarcode, magalieUser, destinationWarehouseId); + article = service.getArticle(articleBarcode); } catch (InvalidMagalieBarcodeException e) { @@ -114,6 +128,31 @@ } + if (quantity == null) { + + double quantityDefined = service.getDefinedQuantity(article, destinationWarehouse); + + if (quantityDefined > 0) { + + quantity = quantityDefined; + + } + + } + + if (quantity == null || ! (quantity > 0.)) { + + askQuantity = true; + + addFieldError("quantity", "Il faut préciser une quantité pour cet article"); + + return INPUT; + + } + + BookArticleResult bookArticleResult = + service.fulfilKanbanTask(article, magalieUser, destinationWarehouse, quantity); + if (bookArticleResult.isArticleUnavailable()) { addActionError("Cet article n'est pas disponible"); @@ -136,6 +175,14 @@ } + public Article getArticle() { + return article; + } + + public String getArticleBarcode() { + return articleBarcode; + } + public String getStorageMovementOrderId() { return storageMovementOrder.getId(); } Modified: trunk/magalie-web/src/main/webapp/WEB-INF/content/fulfil-kanban-input.jsp =================================================================== --- trunk/magalie-web/src/main/webapp/WEB-INF/content/fulfil-kanban-input.jsp 2013-04-17 10:35:44 UTC (rev 104) +++ trunk/magalie-web/src/main/webapp/WEB-INF/content/fulfil-kanban-input.jsp 2013-04-17 13:27:17 UTC (rev 105) @@ -6,7 +6,7 @@ </head> <s:form> - <s:textfield name="articleBarcode" label="Article" inputAppendIcon="barcode" cssClass="input-medium" /> + <s:textfield key="articleBarcode" label="Article" inputAppendIcon="barcode" cssClass="input-medium" /> <s:select label="Magasin destination" key="destinationWarehouseId" @@ -16,6 +16,10 @@ required="true" /> + <s:if test="askQuantity"> + <s:textfield name="quantity" label="Qté" inputAppend="%{article.unit}" cssClass="input-mini" /> + </s:if> + <div class="btn-group"> <s:submit name="next" value="Suivant" cssClass="btn btn-primary" /> </div>