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