use of com.axelor.apps.stock.db.StockMove in project axelor-open-suite by axelor.
the class PurchaseOrderStockServiceImpl method createStockMove.
protected List<Long> createStockMove(PurchaseOrder purchaseOrder, LocalDate estimatedDeliveryDate, List<PurchaseOrderLine> purchaseOrderLineList) throws AxelorException {
List<Long> stockMoveIdList = new ArrayList<>();
Partner supplierPartner = purchaseOrder.getSupplierPartner();
Company company = purchaseOrder.getCompany();
Address address = Beans.get(PartnerService.class).getDeliveryAddress(supplierPartner);
StockLocation startLocation = getStartStockLocation(purchaseOrder);
StockMove stockMove = stockMoveService.createStockMove(address, null, company, supplierPartner, startLocation, purchaseOrder.getStockLocation(), null, estimatedDeliveryDate, purchaseOrder.getNotes(), purchaseOrder.getShipmentMode(), purchaseOrder.getFreightCarrierMode(), null, null, null, StockMoveRepository.TYPE_INCOMING);
StockMove qualityStockMove = stockMoveService.createStockMove(address, null, company, supplierPartner, startLocation, appBaseService.getAppBase().getEnableTradingNamesManagement() ? purchaseOrder.getTradingName().getQualityControlDefaultStockLocation() : company.getStockConfig().getQualityControlDefaultStockLocation(), null, estimatedDeliveryDate, purchaseOrder.getNotes(), purchaseOrder.getShipmentMode(), purchaseOrder.getFreightCarrierMode(), null, null, null, StockMoveRepository.TYPE_INCOMING);
stockMove.setOriginId(purchaseOrder.getId());
stockMove.setOriginTypeSelect(StockMoveRepository.ORIGIN_PURCHASE_ORDER);
stockMove.setOrigin(purchaseOrder.getPurchaseOrderSeq());
stockMove.setTradingName(purchaseOrder.getTradingName());
stockMove.setGroupProductsOnPrintings(purchaseOrder.getGroupProductsOnPrintings());
qualityStockMove.setOriginId(purchaseOrder.getId());
qualityStockMove.setOriginTypeSelect(StockMoveRepository.ORIGIN_PURCHASE_ORDER);
qualityStockMove.setOrigin(purchaseOrder.getPurchaseOrderSeq());
qualityStockMove.setTradingName(purchaseOrder.getTradingName());
qualityStockMove.setGroupProductsOnPrintings(purchaseOrder.getGroupProductsOnPrintings());
SupplyChainConfig supplychainConfig = Beans.get(SupplyChainConfigService.class).getSupplyChainConfig(purchaseOrder.getCompany());
if (supplychainConfig.getDefaultEstimatedDateForPurchaseOrder() == SupplyChainConfigRepository.CURRENT_DATE && stockMove.getEstimatedDate() == null) {
stockMove.setEstimatedDate(appBaseService.getTodayDate(company));
} else if (supplychainConfig.getDefaultEstimatedDateForPurchaseOrder() == SupplyChainConfigRepository.CURRENT_DATE_PLUS_DAYS && stockMove.getEstimatedDate() == null) {
stockMove.setEstimatedDate(appBaseService.getTodayDate(company).plusDays(supplychainConfig.getNumberOfDaysForPurchaseOrder().longValue()));
}
for (PurchaseOrderLine purchaseOrderLine : purchaseOrderLineList) {
BigDecimal qty = purchaseOrderLineServiceSupplychainImpl.computeUndeliveredQty(purchaseOrderLine);
if (qty.signum() > 0 && !existActiveStockMoveForPurchaseOrderLine(purchaseOrderLine)) {
this.createStockMoveLine(stockMove, qualityStockMove, purchaseOrderLine, qty);
}
}
if (stockMove.getStockMoveLineList() != null && !stockMove.getStockMoveLineList().isEmpty()) {
stockMoveService.plan(stockMove);
stockMoveIdList.add(stockMove.getId());
}
if (qualityStockMove.getStockMoveLineList() != null && !qualityStockMove.getStockMoveLineList().isEmpty()) {
stockMoveService.plan(qualityStockMove);
stockMoveIdList.add(qualityStockMove.getId());
}
return stockMoveIdList;
}
use of com.axelor.apps.stock.db.StockMove in project axelor-open-suite by axelor.
the class StockMoveLineSupplychainRepository method populate.
@Override
public Map<String, Object> populate(Map<String, Object> json, Map<String, Object> context) {
Long stockMoveLineId = (Long) json.get("id");
StockMoveLine stockMoveLine = find(stockMoveLineId);
StockMove stockMove = stockMoveLine.getStockMove();
Map<String, Object> stockMoveLineMap = super.populate(json, context);
if (stockMove != null && stockMove.getStatusSelect() == StockMoveRepository.STATUS_REALIZED) {
Beans.get(StockMoveLineServiceSupplychain.class).setInvoiceStatus(stockMoveLine);
json.put("availableStatus", stockMoveLine.getProduct() != null && stockMoveLine.getProduct().getStockManaged() ? stockMoveLine.getAvailableStatus() : null);
json.put("availableStatusSelect", stockMoveLine.getAvailableStatusSelect());
}
return stockMoveLineMap;
}
use of com.axelor.apps.stock.db.StockMove in project axelor-open-suite by axelor.
the class StockMoveSupplychainRepository method copy.
@Override
public StockMove copy(StockMove entity, boolean deep) {
StockMove copy = super.copy(entity, deep);
copy.setInvoiceSet(null);
copy.setOriginTypeSelect(null);
copy.setOrigin(null);
copy.setOriginId(null);
if (copy.getStockMoveLineList() != null) {
for (StockMoveLine stockMoveLine : copy.getStockMoveLineList()) {
stockMoveLine.setReservedQty(BigDecimal.ZERO);
stockMoveLine.setRequestedReservedQty(BigDecimal.ZERO);
stockMoveLine.setIsQtyRequested(false);
stockMoveLine.setReservationDateTime(null);
stockMoveLine.setQtyInvoiced(null);
stockMoveLine.setSaleOrderLine(null);
stockMoveLine.setPurchaseOrderLine(null);
}
}
copy.setInvoicingStatusSelect(StockMoveRepository.STATUS_NOT_INVOICED);
return copy;
}
use of com.axelor.apps.stock.db.StockMove in project axelor-open-suite by axelor.
the class InventoryService method generateStockMove.
/**
* Generate a stock move from an inventory.
*
* @param inventory a realized inventory.
* @param isEnteringStock whether we want to create incoming or upcoming stock move of this
* inventory.
* @return the generated stock move.
* @throws AxelorException
*/
public StockMove generateStockMove(Inventory inventory, boolean isEnteringStock) throws AxelorException {
StockLocation toStockLocation;
StockLocation fromStockLocation;
Company company = inventory.getCompany();
if (isEnteringStock) {
toStockLocation = inventory.getStockLocation();
fromStockLocation = stockConfigService.getInventoryVirtualStockLocation(stockConfigService.getStockConfig(company));
} else {
toStockLocation = stockConfigService.getInventoryVirtualStockLocation(stockConfigService.getStockConfig(company));
fromStockLocation = inventory.getStockLocation();
}
String inventorySeq = inventory.getInventorySeq();
LocalDate inventoryDate = inventory.getPlannedStartDateT().toLocalDate();
LocalDate realDate = inventory.getValidatedOn();
StockMove stockMove = stockMoveService.createStockMove(null, null, company, fromStockLocation, toStockLocation, realDate, inventoryDate, null, StockMoveRepository.TYPE_INTERNAL);
stockMove.setName(inventorySeq);
stockMove.setOriginTypeSelect(StockMoveRepository.ORIGIN_INVENTORY);
stockMove.setOriginId(inventory.getId());
stockMove.setOrigin(inventorySeq);
for (InventoryLine inventoryLine : inventory.getInventoryLineList()) {
generateStockMoveLines(inventoryLine, stockMove, isEnteringStock);
}
if (stockMove.getStockMoveLineList() != null && !stockMove.getStockMoveLineList().isEmpty()) {
stockMoveService.plan(stockMove);
stockMoveService.copyQtyToRealQty(stockMove);
stockMoveService.realize(stockMove, false);
}
return stockMove;
}
use of com.axelor.apps.stock.db.StockMove in project axelor-open-suite by axelor.
the class LogisticalFormServiceImpl method processCollected.
@Override
@Transactional(rollbackOn = { Exception.class })
public void processCollected(LogisticalForm logisticalForm) throws AxelorException {
if (logisticalForm.getLogisticalFormLineList() == null) {
return;
}
Set<StockMove> stockMoveSet = new HashSet<>();
logisticalForm.getLogisticalFormLineList().stream().filter(logisticalFormLine -> logisticalFormLine.getTypeSelect() == LogisticalFormLineRepository.TYPE_DETAIL && logisticalFormLine.getStockMoveLine() != null && logisticalFormLine.getStockMoveLine().getStockMove() != null).forEach(logisticalFormLine -> stockMoveSet.add(logisticalFormLine.getStockMoveLine().getStockMove()));
StockMoveService stockMoveService = Beans.get(StockMoveService.class);
stockMoveSet.forEach(stockMoveService::updateFullySpreadOverLogisticalFormsFlag);
StockConfigService stockConfigService = Beans.get(StockConfigService.class);
StockConfig stockConfig = stockConfigService.getStockConfig(logisticalForm.getCompany());
if (stockConfig.getRealizeStockMovesUponParcelPalletCollection()) {
for (StockMove stockMove : stockMoveSet) {
if (stockMove.getFullySpreadOverLogisticalFormsFlag()) {
stockMoveService.realize(stockMove);
}
}
}
logisticalForm.setStatusSelect(LogisticalFormRepository.STATUS_COLLECTED);
}
Aggregations