Search in sources :

Example 31 with StockLocation

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

the class StockLocationStockRepository method populate.

@Override
public Map<String, Object> populate(Map<String, Object> json, Map<String, Object> context) {
    Long stocklocationId = (Long) json.get("id");
    StockLocation stockLocation = find(stocklocationId);
    if (stockLocation.getTypeSelect() == StockLocationRepository.TYPE_VIRTUAL) {
        return super.populate(json, context);
    }
    json.put("stockLocationValue", Beans.get(StockLocationService.class).getStockLocationValue(stockLocation));
    return super.populate(json, context);
}
Also used : StockLocation(com.axelor.apps.stock.db.StockLocation)

Example 32 with StockLocation

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

the class TrackingNumberManagementRepository method populate.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public Map<String, Object> populate(Map<String, Object> json, Map<String, Object> context) {
    try {
        Long trackingNumberId = (Long) json.get("id");
        TrackingNumber trackingNumber = find(trackingNumberId);
        if (trackingNumber.getProduct() != null && context.get("_parent") != null) {
            Map<String, Object> _parent = (Map<String, Object>) context.get("_parent");
            if (_parent.get("fromStockLocation") != null) {
                StockLocation stockLocation = stockLocationRepo.find(Long.parseLong(((Map) _parent.get("fromStockLocation")).get("id").toString()));
                if (stockLocation != null) {
                    BigDecimal availableQty = stockLocationLineService.getTrackingNumberAvailableQty(stockLocation, trackingNumber);
                    json.put("$availableQty", availableQty);
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return super.populate(json, context);
}
Also used : TrackingNumber(com.axelor.apps.stock.db.TrackingNumber) StockLocation(com.axelor.apps.stock.db.StockLocation) Map(java.util.Map) BigDecimal(java.math.BigDecimal)

Example 33 with StockLocation

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

the class PurchaseOrderController method mergePurchaseOrder.

// Generate single purchase order from several
@SuppressWarnings({ "rawtypes", "unchecked" })
public void mergePurchaseOrder(ActionRequest request, ActionResponse response) {
    List<PurchaseOrder> purchaseOrderList = new ArrayList<>();
    List<Long> purchaseOrderIdList = new ArrayList<>();
    boolean fromPopup = false;
    if (request.getContext().get("purchaseOrderToMerge") != null) {
        if (request.getContext().get("purchaseOrderToMerge") instanceof List) {
            // No confirmation popup, purchase orders are content in a parameter list
            List<Map> purchaseOrderMap = (List<Map>) request.getContext().get("purchaseOrderToMerge");
            for (Map map : purchaseOrderMap) {
                purchaseOrderIdList.add(new Long((Integer) map.get("id")));
            }
        } else {
            // After confirmation popup, purchase order's id are in a string separated by
            // ","
            String purchaseOrderIdListStr = (String) request.getContext().get("purchaseOrderToMerge");
            for (String purchaseOrderId : purchaseOrderIdListStr.split(",")) {
                purchaseOrderIdList.add(new Long(purchaseOrderId));
            }
            fromPopup = true;
        }
    }
    // Check if currency, supplierPartner and company are the same for all selected
    // purchase orders
    Currency commonCurrency = null;
    Partner commonSupplierPartner = null;
    Company commonCompany = null;
    Partner commonContactPartner = null;
    TradingName commonTradingName = null;
    // Useful to determine if a difference exists between contact partners of all
    // purchase orders
    boolean existContactPartnerDiff = false;
    PriceList commonPriceList = null;
    // Useful to determine if a difference exists between price lists of all
    // purchase orders
    boolean existPriceListDiff = false;
    StockLocation commonLocation = null;
    // Useful to determine if a difference exists between stock locations of all
    // purchase orders
    boolean existLocationDiff = false;
    boolean allTradingNamesAreNull = true;
    PurchaseOrder purchaseOrderTemp;
    int count = 1;
    for (Long purchaseOrderId : purchaseOrderIdList) {
        purchaseOrderTemp = JPA.em().find(PurchaseOrder.class, purchaseOrderId);
        purchaseOrderList.add(purchaseOrderTemp);
        if (count == 1) {
            commonCurrency = purchaseOrderTemp.getCurrency();
            commonSupplierPartner = purchaseOrderTemp.getSupplierPartner();
            commonCompany = purchaseOrderTemp.getCompany();
            commonContactPartner = purchaseOrderTemp.getContactPartner();
            commonPriceList = purchaseOrderTemp.getPriceList();
            commonLocation = purchaseOrderTemp.getStockLocation();
            commonTradingName = purchaseOrderTemp.getTradingName();
            allTradingNamesAreNull = commonTradingName == null;
        } else {
            if (commonCurrency != null && !commonCurrency.equals(purchaseOrderTemp.getCurrency())) {
                commonCurrency = null;
            }
            if (commonSupplierPartner != null && !commonSupplierPartner.equals(purchaseOrderTemp.getSupplierPartner())) {
                commonSupplierPartner = null;
            }
            if (commonCompany != null && !commonCompany.equals(purchaseOrderTemp.getCompany())) {
                commonCompany = null;
            }
            if (!Objects.equals(commonTradingName, purchaseOrderTemp.getTradingName())) {
                commonTradingName = null;
                allTradingNamesAreNull = false;
            }
            if (commonContactPartner != null && !commonContactPartner.equals(purchaseOrderTemp.getContactPartner())) {
                commonContactPartner = null;
                existContactPartnerDiff = true;
            }
            if (commonPriceList != null && !commonPriceList.equals(purchaseOrderTemp.getPriceList())) {
                commonPriceList = null;
                existPriceListDiff = true;
            }
            if (commonLocation != null && !commonLocation.equals(purchaseOrderTemp.getStockLocation())) {
                commonLocation = null;
                existLocationDiff = true;
            }
        }
        count++;
    }
    StringBuilder fieldErrors = new StringBuilder();
    if (commonCurrency == null) {
        fieldErrors.append(I18n.get(com.axelor.apps.purchase.exception.IExceptionMessage.PURCHASE_ORDER_MERGE_ERROR_CURRENCY));
    }
    if (commonSupplierPartner == null) {
        if (fieldErrors.length() > 0) {
            fieldErrors.append("<br/>");
        }
        fieldErrors.append(I18n.get(com.axelor.apps.purchase.exception.IExceptionMessage.PURCHASE_ORDER_MERGE_ERROR_SUPPLIER_PARTNER));
    }
    if (commonCompany == null) {
        if (fieldErrors.length() > 0) {
            fieldErrors.append("<br/>");
        }
        fieldErrors.append(I18n.get(com.axelor.apps.purchase.exception.IExceptionMessage.PURCHASE_ORDER_MERGE_ERROR_COMPANY));
    }
    if (commonTradingName == null && !allTradingNamesAreNull) {
        fieldErrors.append(I18n.get(com.axelor.apps.purchase.exception.IExceptionMessage.PURCHASE_ORDER_MERGE_ERROR_TRADING_NAME));
    }
    if (fieldErrors.length() > 0) {
        response.setFlash(fieldErrors.toString());
        return;
    }
    // parameters
    if (request.getContext().get("priceList") != null) {
        commonPriceList = JPA.em().find(PriceList.class, new Long((Integer) ((Map) request.getContext().get("priceList")).get("id")));
    }
    if (request.getContext().get("contactPartner") != null) {
        commonContactPartner = JPA.em().find(Partner.class, new Long((Integer) ((Map) request.getContext().get("contactPartner")).get("id")));
    }
    if (request.getContext().get("stockLocation") != null) {
        commonLocation = JPA.em().find(StockLocation.class, new Long((Integer) ((Map) request.getContext().get("stockLocation")).get("id")));
    }
    if (!fromPopup && (existContactPartnerDiff || existPriceListDiff || existLocationDiff)) {
        // Need to display intermediate screen to select some values
        ActionViewBuilder confirmView = ActionView.define("Confirm merge purchase order").model(Wizard.class.getName()).add("form", "purchase-order-merge-confirm-form").param("popup", "true").param("show-toolbar", "false").param("show-confirm", "false").param("popup-save", "false").param("forceEdit", "true");
        if (existPriceListDiff) {
            confirmView.context("contextPriceListToCheck", "true");
        }
        if (existContactPartnerDiff) {
            confirmView.context("contextContactPartnerToCheck", "true");
            confirmView.context("contextPartnerId", commonSupplierPartner.getId().toString());
        }
        if (existLocationDiff) {
            confirmView.context("contextLocationToCheck", "true");
        }
        confirmView.context("purchaseOrderToMerge", Joiner.on(",").join(purchaseOrderIdList));
        response.setView(confirmView.map());
        return;
    }
    try {
        PurchaseOrder purchaseOrder = Beans.get(PurchaseOrderSupplychainService.class).mergePurchaseOrders(purchaseOrderList, commonCurrency, commonSupplierPartner, commonCompany, commonLocation, commonContactPartner, commonPriceList, commonTradingName);
        if (purchaseOrder != null) {
            // Open the generated purchase order in a new tab
            response.setView(ActionView.define("Purchase order").model(PurchaseOrder.class.getName()).add("grid", "purchase-order-grid").add("form", "purchase-order-form").param("search-filters", "purchase-order-filters").param("forceEdit", "true").context("_showRecord", String.valueOf(purchaseOrder.getId())).map());
            response.setCanClose(true);
        }
    } catch (Exception e) {
        response.setFlash(e.getLocalizedMessage());
    }
}
Also used : Company(com.axelor.apps.base.db.Company) StockLocation(com.axelor.apps.stock.db.StockLocation) ArrayList(java.util.ArrayList) PurchaseOrderSupplychainService(com.axelor.apps.supplychain.service.PurchaseOrderSupplychainService) ActionViewBuilder(com.axelor.meta.schema.actions.ActionView.ActionViewBuilder) AxelorException(com.axelor.exception.AxelorException) Currency(com.axelor.apps.base.db.Currency) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) ArrayList(java.util.ArrayList) List(java.util.List) PriceList(com.axelor.apps.base.db.PriceList) TradingName(com.axelor.apps.base.db.TradingName) Map(java.util.Map) Partner(com.axelor.apps.base.db.Partner) PriceList(com.axelor.apps.base.db.PriceList) Wizard(com.axelor.apps.base.db.Wizard)

Example 34 with StockLocation

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

the class SaleOrderStockServiceImpl method createStockMove.

@Override
public StockMove createStockMove(SaleOrder saleOrder, Company company, LocalDate estimatedDeliveryDate) throws AxelorException {
    StockLocation toStockLocation = saleOrder.getToStockLocation();
    if (toStockLocation == null) {
        toStockLocation = partnerStockSettingsService.getDefaultExternalStockLocation(saleOrder.getClientPartner(), company);
    }
    if (toStockLocation == null) {
        toStockLocation = stockConfigService.getCustomerVirtualStockLocation(stockConfigService.getStockConfig(company));
    }
    Partner partner = computePartnerToUseForStockMove(saleOrder);
    StockMove stockMove = stockMoveService.createStockMove(null, saleOrder.getDeliveryAddress(), company, partner, saleOrder.getStockLocation(), toStockLocation, null, estimatedDeliveryDate, saleOrder.getDescription(), saleOrder.getShipmentMode(), saleOrder.getFreightCarrierMode(), saleOrder.getCarrierPartner(), saleOrder.getForwarderPartner(), saleOrder.getIncoterm(), StockMoveRepository.TYPE_OUTGOING);
    stockMove.setToAddressStr(saleOrder.getDeliveryAddressStr());
    stockMove.setOriginId(saleOrder.getId());
    stockMove.setOriginTypeSelect(StockMoveRepository.ORIGIN_SALE_ORDER);
    stockMove.setOrigin(saleOrder.getSaleOrderSeq());
    stockMove.setStockMoveLineList(new ArrayList<>());
    stockMove.setTradingName(saleOrder.getTradingName());
    stockMove.setSpecificPackage(saleOrder.getSpecificPackage());
    stockMove.setNote(saleOrder.getDeliveryComments());
    stockMove.setPickingOrderComments(saleOrder.getPickingOrderComments());
    stockMove.setGroupProductsOnPrintings(partner.getGroupProductsOnPrintings());
    stockMove.setInvoicedPartner(saleOrder.getInvoicedPartner());
    if (stockMove.getPartner() != null) {
        setDefaultAutoMailSettings(stockMove);
    }
    return stockMove;
}
Also used : StockMove(com.axelor.apps.stock.db.StockMove) StockLocation(com.axelor.apps.stock.db.StockLocation) Partner(com.axelor.apps.base.db.Partner)

Example 35 with StockLocation

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

the class FixedAssetServiceSupplyChainImpl method createFixedAssets.

@Transactional
@Override
public List<FixedAsset> createFixedAssets(Invoice invoice) throws AxelorException {
    List<FixedAsset> fixedAssetList = super.createFixedAssets(invoice);
    if (!Beans.get(AppSupplychainService.class).isApp("supplychain")) {
        return fixedAssetList;
    }
    if (fixedAssetList.isEmpty()) {
        return new ArrayList<>();
    }
    StockLocation stockLocation = invoice.getPurchaseOrder() != null ? invoice.getPurchaseOrder().getStockLocation() : null;
    for (FixedAsset fixedAsset : fixedAssetList) {
        PurchaseOrderLine pol = fixedAsset.getInvoiceLine().getPurchaseOrderLine();
        fixedAsset.setStockLocation(stockLocation);
        if (fixedAsset.getInvoiceLine().getIncomingStockMove() != null && CollectionUtils.isNotEmpty(fixedAsset.getInvoiceLine().getIncomingStockMove().getStockMoveLineList())) {
            fixedAsset.setTrackingNumber(fixedAsset.getInvoiceLine().getIncomingStockMove().getStockMoveLineList().stream().filter(l -> pol.equals(l.getPurchaseOrderLine())).findFirst().map(StockMoveLine::getTrackingNumber).orElse(null));
            fixedAsset.setStockLocation(fixedAsset.getInvoiceLine().getIncomingStockMove().getToStockLocation());
        }
    }
    return fixedAssetList;
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) StockLocation(com.axelor.apps.stock.db.StockLocation) ArrayList(java.util.ArrayList) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) FixedAsset(com.axelor.apps.account.db.FixedAsset) Transactional(com.google.inject.persist.Transactional)

Aggregations

StockLocation (com.axelor.apps.stock.db.StockLocation)56 Company (com.axelor.apps.base.db.Company)19 BigDecimal (java.math.BigDecimal)18 Product (com.axelor.apps.base.db.Product)15 AxelorException (com.axelor.exception.AxelorException)13 Transactional (com.google.inject.persist.Transactional)13 StockMove (com.axelor.apps.stock.db.StockMove)12 StockLocationRepository (com.axelor.apps.stock.db.repo.StockLocationRepository)12 ArrayList (java.util.ArrayList)12 StockConfig (com.axelor.apps.stock.db.StockConfig)10 StockConfigProductionService (com.axelor.apps.production.service.config.StockConfigProductionService)9 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)8 StockLocationService (com.axelor.apps.stock.service.StockLocationService)8 List (java.util.List)8 Partner (com.axelor.apps.base.db.Partner)6 Unit (com.axelor.apps.base.db.Unit)6 StockLocationLine (com.axelor.apps.stock.db.StockLocationLine)6 LocalDate (java.time.LocalDate)6 UnitConversionService (com.axelor.apps.base.service.UnitConversionService)5 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)5