Search in sources :

Example 61 with StockMove

use of com.axelor.apps.stock.db.StockMove in project axelor-open-suite by axelor.

the class StockMoveLineStockRepository 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();
    if (stockMove == null || (stockMove.getFromStockLocation() != null && stockMove.getFromStockLocation().getTypeSelect() == StockLocationRepository.TYPE_VIRTUAL)) {
        return super.populate(json, context);
    }
    if (stockMove.getStatusSelect() < StockMoveRepository.STATUS_REALIZED) {
        Beans.get(StockMoveLineService.class).setAvailableStatus(stockMoveLine);
        json.put("availableStatus", stockMoveLine.getProduct() != null && stockMoveLine.getProduct().getStockManaged() ? stockMoveLine.getAvailableStatus() : null);
        json.put("availableStatusSelect", stockMoveLine.getAvailableStatusSelect());
    }
    return super.populate(json, context);
}
Also used : StockMoveLineService(com.axelor.apps.stock.service.StockMoveLineService) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine)

Example 62 with StockMove

use of com.axelor.apps.stock.db.StockMove in project axelor-open-suite by axelor.

the class StockMoveManagementRepository method populate.

@Override
public Map<String, Object> populate(Map<String, Object> json, Map<String, Object> context) {
    Long stockMoveId = (Long) json.get("id");
    StockMove stockMove = find(stockMoveId);
    if (stockMove.getStatusSelect() > STATUS_PLANNED || stockMove.getStockMoveLineList() == null || (stockMove.getFromStockLocation() != null && stockMove.getFromStockLocation().getTypeSelect() == StockLocationRepository.TYPE_VIRTUAL)) {
        return super.populate(json, context);
    }
    int available = 0, availableForProduct = 0, missing = 0;
    for (StockMoveLine stockMoveLine : stockMove.getStockMoveLineList()) {
        if (stockMoveLine != null && stockMoveLine.getProduct() != null && stockMoveLine.getProduct().getProductTypeSelect() != null && stockMoveLine.getProduct().getProductTypeSelect().equals(ProductRepository.PRODUCT_TYPE_SERVICE)) {
            continue;
        }
        Beans.get(StockMoveLineService.class).updateAvailableQty(stockMoveLine, stockMove.getFromStockLocation());
        Product product = stockMoveLine.getProduct();
        if (stockMoveLine.getAvailableQty().compareTo(stockMoveLine.getRealQty()) >= 0 || product != null && !product.getStockManaged()) {
            available++;
        } else if (stockMoveLine.getAvailableQtyForProduct().compareTo(stockMoveLine.getRealQty()) >= 0) {
            availableForProduct++;
        } else if (stockMoveLine.getAvailableQty().compareTo(stockMoveLine.getRealQty()) < 0 && stockMoveLine.getAvailableQtyForProduct().compareTo(stockMoveLine.getRealQty()) < 0) {
            missing++;
        }
    }
    if ((available > 0 || availableForProduct > 0) && missing == 0) {
        json.put("availableStatusSelect", StockMoveRepository.STATUS_AVAILABLE);
    } else if ((available > 0 || availableForProduct > 0) && missing > 0) {
        json.put("availableStatusSelect", StockMoveRepository.STATUS_PARTIALLY_AVAILABLE);
    } else if (available == 0 && availableForProduct == 0 && missing > 0) {
        json.put("availableStatusSelect", StockMoveRepository.STATUS_UNAVAILABLE);
    }
    return super.populate(json, context);
}
Also used : StockMoveLineService(com.axelor.apps.stock.service.StockMoveLineService) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Product(com.axelor.apps.base.db.Product)

Example 63 with StockMove

use of com.axelor.apps.stock.db.StockMove in project axelor-open-suite by axelor.

the class StockMoveManagementRepository method copy.

@Override
public StockMove copy(StockMove entity, boolean deep) {
    StockMove copy = super.copy(entity, deep);
    copy.setStatusSelect(STATUS_DRAFT);
    copy.setStockMoveSeq(null);
    copy.setName(null);
    copy.setRealDate(null);
    copy.setPickingEditDate(null);
    copy.setPickingIsEdited(false);
    copy.setAvailabilityRequest(false);
    copy.setSupplierShipmentDate(null);
    copy.setSupplierShipmentRef(null);
    copy.setAvailabilityRequest(false);
    copy.setFullySpreadOverLogisticalFormsFlag(false);
    return copy;
}
Also used : StockMove(com.axelor.apps.stock.db.StockMove)

Example 64 with StockMove

use of com.axelor.apps.stock.db.StockMove in project axelor-open-suite by axelor.

the class SaleOrderController method notifyStockMoveCreated.

public void notifyStockMoveCreated(ActionRequest request, ActionResponse response) {
    SaleOrder saleOrder = request.getContext().asType(SaleOrder.class);
    StockMoveRepository stockMoveRepo = Beans.get(StockMoveRepository.class);
    StockMove stockMove = stockMoveRepo.all().filter("self.originTypeSelect = ?1 AND self.originId = ?2 AND self.statusSelect = ?3", "com.axelor.apps.sale.db.SaleOrder", saleOrder.getId(), StockMoveRepository.STATUS_PLANNED).fetchOne();
    if (stockMove != null) {
        response.setNotify(String.format(I18n.get(IExceptionMessage.SALE_ORDER_STOCK_MOVE_CREATED), stockMove.getStockMoveSeq()));
    }
}
Also used : StockMove(com.axelor.apps.stock.db.StockMove) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository) SaleOrder(com.axelor.apps.sale.db.SaleOrder)

Example 65 with StockMove

use of com.axelor.apps.stock.db.StockMove in project axelor-open-suite by axelor.

the class ImportSupplyChain method importPurchaseOrderFromSupplyChain.

@Transactional
public Object importPurchaseOrderFromSupplyChain(Object bean, Map<String, Object> values) {
    try {
        StockMoveService stockMoveService = Beans.get(StockMoveService.class);
        PurchaseOrder purchaseOrder = (PurchaseOrder) bean;
        int status = purchaseOrder.getStatusSelect();
        purchaseOrder = (PurchaseOrder) importPurchaseOrder.importPurchaseOrder(bean, values);
        for (PurchaseOrderLine line : purchaseOrder.getPurchaseOrderLineList()) {
            Product product = line.getProduct();
            if (product.getMassUnit() == null) {
                product.setMassUnit(stockConfigService.getStockConfig(purchaseOrder.getCompany()).getCustomsMassUnit());
            }
        }
        if (status == PurchaseOrderRepository.STATUS_VALIDATED || status == PurchaseOrderRepository.STATUS_FINISHED) {
            purchaseOrderWorkflowService.validatePurchaseOrder(purchaseOrder);
        }
        if (status == PurchaseOrderRepository.STATUS_FINISHED) {
            List<Long> idList = purchaseOrderStockServiceImpl.createStockMoveFromPurchaseOrder(purchaseOrder);
            for (Long id : idList) {
                StockMove stockMove = Beans.get(StockMoveRepository.class).find(id);
                stockMoveService.copyQtyToRealQty(stockMove);
                stockMoveService.realize(stockMove);
                stockMove.setRealDate(purchaseOrder.getDeliveryDate());
            }
            purchaseOrder.setValidationDate(purchaseOrder.getOrderDate());
            purchaseOrder.setValidatedByUser(AuthUtils.getUser());
            purchaseOrder.setSupplierPartner(purchaseOrderService.validateSupplier(purchaseOrder));
            Invoice invoice = Beans.get(PurchaseOrderInvoiceService.class).generateInvoice(purchaseOrder);
            String prefixSupplierSeq = "INV000";
            invoice.setSupplierInvoiceNb(prefixSupplierSeq + purchaseOrder.getImportId());
            invoice.setInternalReference(purchaseOrder.getInternalReference());
            LocalDate date;
            if (purchaseOrder.getValidationDate() != null) {
                date = purchaseOrder.getValidationDate();
            } else {
                date = Beans.get(AppBaseService.class).getTodayDate(purchaseOrder.getCompany());
            }
            invoice.setInvoiceDate(date);
            invoice.setOriginDate(date.minusDays(15));
            invoiceService.validateAndVentilate(invoice);
            purchaseOrderWorkflowService.finishPurchaseOrder(purchaseOrder);
        }
    } catch (Exception e) {
        TraceBackService.trace(e);
    }
    return null;
}
Also used : StockMoveService(com.axelor.apps.stock.service.StockMoveService) StockMove(com.axelor.apps.stock.db.StockMove) Invoice(com.axelor.apps.account.db.Invoice) Product(com.axelor.apps.base.db.Product) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository) LocalDate(java.time.LocalDate) AxelorException(com.axelor.exception.AxelorException) PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) ImportPurchaseOrder(com.axelor.apps.purchase.script.ImportPurchaseOrder) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) PurchaseOrderInvoiceService(com.axelor.apps.supplychain.service.PurchaseOrderInvoiceService) Transactional(com.google.inject.persist.Transactional)

Aggregations

StockMove (com.axelor.apps.stock.db.StockMove)129 AxelorException (com.axelor.exception.AxelorException)57 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)50 ArrayList (java.util.ArrayList)36 StockMoveRepository (com.axelor.apps.stock.db.repo.StockMoveRepository)33 Transactional (com.google.inject.persist.Transactional)32 StockMoveService (com.axelor.apps.stock.service.StockMoveService)31 BigDecimal (java.math.BigDecimal)30 List (java.util.List)25 Company (com.axelor.apps.base.db.Company)23 Map (java.util.Map)21 Product (com.axelor.apps.base.db.Product)19 Invoice (com.axelor.apps.account.db.Invoice)18 StockLocation (com.axelor.apps.stock.db.StockLocation)18 Beans (com.axelor.inject.Beans)17 Optional (java.util.Optional)16 StockMoveLineService (com.axelor.apps.stock.service.StockMoveLineService)15 I18n (com.axelor.i18n.I18n)15 Inject (com.google.inject.Inject)14 HashMap (java.util.HashMap)14