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);
}
}
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);
}
}
Aggregations