Search in sources :

Example 76 with StockMove

use of com.axelor.apps.stock.db.StockMove 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 77 with StockMove

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

the class DeclarationOfExchangesExporterServices method exportToCSV.

// TODO: factorize code to parent.
@Override
protected String exportToCSV() throws AxelorException {
    Path path = getFilePath();
    Period period = declarationOfExchanges.getPeriod();
    List<StockMoveLine> stockMoveLines = Beans.get(StockMoveLineRepository.class).findForDeclarationOfExchanges(period.getFromDate(), period.getToDate(), declarationOfExchanges.getProductTypeSelect(), declarationOfExchanges.getStockMoveTypeSelect(), declarationOfExchanges.getCountry(), declarationOfExchanges.getCompany()).fetch();
    List<String[]> dataList = new ArrayList<>(stockMoveLines.size());
    int lineNum = 1;
    for (StockMoveLine stockMoveLine : stockMoveLines) {
        String[] data = new String[columnHeadersList.size()];
        StockMove stockMove = stockMoveLine.getStockMove();
        BigDecimal fiscalValue = stockMoveLine.getUnitPriceUntaxed().multiply(stockMoveLine.getRealQty()).setScale(0, RoundingMode.HALF_UP);
        String taxNbr;
        if (stockMove.getTypeSelect() == StockMoveRepository.TYPE_OUTGOING && stockMoveLine.getRegime() != Regime.OTHER_EXPEDITIONS) {
            if (stockMove.getPartner() == null) {
                taxNbr = String.format(I18n.get("Partner is missing on stock move %s."), stockMove.getName());
            }
            if (StringUtils.isBlank(stockMove.getPartner().getTaxNbr())) {
                taxNbr = String.format(I18n.get("Tax number is missing on partner %s."), stockMove.getPartner().getName());
            }
            taxNbr = stockMove.getPartner().getTaxNbr();
        } else {
            taxNbr = "";
        }
        data[columnHeadersList.indexOf(LINE_NUM)] = String.valueOf(lineNum++);
        data[columnHeadersList.indexOf(FISC_VAL)] = String.valueOf(fiscalValue);
        data[columnHeadersList.indexOf(TAKER)] = taxNbr;
        dataList.add(data);
    }
    try {
        MoreFiles.createParentDirectories(path);
        CsvTool.csvWriter(path.getParent().toString(), path.getFileName().toString(), ';', getTranslatedHeaders(), dataList);
    } catch (IOException e) {
        throw new AxelorException(e, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, e.getLocalizedMessage());
    }
    return attach(path.toString());
}
Also used : Path(java.nio.file.Path) AxelorException(com.axelor.exception.AxelorException) StockMove(com.axelor.apps.stock.db.StockMove) ArrayList(java.util.ArrayList) Period(com.axelor.apps.base.db.Period) IOException(java.io.IOException) BigDecimal(java.math.BigDecimal) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine)

Example 78 with StockMove

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

the class StockMoveServiceSupplychainImpl method setDefaultInvoicedPartner.

@Override
public void setDefaultInvoicedPartner(StockMove stockMove) {
    if (stockMove != null && stockMove.getPartner() != null && stockMove.getPartner().getId() != null) {
        Partner partner = Beans.get(PartnerRepository.class).find(stockMove.getPartner().getId());
        if (partner != null) {
            if (!CollectionUtils.isEmpty(partner.getPartner1SupplychainLinkList())) {
                List<PartnerSupplychainLink> partnerSupplychainLinkList = partner.getPartner1SupplychainLinkList();
                // Retrieve all Invoiced by Type
                List<PartnerSupplychainLink> partnerSupplychainLinkInvoicedByList = partnerSupplychainLinkList.stream().filter(partnerSupplychainLink -> PartnerSupplychainLinkTypeRepository.TYPE_SELECT_INVOICED_BY.equals(partnerSupplychainLink.getPartnerSupplychainLinkType().getTypeSelect())).collect(Collectors.toList());
                // If there is only one, then it is the default one
                if (partnerSupplychainLinkInvoicedByList.size() == 1) {
                    PartnerSupplychainLink partnerSupplychainLinkInvoicedBy = partnerSupplychainLinkInvoicedByList.get(0);
                    stockMove.setInvoicedPartner(partnerSupplychainLinkInvoicedBy.getPartner2());
                } else if (partnerSupplychainLinkInvoicedByList.size() == 0) {
                    stockMove.setInvoicedPartner(partner);
                } else {
                    stockMove.setInvoicedPartner(null);
                }
            } else {
                stockMove.setInvoicedPartner(partner);
            }
        }
    }
}
Also used : PartnerRepository(com.axelor.apps.base.db.repo.PartnerRepository) PartnerProductQualityRatingService(com.axelor.apps.stock.service.PartnerProductQualityRatingService) PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) StockMoveLineRepository(com.axelor.apps.stock.db.repo.StockMoveLineRepository) IExceptionMessage(com.axelor.apps.supplychain.exception.IExceptionMessage) PurchaseOrderRepository(com.axelor.apps.purchase.db.repo.PurchaseOrderRepository) StockMoveToolService(com.axelor.apps.stock.service.StockMoveToolService) PartnerSupplychainLink(com.axelor.apps.supplychain.db.PartnerSupplychainLink) ProductRepository(com.axelor.apps.base.db.repo.ProductRepository) Inject(com.google.inject.Inject) LoggerFactory(org.slf4j.LoggerFactory) Transactional(com.google.inject.persist.Transactional) SaleOrderLineRepository(com.axelor.apps.sale.db.repo.SaleOrderLineRepository) Strings(com.google.common.base.Strings) BigDecimal(java.math.BigDecimal) SaleOrderRepository(com.axelor.apps.sale.db.repo.SaleOrderRepository) AppSupplychain(com.axelor.apps.base.db.AppSupplychain) StockMoveServiceImpl(com.axelor.apps.stock.service.StockMoveServiceImpl) AxelorException(com.axelor.exception.AxelorException) UnitConversionService(com.axelor.apps.base.service.UnitConversionService) CollectionUtils(org.apache.commons.collections.CollectionUtils) I18n(com.axelor.i18n.I18n) SaleOrder(com.axelor.apps.sale.db.SaleOrder) StockMoveLineService(com.axelor.apps.stock.service.StockMoveLineService) PartnerSupplychainLinkTypeRepository(com.axelor.apps.supplychain.db.repo.PartnerSupplychainLinkTypeRepository) JPA(com.axelor.db.JPA) Logger(org.slf4j.Logger) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository) MethodHandles(java.lang.invoke.MethodHandles) PartnerRepository(com.axelor.apps.base.db.repo.PartnerRepository) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) List(java.util.List) Query(javax.persistence.Query) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) Beans(com.axelor.inject.Beans) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) StringJoiner(java.util.StringJoiner) ObjectUtils(com.axelor.common.ObjectUtils) Optional(java.util.Optional) AppSupplychainService(com.axelor.apps.supplychain.service.app.AppSupplychainService) Partner(com.axelor.apps.base.db.Partner) TrackingNumber(com.axelor.apps.stock.db.TrackingNumber) PartnerSupplychainLink(com.axelor.apps.supplychain.db.PartnerSupplychainLink) Partner(com.axelor.apps.base.db.Partner)

Example 79 with StockMove

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

the class StockMoveServiceSupplychainImpl method isAllocatedStockMoveLineRemoved.

@Override
public boolean isAllocatedStockMoveLineRemoved(StockMove stockMove) {
    StockMove storedStockMove = Beans.get(StockMoveRepository.class).find(stockMove.getId());
    Boolean isAllocatedStockMoveLineRemoved = false;
    if (ObjectUtils.notEmpty(storedStockMove)) {
        List<StockMoveLine> stockMoveLineList = stockMove.getStockMoveLineList();
        List<StockMoveLine> storedStockMoveLineList = storedStockMove.getStockMoveLineList();
        if (stockMoveLineList != null && storedStockMoveLineList != null) {
            for (StockMoveLine stockMoveLine : storedStockMoveLineList) {
                if (Beans.get(StockMoveLineServiceSupplychain.class).isAllocatedStockMoveLine(stockMoveLine) && !stockMoveLineList.contains(stockMoveLine)) {
                    stockMoveLineList.add(stockMoveLine);
                    isAllocatedStockMoveLineRemoved = true;
                }
                if (isAllocatedStockMoveLineRemoved) {
                    stockMove.setStockMoveLineList(stockMoveLineList);
                }
            }
        }
    }
    return isAllocatedStockMoveLineRemoved;
}
Also used : StockMove(com.axelor.apps.stock.db.StockMove) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine)

Example 80 with StockMove

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

the class StockMoveLineServiceSupplychainImpl method getMergedStockMoveLine.

@Override
public StockMoveLine getMergedStockMoveLine(List<StockMoveLine> stockMoveLineList) throws AxelorException {
    if (stockMoveLineList == null || stockMoveLineList.isEmpty()) {
        return null;
    }
    if (stockMoveLineList.size() == 1) {
        return stockMoveLineList.get(0);
    }
    StockMove stockMove = stockMoveLineList.get(0).getStockMove();
    SaleOrderLine saleOrderLine = stockMoveLineList.get(0).getSaleOrderLine();
    PurchaseOrderLine purchaseOrderLine = stockMoveLineList.get(0).getPurchaseOrderLine();
    Product product;
    String productName;
    String description;
    BigDecimal quantity = BigDecimal.ZERO;
    Unit unit;
    if (saleOrderLine != null) {
        product = saleOrderLine.getProduct();
        productName = saleOrderLine.getProductName();
        description = saleOrderLine.getDescription();
        unit = saleOrderLine.getUnit();
    } else if (purchaseOrderLine != null) {
        product = purchaseOrderLine.getProduct();
        productName = purchaseOrderLine.getProductName();
        description = purchaseOrderLine.getDescription();
        unit = purchaseOrderLine.getUnit();
    } else {
        // shouldn't ever happen or you misused this function
        return null;
    }
    for (StockMoveLine stockMoveLine : stockMoveLineList) {
        quantity = quantity.add(stockMoveLine.getRealQty());
    }
    StockMoveLine generatedStockMoveLine = createStockMoveLine(product, productName, description, quantity, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, unit, stockMove, null);
    generatedStockMoveLine.setSaleOrderLine(saleOrderLine);
    generatedStockMoveLine.setPurchaseOrderLine(purchaseOrderLine);
    generatedStockMoveLine.setIsMergedStockMoveLine(true);
    return generatedStockMoveLine;
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) StockMove(com.axelor.apps.stock.db.StockMove) Product(com.axelor.apps.base.db.Product) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) Unit(com.axelor.apps.base.db.Unit) BigDecimal(java.math.BigDecimal)

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