Search in sources :

Example 51 with StockMove

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

the class BatchAccountingCutOff method process.

@Override
protected void process() {
    int offset = 0;
    SupplychainBatch supplychainBatch = batch.getSupplychainBatch();
    LocalDate moveDate = supplychainBatch.getMoveDate();
    LocalDate reverseMoveDate = supplychainBatch.getReverseMoveDate();
    boolean recoveredTax = supplychainBatch.getRecoveredTax();
    boolean ati = supplychainBatch.getAti();
    String moveDescription = supplychainBatch.getMoveDescription();
    int accountingCutOffTypeSelect = supplychainBatch.getAccountingCutOffTypeSelect();
    updateBatch(moveDate, accountingCutOffTypeSelect);
    Company company = supplychainBatch.getCompany();
    boolean includeNotStockManagedProduct = supplychainBatch.getIncludeNotStockManagedProduct();
    if (accountingCutOffTypeSelect == 0) {
        return;
    }
    List<StockMove> stockMoveList;
    while (!(stockMoveList = cutOffService.getStockMoves(company, accountingCutOffTypeSelect, moveDate, FETCH_LIMIT, offset)).isEmpty()) {
        findBatch();
        for (StockMove stockMove : stockMoveList) {
            ++offset;
            try {
                List<Move> moveList = cutOffService.generateCutOffMoves(stockMove, moveDate, reverseMoveDate, accountingCutOffTypeSelect, recoveredTax, ati, moveDescription, includeNotStockManagedProduct);
                if (moveList != null && !moveList.isEmpty()) {
                    updateStockMove(stockMove);
                    for (Move move : moveList) {
                        updateAccountMove(move, false);
                    }
                }
            } catch (AxelorException e) {
                TraceBackService.trace(new AxelorException(e, e.getCategory(), I18n.get("StockMove") + " %s", stockMove.getStockMoveSeq()), ExceptionOriginRepository.INVOICE_ORIGIN, batch.getId());
                incrementAnomaly();
                break;
            } catch (Exception e) {
                TraceBackService.trace(new Exception(String.format(I18n.get("StockMove") + " %s", stockMove.getStockMoveSeq()), e), ExceptionOriginRepository.INVOICE_ORIGIN, batch.getId());
                incrementAnomaly();
                LOG.error("Anomaly generated for the stock move {}", stockMove.getStockMoveSeq());
                break;
            }
        }
        JPA.clear();
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) Company(com.axelor.apps.base.db.Company) StockMove(com.axelor.apps.stock.db.StockMove) Move(com.axelor.apps.account.db.Move) StockMove(com.axelor.apps.stock.db.StockMove) SupplychainBatch(com.axelor.apps.supplychain.db.SupplychainBatch) LocalDate(java.time.LocalDate) AxelorException(com.axelor.exception.AxelorException)

Example 52 with StockMove

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

the class LogisticalFormSupplychainServiceImpl method createLogisticalFormLine.

@Override
protected LogisticalFormLine createLogisticalFormLine(LogisticalForm logisticalForm, StockMoveLine stockMoveLine, BigDecimal qty) {
    LogisticalFormLine logisticalFormLine = super.createLogisticalFormLine(logisticalForm, stockMoveLine, qty);
    if (!Beans.get(AppSupplychainService.class).isApp("supplychain")) {
        return logisticalFormLine;
    }
    StockMove stockMove = logisticalFormLine.getStockMoveLine() != null ? logisticalFormLine.getStockMoveLine().getStockMove() : null;
    if (stockMove != null && stockMove.getOriginId() != null && stockMove.getOriginId() != 0 && stockMove.getOriginTypeSelect().equals(StockMoveRepository.ORIGIN_SALE_ORDER)) {
        logisticalFormLine.setSaleOrder(Beans.get(SaleOrderRepository.class).find(stockMove.getOriginId()));
    }
    return logisticalFormLine;
}
Also used : StockMove(com.axelor.apps.stock.db.StockMove) LogisticalFormLine(com.axelor.apps.stock.db.LogisticalFormLine)

Example 53 with StockMove

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

the class ReservedQtyServiceImpl method consolidateReservedQtyInStockMoveLineByProduct.

@Override
public void consolidateReservedQtyInStockMoveLineByProduct(StockMove stockMove) {
    if (stockMove.getStockMoveLineList() == null) {
        return;
    }
    List<Product> productList = stockMove.getStockMoveLineList().stream().map(StockMoveLine::getProduct).filter(Objects::nonNull).filter(Product::getStockManaged).distinct().collect(Collectors.toList());
    for (Product product : productList) {
        if (product != null) {
            List<StockMoveLine> stockMoveLineListToConsolidate = stockMove.getStockMoveLineList().stream().filter(stockMoveLine1 -> product.equals(stockMoveLine1.getProduct())).collect(Collectors.toList());
            if (stockMoveLineListToConsolidate.size() > 1) {
                stockMoveLineListToConsolidate.sort(Comparator.comparing(StockMoveLine::getId));
                BigDecimal reservedQtySum = stockMoveLineListToConsolidate.stream().map(StockMoveLine::getReservedQty).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
                stockMoveLineListToConsolidate.forEach(toConsolidateStockMoveLine -> toConsolidateStockMoveLine.setReservedQty(BigDecimal.ZERO));
                stockMoveLineListToConsolidate.get(0).setReservedQty(reservedQtySum);
            }
        }
    }
}
Also used : Company(com.axelor.apps.base.db.Company) StockLocationRepository(com.axelor.apps.stock.db.repo.StockLocationRepository) StockMoveLineRepository(com.axelor.apps.stock.db.repo.StockMoveLineRepository) IExceptionMessage(com.axelor.apps.supplychain.exception.IExceptionMessage) Inject(com.google.inject.Inject) Transactional(com.google.inject.persist.Transactional) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException) UnitConversionService(com.axelor.apps.base.service.UnitConversionService) StockLocation(com.axelor.apps.stock.db.StockLocation) CancelReason(com.axelor.apps.base.db.CancelReason) I18n(com.axelor.i18n.I18n) StockLocationLineService(com.axelor.apps.stock.service.StockLocationLineService) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) Collectors(java.util.stream.Collectors) SupplyChainConfig(com.axelor.apps.supplychain.db.SupplyChainConfig) Objects(java.util.Objects) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) List(java.util.List) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) Beans(com.axelor.inject.Beans) Product(com.axelor.apps.base.db.Product) Unit(com.axelor.apps.base.db.Unit) Optional(java.util.Optional) AppSupplychainService(com.axelor.apps.supplychain.service.app.AppSupplychainService) Comparator(java.util.Comparator) SupplyChainConfigService(com.axelor.apps.supplychain.service.config.SupplyChainConfigService) Product(com.axelor.apps.base.db.Product) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) BigDecimal(java.math.BigDecimal)

Example 54 with StockMove

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

the class AccountingCutOffServiceImpl method generateCutOffMove.

public Move generateCutOffMove(StockMove stockMove, List<StockMoveLine> sortedStockMoveLine, LocalDate moveDate, LocalDate originDate, boolean isPurchase, boolean recoveredTax, boolean ati, String moveDescription, boolean includeNotStockManagedProduct, boolean isReverse) throws AxelorException {
    if (moveDate == null || stockMove.getOriginTypeSelect() == null || stockMove.getOriginId() == null) {
        return null;
    }
    Company company = stockMove.getCompany();
    AccountConfig accountConfig = accountConfigSupplychainService.getAccountConfig(company);
    Partner partner = stockMove.getPartner();
    Account partnerAccount = null;
    Currency currency = null;
    if (StockMoveRepository.ORIGIN_SALE_ORDER.equals(stockMove.getOriginTypeSelect()) && stockMove.getOriginId() != null) {
        SaleOrder saleOrder = saleOrderRepository.find(stockMove.getOriginId());
        currency = saleOrder.getCurrency();
        if (partner == null) {
            partner = saleOrder.getClientPartner();
        }
        partnerAccount = accountConfigSupplychainService.getForecastedInvCustAccount(accountConfig);
    }
    if (StockMoveRepository.ORIGIN_PURCHASE_ORDER.equals(stockMove.getOriginTypeSelect()) && stockMove.getOriginId() != null) {
        PurchaseOrder purchaseOrder = purchaseOrderRepository.find(stockMove.getOriginId());
        currency = purchaseOrder.getCurrency();
        if (partner == null) {
            partner = purchaseOrder.getSupplierPartner();
        }
        partnerAccount = accountConfigSupplychainService.getForecastedInvSuppAccount(accountConfig);
    }
    String origin = stockMove.getStockMoveSeq();
    Move move = moveCreateService.createMove(accountConfigSupplychainService.getAutoMiscOpeJournal(accountConfig), company, currency, partner, moveDate, null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_CUT_OFF);
    counter = 0;
    this.generateMoveLines(move, stockMove.getStockMoveLineList(), origin, isPurchase, recoveredTax, ati, moveDescription, isReverse, originDate, includeNotStockManagedProduct);
    this.generatePartnerMoveLine(move, origin, partnerAccount, moveDescription, originDate);
    if (move.getMoveLineList() != null && !move.getMoveLineList().isEmpty()) {
        move.setStockMove(stockMove);
        moveValidateService.validate(move);
    } else {
        moveRepository.remove(move);
        return null;
    }
    return move;
}
Also used : Account(com.axelor.apps.account.db.Account) Company(com.axelor.apps.base.db.Company) Move(com.axelor.apps.account.db.Move) StockMove(com.axelor.apps.stock.db.StockMove) Currency(com.axelor.apps.base.db.Currency) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) SaleOrder(com.axelor.apps.sale.db.SaleOrder) Partner(com.axelor.apps.base.db.Partner) AccountConfig(com.axelor.apps.account.db.AccountConfig)

Example 55 with StockMove

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

the class AccountingCutOffServiceImpl method generateCutOffMoves.

@Transactional(rollbackOn = { Exception.class })
public List<Move> generateCutOffMoves(StockMove stockMove, LocalDate moveDate, LocalDate reverseMoveDate, int accountingCutOffTypeSelect, boolean recoveredTax, boolean ati, String moveDescription, boolean includeNotStockManagedProduct) throws AxelorException {
    List<Move> moveList = new ArrayList<>();
    List<StockMoveLine> stockMoveLineSortedList = stockMove.getStockMoveLineList();
    Collections.sort(stockMoveLineSortedList, Comparator.comparing(StockMoveLine::getSequence));
    Move move = generateCutOffMove(stockMove, stockMoveLineSortedList, moveDate, moveDate, accountingCutOffTypeSelect == SupplychainBatchRepository.ACCOUNTING_CUT_OFF_TYPE_SUPPLIER_INVOICES, recoveredTax, ati, moveDescription, includeNotStockManagedProduct, false);
    if (move == null) {
        return null;
    }
    moveList.add(move);
    Move reverseMove = generateCutOffMove(stockMove, stockMoveLineSortedList, reverseMoveDate, moveDate, accountingCutOffTypeSelect == SupplychainBatchRepository.ACCOUNTING_CUT_OFF_TYPE_SUPPLIER_INVOICES, recoveredTax, ati, moveDescription, includeNotStockManagedProduct, true);
    if (reverseMove == null) {
        return null;
    }
    moveList.add(reverseMove);
    reconcile(move, reverseMove);
    return moveList;
}
Also used : Move(com.axelor.apps.account.db.Move) StockMove(com.axelor.apps.stock.db.StockMove) ArrayList(java.util.ArrayList) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Transactional(com.google.inject.persist.Transactional)

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