Commit e944a90b authored by Matija Obreza's avatar Matija Obreza
Browse files

Merge branch '284-updating-inventory-actions' into 'main'

Resolve "Updating inventory actions"

Closes #284

See merge request grin-global/grin-global-server!372
parents 1df43086 514b2e66
......@@ -26,9 +26,12 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import javax.persistence.EntityManager;
import com.querydsl.core.types.dsl.BooleanExpression;
import org.apache.commons.lang3.StringUtils;
import org.genesys.filerepository.InvalidRepositoryFileDataException;
import org.genesys.filerepository.InvalidRepositoryPathException;
......@@ -83,6 +86,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
......@@ -133,6 +137,12 @@ public class InventoryServiceImpl extends FilteredCRUDServiceImpl<Inventory, Inv
@Autowired
private TemplatingService templatingService;
@Autowired
private InventoryActionService inventoryActionService;
@Autowired
QuerydslPredicateExecutor<InventoryAction> actionFinder;
@Autowired
private EntityManager em;
......@@ -465,6 +475,24 @@ public class InventoryServiceImpl extends FilteredCRUDServiceImpl<Inventory, Inv
}
private void addInventoryAction(Inventory inventory, CodeValueDef actionCodeValue, String note) {
Date nowDate = new Date();
BooleanExpression expression = QInventoryAction.inventoryAction.inventory.id.in(inventory.getId())
.and(QInventoryAction.inventoryAction.completedDate.isNull())
.and(QInventoryAction.inventoryAction.notBeforeDate.isNull().or(QInventoryAction.inventoryAction.notBeforeDate.loe(nowDate)))
.and(QInventoryAction.inventoryAction.actionNameCode.eq(actionCodeValue.value));
var pendingActions = StreamSupport.stream(actionFinder.findAll(expression).spliterator(), false)
.peek(action -> {
action.setCompletedDate(nowDate);
action.setCompletedDateCode(CommunityCodeValues.DATE_FORMAT_DATETIME.value);
if (note != null) {
action.setNote(note);
}
}).collect(Collectors.toList());
var result = inventoryActionService.update(pendingActions);
if (result.success.size() > 0) {
return;
}
InventoryAction quantityAction = new InventoryAction();
quantityAction.setActionNameCode(actionCodeValue.value);
quantityAction.setInventory(inventory);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment