Search in sources :

Example 1 with StockMoveInvoiceService

use of com.axelor.apps.supplychain.service.StockMoveInvoiceService in project axelor-open-suite by axelor.

the class StockMoveInvoiceController method fillDefaultValueWizard.

public void fillDefaultValueWizard(ActionRequest request, ActionResponse response) {
    try {
        Long id = Long.parseLong(request.getContext().get("_id").toString());
        StockMove stockMove = Beans.get(StockMoveRepository.class).find(id);
        StockMoveInvoiceService stockMoveInvoiceService = Beans.get(StockMoveInvoiceService.class);
        BigDecimal totalInvoicedQty = stockMoveInvoiceService.computeNonCanceledInvoiceQty(stockMove);
        if (totalInvoicedQty.compareTo(BigDecimal.ZERO) == 0) {
            response.setValue("operationSelect", StockMoveRepository.INVOICE_ALL);
        } else {
            response.setValue("operationSelect", StockMoveRepository.INVOICE_PARTIALLY);
            response.setAttr("operationSelect", "selection-in", "[2]");
        }
        List<Map<String, Object>> stockMoveLines = Beans.get(StockMoveInvoiceService.class).getStockMoveLinesToInvoice(stockMove);
        response.setValue("$stockMoveLines", stockMoveLines);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : StockMove(com.axelor.apps.stock.db.StockMove) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository) StockMoveInvoiceService(com.axelor.apps.supplychain.service.StockMoveInvoiceService) Map(java.util.Map) BigDecimal(java.math.BigDecimal)

Example 2 with StockMoveInvoiceService

use of com.axelor.apps.supplychain.service.StockMoveInvoiceService 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)

Aggregations

StockMove (com.axelor.apps.stock.db.StockMove)2 StockMoveInvoiceService (com.axelor.apps.supplychain.service.StockMoveInvoiceService)2 Map (java.util.Map)2 Invoice (com.axelor.apps.account.db.Invoice)1 Company (com.axelor.apps.base.db.Company)1 StockMoveRepository (com.axelor.apps.stock.db.repo.StockMoveRepository)1 SupplyChainConfig (com.axelor.apps.supplychain.db.SupplyChainConfig)1 AppSupplychainService (com.axelor.apps.supplychain.service.app.AppSupplychainService)1 SupplyChainConfigService (com.axelor.apps.supplychain.service.config.SupplyChainConfigService)1 BigDecimal (java.math.BigDecimal)1