Search in sources :

Example 36 with StockMove

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

the class StockMoveInvoiceController method openInvoicingWizard.

public void openInvoicingWizard(ActionRequest request, ActionResponse response) {
    try {
        response.setReload(true);
        StockMove stockMove = request.getContext().asType(StockMove.class);
        stockMove = Beans.get(StockMoveRepository.class).find(stockMove.getId());
        StockMoveInvoiceService stockMoveInvoiceService = Beans.get(StockMoveInvoiceService.class);
        List<Map<String, Object>> stockMoveLines = stockMoveInvoiceService.getStockMoveLinesToInvoice(stockMove);
        Company company = stockMove.getCompany();
        SupplyChainConfig supplyChainConfig = Beans.get(SupplyChainConfigService.class).getSupplyChainConfig(company);
        boolean isPartialInvoicingActivated = (stockMove.getTypeSelect() == StockMoveRepository.TYPE_INCOMING && supplyChainConfig.getActivateIncStockMovePartialInvoicing()) || (stockMove.getTypeSelect() == StockMoveRepository.TYPE_OUTGOING && supplyChainConfig.getActivateOutStockMovePartialInvoicing());
        if (isPartialInvoicingActivated && !stockMoveLines.isEmpty()) {
            // open wizard view for partial invoicing
            response.setView(ActionView.define(I18n.get(ITranslation.INVOICING)).model(StockMove.class.getName()).add("form", "stock-move-invoicing-wizard-form").param("popup", "reload").param("show-toolbar", "false").param("show-confirm", "false").param("width", "large").param("popup-save", "false").context("_id", stockMove.getId()).map());
        } else if (!stockMoveLines.isEmpty()) {
            // invoice everything if config is disabled.
            Invoice invoice = stockMoveInvoiceService.createInvoice(stockMove, StockMoveRepository.INVOICE_ALL, null);
            if (invoice != null) {
                response.setView(ActionView.define(I18n.get(ITranslation.INVOICE)).model(Invoice.class.getName()).add("grid", "invoice-grid").add("form", "invoice-form").param("search-filters", "customer-invoices-filters").param("forceEdit", "true").context("_showRecord", String.valueOf(invoice.getId())).context("_operationTypeSelect", invoice.getOperationTypeSelect()).context("todayDate", Beans.get(AppSupplychainService.class).getTodayDate(company)).map());
            }
        } else {
            response.setAlert(I18n.get(IExceptionMessage.STOCK_MOVE_INVOICE_ERROR));
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Company(com.axelor.apps.base.db.Company) StockMove(com.axelor.apps.stock.db.StockMove) Invoice(com.axelor.apps.account.db.Invoice) SupplyChainConfigService(com.axelor.apps.supplychain.service.config.SupplyChainConfigService) SupplyChainConfig(com.axelor.apps.supplychain.db.SupplyChainConfig) StockMoveInvoiceService(com.axelor.apps.supplychain.service.StockMoveInvoiceService) Map(java.util.Map) AppSupplychainService(com.axelor.apps.supplychain.service.app.AppSupplychainService)

Example 37 with StockMove

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

the class StockMoveLineController method compute.

public void compute(ActionRequest request, ActionResponse response) throws AxelorException {
    StockMoveLine stockMoveLine = request.getContext().asType(StockMoveLine.class);
    Optional<StockMove> stockMove = Optional.ofNullable(stockMoveLine.getStockMove());
    if (!stockMove.isPresent()) {
        Context parentContext = request.getContext().getParent();
        if (parentContext.getContextClass().equals(StockMove.class)) {
            stockMove = Optional.ofNullable(parentContext.asType(StockMove.class));
        } else if (parentContext.getContextClass().equals(ManufOrder.class)) {
            ManufOrder manufOrder = parentContext.asType(ManufOrder.class);
            ManufOrderStockMoveService manufOrderStockMoveService = Beans.get(ManufOrderStockMoveService.class);
            stockMove = manufOrderStockMoveService.getPlannedStockMove(manufOrder.getInStockMoveList());
        }
        if (!stockMove.isPresent()) {
            return;
        }
    }
    stockMoveLine = Beans.get(StockMoveLineService.class).compute(stockMoveLine, stockMove.get());
    response.setValue("companyPurchasePrice", stockMoveLine.getCompanyPurchasePrice());
    response.setValue("unitPriceUntaxed", stockMoveLine.getUnitPriceUntaxed());
    response.setValue("unitPriceTaxed", stockMoveLine.getUnitPriceTaxed());
}
Also used : Context(com.axelor.rpc.Context) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) ManufOrderStockMoveService(com.axelor.apps.production.service.manuforder.ManufOrderStockMoveService) ManufOrder(com.axelor.apps.production.db.ManufOrder)

Example 38 with StockMove

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

the class StockMoveLineController method setProductInfo.

/**
 * Called from stock move line form. Fill product info using the company either from the stock
 * move line, from the parent stock move or the parent manuf order.
 *
 * @param request
 * @param response
 */
public void setProductInfo(ActionRequest request, ActionResponse response) {
    StockMoveLine stockMoveLine;
    try {
        stockMoveLine = request.getContext().asType(StockMoveLine.class);
        Company company;
        StockMove stockMove = stockMoveLine.getStockMove();
        if (stockMove == null) {
            Context parentContext = request.getContext().getParent();
            if (parentContext.getContextClass().equals(StockMove.class)) {
                stockMove = parentContext.asType(StockMove.class);
                company = stockMove.getCompany();
            } else if (parentContext.getContextClass().equals(ManufOrder.class)) {
                ManufOrder manufOrder = parentContext.asType(ManufOrder.class);
                company = manufOrder.getCompany();
            } else if (parentContext.getContextClass().equals(OperationOrder.class)) {
                OperationOrder operationOrder = parentContext.asType(OperationOrder.class);
                if (operationOrder.getManufOrder() == null) {
                    return;
                }
                company = operationOrder.getManufOrder().getCompany();
            } else {
                throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, IExceptionMessage.STOCK_MOVE_LINE_UNKNOWN_PARENT_CONTEXT);
            }
        } else {
            company = stockMove.getCompany();
        }
        if (stockMoveLine.getProduct() == null) {
            stockMoveLine = new StockMoveLine();
            response.setValues(Mapper.toMap(stockMoveLine));
            return;
        }
        Beans.get(StockMoveLineService.class).setProductInfo(stockMove, stockMoveLine, company);
        response.setValues(stockMoveLine);
    } catch (Exception e) {
        stockMoveLine = new StockMoveLine();
        response.setValues(Mapper.toMap(stockMoveLine));
        TraceBackService.trace(response, e);
    }
}
Also used : Context(com.axelor.rpc.Context) StockMoveLineService(com.axelor.apps.stock.service.StockMoveLineService) AxelorException(com.axelor.exception.AxelorException) Company(com.axelor.apps.base.db.Company) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) OperationOrder(com.axelor.apps.production.db.OperationOrder) AxelorException(com.axelor.exception.AxelorException) ManufOrder(com.axelor.apps.production.db.ManufOrder)

Example 39 with StockMove

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

the class SupplierViewController method getLastDelivery.

/* StockMove OnClick*/
public void getLastDelivery(ActionRequest request, ActionResponse response) {
    try {
        SupplierViewService supplierViewService = Beans.get(SupplierViewService.class);
        User user = supplierViewService.getSupplierUser();
        String domain = Beans.get(SupplierViewService.class).getLastDeliveryOfSupplier(user);
        StockMove stockMove = Beans.get(StockMoveRepository.class).all().filter(domain).fetchOne();
        if (stockMove != null) {
            response.setView(ActionView.define(I18n.get("Last 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 40 with StockMove

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

the class SaleOrderStockServiceImpl method createStockMove.

protected Optional<StockMove> createStockMove(SaleOrder saleOrder, LocalDate estimatedDeliveryDate, List<SaleOrderLine> saleOrderLineList) throws AxelorException {
    StockMove stockMove = this.createStockMove(saleOrder, saleOrder.getCompany(), estimatedDeliveryDate);
    stockMove.setDeliveryCondition(saleOrder.getDeliveryCondition());
    for (SaleOrderLine saleOrderLine : saleOrderLineList) {
        if (saleOrderLine.getProduct() != null) {
            BigDecimal qty = saleOrderLineServiceSupplyChain.computeUndeliveredQty(saleOrderLine);
            if (qty.signum() > 0 && !existActiveStockMoveForSaleOrderLine(saleOrderLine)) {
                createStockMoveLine(stockMove, saleOrderLine, qty);
            }
        }
    }
    if (stockMove.getStockMoveLineList() == null || stockMove.getStockMoveLineList().isEmpty()) {
        return Optional.empty();
    }
    if (stockMove.getStockMoveLineList().stream().noneMatch(stockMoveLine -> stockMoveLine.getSaleOrderLine() != null && stockMoveLine.getSaleOrderLine().getTypeSelect() == SaleOrderLineRepository.TYPE_NORMAL)) {
        stockMove.setFullySpreadOverLogisticalFormsFlag(true);
    }
    boolean isNeedingConformityCertificate = saleOrder.getIsNeedingConformityCertificate();
    stockMove.setIsNeedingConformityCertificate(isNeedingConformityCertificate);
    if (isNeedingConformityCertificate) {
        stockMove.setSignatoryUser(stockConfigService.getStockConfig(stockMove.getCompany()).getSignatoryUser());
    }
    SupplyChainConfig supplychainConfig = Beans.get(SupplyChainConfigService.class).getSupplyChainConfig(saleOrder.getCompany());
    if (supplychainConfig.getDefaultEstimatedDate() != null && supplychainConfig.getDefaultEstimatedDate() == SupplyChainConfigRepository.CURRENT_DATE && stockMove.getEstimatedDate() == null) {
        stockMove.setEstimatedDate(appBaseService.getTodayDate(saleOrder.getCompany()));
    } else if (supplychainConfig.getDefaultEstimatedDate() == SupplyChainConfigRepository.CURRENT_DATE_PLUS_DAYS && stockMove.getEstimatedDate() == null) {
        stockMove.setEstimatedDate(appBaseService.getTodayDate(saleOrder.getCompany()).plusDays(supplychainConfig.getNumberOfDays().longValue()));
    }
    setReservationDateTime(stockMove, saleOrder);
    stockMoveService.plan(stockMove);
    return Optional.of(stockMove);
}
Also used : StockMove(com.axelor.apps.stock.db.StockMove) SupplyChainConfigService(com.axelor.apps.supplychain.service.config.SupplyChainConfigService) SupplyChainConfig(com.axelor.apps.supplychain.db.SupplyChainConfig) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) BigDecimal(java.math.BigDecimal)

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