Search in sources :

Example 86 with StockMove

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

the class BatchOutgoingStockMoveInvoicing method process.

@Override
protected void process() {
    SupplychainBatch supplychainBatch = batch.getSupplychainBatch();
    List<Long> anomalyList = Lists.newArrayList(0L);
    SaleOrderRepository saleRepo = Beans.get(SaleOrderRepository.class);
    TypedQuery<StockMove> query = JPA.em().createQuery("SELECT self FROM StockMove self " + "WHERE self.statusSelect = :statusSelect " + "AND self.originTypeSelect LIKE :typeSaleOrder " + "AND self.invoicingStatusSelect !=  :invoicingStatusSelect " + "AND (SELECT count(invoice.id) FROM Invoice invoice WHERE invoice.statusSelect != :invoiceStatusCanceled AND invoice MEMBER OF self.invoiceSet) = 0" + "AND self.id NOT IN (:anomalyList) " + "AND self.partner.id NOT IN (" + Beans.get(BlockingService.class).listOfBlockedPartner(supplychainBatch.getCompany(), BlockingRepository.INVOICING_BLOCKING) + ") " + "AND :batch NOT MEMBER OF self.batchSet " + "ORDER BY self.id", StockMove.class).setParameter("statusSelect", StockMoveRepository.STATUS_REALIZED).setParameter("typeSaleOrder", StockMoveRepository.ORIGIN_SALE_ORDER).setParameter("invoiceStatusCanceled", InvoiceRepository.STATUS_CANCELED).setParameter("invoicingStatusSelect", StockMoveRepository.STATUS_DELAYED_INVOICE).setParameter("anomalyList", anomalyList).setParameter("batch", batch).setMaxResults(FETCH_LIMIT);
    List<StockMove> stockMoveList;
    while (!(stockMoveList = query.getResultList()).isEmpty()) {
        for (StockMove stockMove : stockMoveList) {
            try {
                stockMoveInvoiceService.createInvoiceFromSaleOrder(stockMove, saleRepo.find(stockMove.getOriginId()), null);
                updateStockMove(stockMove);
            } catch (Exception e) {
                incrementAnomaly();
                anomalyList.add(stockMove.getId());
                query.setParameter("anomalyList", anomalyList);
                TraceBackService.trace(e, ExceptionOriginRepository.INVOICE_ORIGIN, batch.getId());
                break;
            }
        }
        JPA.clear();
    }
}
Also used : StockMove(com.axelor.apps.stock.db.StockMove) SupplychainBatch(com.axelor.apps.supplychain.db.SupplychainBatch) SaleOrderRepository(com.axelor.apps.sale.db.repo.SaleOrderRepository) BlockingService(com.axelor.apps.base.service.BlockingService)

Example 87 with StockMove

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

the class SupplierViewController method getNextDelivery.

public void getNextDelivery(ActionRequest request, ActionResponse response) {
    try {
        SupplierViewService supplierViewService = Beans.get(SupplierViewService.class);
        User user = supplierViewService.getSupplierUser();
        String domain = Beans.get(SupplierViewService.class).getNextDeliveryOfSupplier(user);
        StockMove stockMove = Beans.get(StockMoveRepository.class).all().filter(domain).fetchOne();
        if (stockMove != null) {
            response.setView(ActionView.define(I18n.get("Next delivery")).model(StockMove.class.getName()).add("form", "stock-move-supplier-form").domain(domain).context("_showRecord", stockMove.getId()).map());
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : User(com.axelor.auth.db.User) StockMove(com.axelor.apps.stock.db.StockMove) SupplierViewService(com.axelor.apps.supplierportal.service.SupplierViewService) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository)

Example 88 with StockMove

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

the class SupplierViewServiceImpl method updateSupplierViewIndicators.

@Override
public Map<String, Object> updateSupplierViewIndicators() {
    User user = getSupplierUser();
    Map<String, Object> map = new HashMap<>();
    /* PurchaseOrder */
    map.put("$orders", getCount(PurchaseOrder.class, getPurchaseOrdersOfSupplier(user)));
    map.put("$quotationInProgress", getCount(PurchaseOrder.class, getPurchaseQuotationsInProgressOfSupplier(user)));
    PurchaseOrder lastOrder = getData(PurchaseOrder.class, getLastPurchaseOrderOfSupplier(user));
    map.put("$lastOrder", lastOrder != null ? lastOrder.getValidationDate().format(DATE_FORMATTER) : I18n.get(SUPPLIER_PORTAL_NO_DATE));
    /* StockMove */
    StockMove stockMoveLastDelivery = getData(StockMove.class, getLastDeliveryOfSupplier(user));
    map.put("$lastDelivery", stockMoveLastDelivery != null ? stockMoveLastDelivery.getRealDate().format(DATE_FORMATTER) : I18n.get(SUPPLIER_PORTAL_NO_DATE));
    StockMove stockMoveNextDelivery = getData(StockMove.class, getNextDeliveryOfSupplier(user));
    map.put("$nextDelivery", stockMoveNextDelivery != null ? stockMoveNextDelivery.getEstimatedDate().format(DATE_FORMATTER) : I18n.get(SUPPLIER_PORTAL_NO_DATE));
    map.put("$deliveriesToPrepare", getCount(StockMove.class, getDeliveriesToPrepareOfSupplier(user)));
    /* Invoice */
    map.put("$overdueInvoices", getCount(Invoice.class, getOverdueInvoicesOfSupplier(user)));
    map.put("$awaitingInvoices", getCount(Invoice.class, getAwaitingInvoicesOfSupplier(user)));
    map.put("$totalRemaining", getCount(Invoice.class, getTotalRemainingOfSupplier(user)));
    return map;
}
Also used : User(com.axelor.auth.db.User) StockMove(com.axelor.apps.stock.db.StockMove) Invoice(com.axelor.apps.account.db.Invoice) HashMap(java.util.HashMap) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder)

Example 89 with StockMove

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

the class ManufOrderServiceImpl method updateProducedStockMoveFromManufOrder.

@Override
@Transactional(rollbackOn = { Exception.class })
public void updateProducedStockMoveFromManufOrder(ManufOrder manufOrder) throws AxelorException {
    List<StockMoveLine> producedStockMoveLineList = manufOrder.getProducedStockMoveLineList();
    ManufOrderStockMoveService manufOrderStockMoveService = Beans.get(ManufOrderStockMoveService.class);
    Optional<StockMove> stockMoveOpt = manufOrderStockMoveService.getPlannedStockMove(manufOrder.getOutStockMoveList());
    StockMove stockMove;
    if (stockMoveOpt.isPresent()) {
        stockMove = stockMoveOpt.get();
    } else {
        stockMove = manufOrderStockMoveService._createToProduceStockMove(manufOrder, manufOrder.getCompany());
        manufOrder.addOutStockMoveListItem(stockMove);
        Beans.get(StockMoveService.class).plan(stockMove);
    }
    updateStockMoveFromManufOrder(producedStockMoveLineList, stockMove);
}
Also used : StockMove(com.axelor.apps.stock.db.StockMove) StockMoveService(com.axelor.apps.stock.service.StockMoveService) OperationOrderStockMoveService(com.axelor.apps.production.service.operationorder.OperationOrderStockMoveService) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Transactional(com.google.inject.persist.Transactional)

Example 90 with StockMove

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

the class ManufOrderServiceImpl method generateWasteStockMove.

@Override
@Transactional(rollbackOn = { Exception.class })
public StockMove generateWasteStockMove(ManufOrder manufOrder) throws AxelorException {
    StockMove wasteStockMove = null;
    Company company = manufOrder.getCompany();
    if (manufOrder.getWasteProdProductList() == null || company == null || manufOrder.getWasteProdProductList().isEmpty()) {
        return wasteStockMove;
    }
    StockConfigProductionService stockConfigService = Beans.get(StockConfigProductionService.class);
    StockMoveService stockMoveService = Beans.get(StockMoveService.class);
    StockMoveLineService stockMoveLineService = Beans.get(StockMoveLineService.class);
    AppBaseService appBaseService = Beans.get(AppBaseService.class);
    StockConfig stockConfig = stockConfigService.getStockConfig(company);
    StockLocation virtualStockLocation = stockConfigService.getProductionVirtualStockLocation(stockConfig, false);
    StockLocation wasteStockLocation = stockConfigService.getWasteStockLocation(stockConfig);
    wasteStockMove = stockMoveService.createStockMove(virtualStockLocation.getAddress(), wasteStockLocation.getAddress(), company, virtualStockLocation, wasteStockLocation, null, appBaseService.getTodayDate(company), manufOrder.getWasteProdDescription(), StockMoveRepository.TYPE_INTERNAL);
    for (ProdProduct prodProduct : manufOrder.getWasteProdProductList()) {
        stockMoveLineService.createStockMoveLine(prodProduct.getProduct(), (String) productCompanyService.get(prodProduct.getProduct(), "name", company), (String) productCompanyService.get(prodProduct.getProduct(), "description", company), prodProduct.getQty(), (BigDecimal) productCompanyService.get(prodProduct.getProduct(), "costPrice", company), (BigDecimal) productCompanyService.get(prodProduct.getProduct(), "costPrice", company), prodProduct.getUnit(), wasteStockMove, StockMoveLineService.TYPE_WASTE_PRODUCTIONS, false, BigDecimal.ZERO);
    }
    stockMoveService.validate(wasteStockMove);
    manufOrder.setWasteStockMove(wasteStockMove);
    return wasteStockMove;
}
Also used : StockMoveLineService(com.axelor.apps.stock.service.StockMoveLineService) Company(com.axelor.apps.base.db.Company) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveService(com.axelor.apps.stock.service.StockMoveService) OperationOrderStockMoveService(com.axelor.apps.production.service.operationorder.OperationOrderStockMoveService) StockConfig(com.axelor.apps.stock.db.StockConfig) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) StockLocation(com.axelor.apps.stock.db.StockLocation) StockConfigProductionService(com.axelor.apps.production.service.config.StockConfigProductionService) ProdProduct(com.axelor.apps.production.db.ProdProduct) 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