Search in sources :

Example 66 with StockMove

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

the class ImportSupplyChain method importSaleOrderFromSupplyChain.

@Transactional
public Object importSaleOrderFromSupplyChain(Object bean, Map<String, Object> values) {
    try {
        SaleOrderWorkflowService saleOrderWorkflowService = Beans.get(SaleOrderWorkflowService.class);
        StockMoveService stockMoveService = Beans.get(StockMoveService.class);
        SaleOrder saleOrder = (SaleOrder) importSaleOrder.importSaleOrder(bean, values);
        for (SaleOrderLine line : saleOrder.getSaleOrderLineList()) {
            Product product = line.getProduct();
            if (product.getMassUnit() == null) {
                product.setMassUnit(stockConfigService.getStockConfig(saleOrder.getCompany()).getCustomsMassUnit());
            }
        }
        if (saleOrder.getStatusSelect() == SaleOrderRepository.STATUS_FINALIZED_QUOTATION) {
            // taskSaleOrderService.createTasks(saleOrder); TODO once we will have done the generation//
            // of tasks in project module
            saleOrderWorkflowService.confirmSaleOrder(saleOrder);
            // Beans.get(SaleOrderPurchaseService.class).createPurchaseOrders(saleOrder);
            // productionOrderSaleOrderService.generateProductionOrder(saleOrder);
            // saleOrder.setClientPartner(saleOrderWorkflowService.validateCustomer(saleOrder));
            // Generate invoice from sale order
            Invoice invoice = Beans.get(SaleOrderInvoiceService.class).generateInvoice(saleOrder);
            if (saleOrder.getConfirmationDateTime() != null) {
                invoice.setInvoiceDate(saleOrder.getConfirmationDateTime().toLocalDate());
            } else {
                invoice.setInvoiceDate(Beans.get(AppBaseService.class).getTodayDate(saleOrder.getCompany()));
            }
            invoiceService.validateAndVentilate(invoice);
            List<Long> idList = saleOrderStockService.createStocksMovesFromSaleOrder(saleOrder);
            for (Long id : idList) {
                StockMove stockMove = Beans.get(StockMoveRepository.class).find(id);
                if (stockMove.getStockMoveLineList() != null && !stockMove.getStockMoveLineList().isEmpty()) {
                    stockMoveService.copyQtyToRealQty(stockMove);
                    stockMoveService.validate(stockMove);
                    if (saleOrder.getConfirmationDateTime() != null) {
                        stockMove.setRealDate(saleOrder.getConfirmationDateTime().toLocalDate());
                    }
                }
            }
        }
        saleOrderRepo.save(saleOrder);
    } catch (Exception e) {
        TraceBackService.trace(e);
    }
    return null;
}
Also used : StockMoveService(com.axelor.apps.stock.service.StockMoveService) Invoice(com.axelor.apps.account.db.Invoice) StockMove(com.axelor.apps.stock.db.StockMove) SaleOrderWorkflowService(com.axelor.apps.sale.service.saleorder.SaleOrderWorkflowService) SaleOrderInvoiceService(com.axelor.apps.supplychain.service.SaleOrderInvoiceService) Product(com.axelor.apps.base.db.Product) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository) SaleOrder(com.axelor.apps.sale.db.SaleOrder) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) AxelorException(com.axelor.exception.AxelorException) Transactional(com.google.inject.persist.Transactional)

Example 67 with StockMove

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

the class StockMoveController method verifyProductStock.

public void verifyProductStock(ActionRequest request, ActionResponse response) {
    try {
        StockMove stockMove = request.getContext().asType(StockMove.class);
        if (stockMove.getPickingIsEdited() && !stockMove.getAvailabilityRequest()) {
            response.setValue("availabilityRequest", true);
            response.setFlash(I18n.get(IExceptionMessage.STOCK_MOVE_AVAILABILITY_REQUEST_NOT_UPDATABLE));
            return;
        }
        Beans.get(StockMoveServiceSupplychain.class).verifyProductStock(stockMove);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
        response.setValue("availabilityRequest", false);
    }
}
Also used : StockMove(com.axelor.apps.stock.db.StockMove) StockMoveServiceSupplychain(com.axelor.apps.supplychain.service.StockMoveServiceSupplychain)

Example 68 with StockMove

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

the class StockMoveInvoiceController method generateInvoiceConcatOutStockMoveCheckMissingFields.

/**
 * Called from mass invoicing out stock move form view. Call method to check for missing fields.
 * If there are missing fields, show a wizard. Else call {@link
 * StockMoveMultiInvoiceService#createInvoiceFromMultiOutgoingStockMove(List)} and show the
 * generated invoice.
 *
 * @param request
 * @param response
 */
public void generateInvoiceConcatOutStockMoveCheckMissingFields(ActionRequest request, ActionResponse response) {
    try {
        List<StockMove> stockMoveList = new ArrayList<>();
        List<Long> stockMoveIdList = new ArrayList<>();
        // No confirmation popup, stock Moves are content in a parameter list
        List<Map> stockMoveMap = (List<Map>) request.getContext().get("customerStockMoveToInvoice");
        for (Map map : stockMoveMap) {
            stockMoveIdList.add(Long.valueOf((Integer) map.get("id")));
        }
        for (Long stockMoveId : stockMoveIdList) {
            stockMoveList.add(JPA.em().find(StockMove.class, stockMoveId));
        }
        Map<String, Object> mapResult = Beans.get(StockMoveMultiInvoiceService.class).areFieldsConflictedToGenerateCustInvoice(stockMoveList);
        boolean paymentConditionToCheck = (Boolean) mapResult.getOrDefault("paymentConditionToCheck", false);
        boolean paymentModeToCheck = (Boolean) mapResult.getOrDefault("paymentModeToCheck", false);
        boolean contactPartnerToCheck = (Boolean) mapResult.getOrDefault("contactPartnerToCheck", false);
        StockMove stockMove = stockMoveList.get(0);
        Partner partner = stockMove.getPartner();
        if (paymentConditionToCheck || paymentModeToCheck || contactPartnerToCheck) {
            ActionViewBuilder confirmView = ActionView.define("StockMove").model(StockMove.class.getName()).add("form", "stock-move-supplychain-concat-cust-invoice-confirm-form").param("popup", "true").param("show-toolbar", "false").param("show-confirm", "false").param("popup-save", "false").param("forceEdit", "true");
            if (paymentConditionToCheck) {
                confirmView.context("contextPaymentConditionToCheck", "true");
            } else {
                confirmView.context("paymentCondition", mapResult.get("paymentCondition"));
            }
            if (paymentModeToCheck) {
                confirmView.context("contextPaymentModeToCheck", "true");
            } else {
                confirmView.context("paymentMode", mapResult.get("paymentMode"));
            }
            if (contactPartnerToCheck) {
                confirmView.context("contextContactPartnerToCheck", "true");
                confirmView.context("contextPartnerId", partner.getId().toString());
            } else {
                confirmView.context("contactPartner", mapResult.get("contactPartner"));
            }
            confirmView.context("customerStockMoveToInvoice", Joiner.on(",").join(stockMoveIdList));
            response.setView(confirmView.map());
        } else {
            Optional<Invoice> invoice = Beans.get(StockMoveMultiInvoiceService.class).createInvoiceFromMultiOutgoingStockMove(stockMoveList);
            invoice.ifPresent(inv -> response.setView(ActionView.define("Invoice").model(Invoice.class.getName()).add("grid", "invoice-grid").add("form", "invoice-form").param("search-filters", "customer-invoices-filters").param("forceEdit", "true").context("_operationTypeSelect", inv.getOperationTypeSelect()).context("todayDate", Beans.get(AppSupplychainService.class).getTodayDate(stockMove.getCompany())).context("_showRecord", String.valueOf(inv.getId())).map()));
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : StockMove(com.axelor.apps.stock.db.StockMove) Invoice(com.axelor.apps.account.db.Invoice) StockMoveMultiInvoiceService(com.axelor.apps.supplychain.service.StockMoveMultiInvoiceService) ArrayList(java.util.ArrayList) ActionViewBuilder(com.axelor.meta.schema.actions.ActionView.ActionViewBuilder) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) Partner(com.axelor.apps.base.db.Partner)

Example 69 with StockMove

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

the class StockMoveInvoiceController method generateMultiCustomerInvoice.

@SuppressWarnings({ "rawtypes", "unchecked" })
public void generateMultiCustomerInvoice(ActionRequest request, ActionResponse response) {
    try {
        List<Map> stockMoveMap = (List<Map>) request.getContext().get("customerStockMoveToInvoice");
        List<Long> stockMoveIdList = new ArrayList<>();
        List<StockMove> stockMoveList = new ArrayList<>();
        for (Map map : stockMoveMap) {
            stockMoveIdList.add(((Number) map.get("id")).longValue());
        }
        for (Long stockMoveId : stockMoveIdList) {
            stockMoveList.add(JPA.em().find(StockMove.class, stockMoveId));
        }
        Beans.get(StockMoveMultiInvoiceService.class).checkForAlreadyInvoicedStockMove(stockMoveList);
        Entry<List<Long>, String> result = Beans.get(StockMoveMultiInvoiceService.class).generateMultipleInvoices(stockMoveIdList);
        List<Long> invoiceIdList = result.getKey();
        String warningMessage = result.getValue();
        if (!invoiceIdList.isEmpty()) {
            ActionViewBuilder viewBuilder;
            viewBuilder = ActionView.define("Cust. Invoices");
            viewBuilder.model(Invoice.class.getName()).add("grid", "invoice-grid").add("form", "invoice-form").param("search-filters", "customer-invoices-filters").domain("self.id IN (" + Joiner.on(",").join(invoiceIdList) + ")").context("_operationTypeSelect", InvoiceRepository.OPERATION_TYPE_CLIENT_SALE).context("todayDate", Beans.get(AppSupplychainService.class).getTodayDate(Optional.ofNullable(AuthUtils.getUser()).map(User::getActiveCompany).orElse(null)));
            response.setView(viewBuilder.map());
        }
        if (warningMessage != null && !warningMessage.isEmpty()) {
            response.setFlash(warningMessage);
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : StockMove(com.axelor.apps.stock.db.StockMove) Invoice(com.axelor.apps.account.db.Invoice) StockMoveMultiInvoiceService(com.axelor.apps.supplychain.service.StockMoveMultiInvoiceService) ArrayList(java.util.ArrayList) ActionViewBuilder(com.axelor.meta.schema.actions.ActionView.ActionViewBuilder) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Example 70 with StockMove

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

the class StockMoveInvoiceController method generateInvoiceConcatOutStockMove.

/**
 * Called from mass invoicing in stock move confirm view. Get parameters entered by the user, then
 * call {@link StockMoveMultiInvoiceService#createInvoiceFromMultiOutgoingStockMove(List,
 * PaymentCondition, PaymentMode, Partner)} and show the generated invoice.
 *
 * @param request
 * @param response
 */
public void generateInvoiceConcatOutStockMove(ActionRequest request, ActionResponse response) {
    try {
        List<StockMove> stockMoveList = new ArrayList<>();
        String stockMoveListStr = (String) request.getContext().get("customerStockMoveToInvoice");
        for (String stockMoveId : stockMoveListStr.split(",")) {
            stockMoveList.add(JPA.em().find(StockMove.class, new Long(stockMoveId)));
        }
        // Check if paymentCondition, paymentMode or contactPartner are content in parameters
        PaymentCondition paymentCondition = null;
        PaymentMode paymentMode = null;
        Partner contactPartner = null;
        // paymentCondition, only for customer stockMove
        if (request.getContext().get("paymentCondition") != null) {
            paymentCondition = JPA.em().find(PaymentCondition.class, Long.valueOf((Integer) ((Map) request.getContext().get("paymentCondition")).get("id")));
        }
        // paymentMode, only for customer stockMove
        if (request.getContext().get("paymentMode") != null) {
            paymentMode = JPA.em().find(PaymentMode.class, Long.valueOf((Integer) ((Map) request.getContext().get("paymentMode")).get("id")));
        }
        if (request.getContext().get("contactPartner") != null) {
            contactPartner = JPA.em().find(Partner.class, Long.valueOf((Integer) ((Map) request.getContext().get("contactPartner")).get("id")));
        }
        Optional<Invoice> invoice = Beans.get(StockMoveMultiInvoiceService.class).createInvoiceFromMultiOutgoingStockMove(stockMoveList, paymentCondition, paymentMode, contactPartner);
        invoice.ifPresent(inv -> response.setView(ActionView.define("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(inv.getId())).context("_operationTypeSelect", inv.getOperationTypeSelect()).context("todayDate", Beans.get(AppSupplychainService.class).getTodayDate(inv.getCompany())).map()));
        response.setCanClose(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : PaymentCondition(com.axelor.apps.account.db.PaymentCondition) StockMove(com.axelor.apps.stock.db.StockMove) Invoice(com.axelor.apps.account.db.Invoice) StockMoveMultiInvoiceService(com.axelor.apps.supplychain.service.StockMoveMultiInvoiceService) ArrayList(java.util.ArrayList) AppSupplychainService(com.axelor.apps.supplychain.service.app.AppSupplychainService) Partner(com.axelor.apps.base.db.Partner) Map(java.util.Map) PaymentMode(com.axelor.apps.account.db.PaymentMode)

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