Search in sources :

Example 46 with Product

use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.

the class PurchaseOrderStockServiceImpl method needControlOnReceipt.

/**
 * @param product
 * @param purchaseOrder
 * @return true if product needs a control on receipt and if the purchase order is not a direct
 *     order
 */
protected boolean needControlOnReceipt(PurchaseOrderLine purchaseOrderLine) {
    Product product = purchaseOrderLine.getProduct();
    PurchaseOrder purchaseOrder = purchaseOrderLine.getPurchaseOrder();
    if (product.getControlOnReceipt() && !purchaseOrder.getStockLocation().getDirectOrderLocation()) {
        return true;
    }
    return false;
}
Also used : Product(com.axelor.apps.base.db.Product) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder)

Example 47 with Product

use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.

the class PurchaseOrderStockServiceImpl method createProductStockMoveLine.

protected StockMoveLine createProductStockMoveLine(PurchaseOrderLine purchaseOrderLine, BigDecimal qty, StockMove stockMove) throws AxelorException {
    PurchaseOrder purchaseOrder = purchaseOrderLine.getPurchaseOrder();
    Product product = purchaseOrderLine.getProduct();
    Unit unit = product.getUnit();
    BigDecimal priceDiscounted = purchaseOrderLine.getPriceDiscounted();
    BigDecimal companyUnitPriceUntaxed = purchaseOrderLine.getCompanyExTaxTotal();
    if (purchaseOrderLine.getQty().compareTo(BigDecimal.ZERO) != 0) {
        companyUnitPriceUntaxed = purchaseOrderLine.getCompanyExTaxTotal().divide(purchaseOrderLine.getQty(), appBaseService.getNbDecimalDigitForUnitPrice(), RoundingMode.HALF_UP);
    }
    if (unit != null && !unit.equals(purchaseOrderLine.getUnit())) {
        qty = unitConversionService.convert(purchaseOrderLine.getUnit(), unit, qty, qty.scale(), product);
        priceDiscounted = unitConversionService.convert(unit, purchaseOrderLine.getUnit(), priceDiscounted, appBaseService.getNbDecimalDigitForUnitPrice(), product);
        companyUnitPriceUntaxed = unitConversionService.convert(unit, purchaseOrderLine.getUnit(), companyUnitPriceUntaxed, appBaseService.getNbDecimalDigitForUnitPrice(), product);
    }
    BigDecimal shippingCoef = shippingCoefService.getShippingCoef(product, purchaseOrder.getSupplierPartner(), purchaseOrder.getCompany(), qty);
    BigDecimal companyPurchasePrice = priceDiscounted;
    priceDiscounted = priceDiscounted.multiply(shippingCoef);
    companyUnitPriceUntaxed = companyUnitPriceUntaxed.multiply(shippingCoef);
    BigDecimal taxRate = BigDecimal.ZERO;
    TaxLine taxLine = purchaseOrderLine.getTaxLine();
    if (taxLine != null) {
        taxRate = taxLine.getValue();
    }
    if (purchaseOrderLine.getReceiptState() == 0) {
        purchaseOrderLine.setReceiptState(PurchaseOrderLineRepository.RECEIPT_STATE_NOT_RECEIVED);
    }
    return stockMoveLineServiceSupplychain.createStockMoveLine(product, purchaseOrderLine.getProductName(), purchaseOrderLine.getDescription(), qty, BigDecimal.ZERO, priceDiscounted, companyUnitPriceUntaxed, companyPurchasePrice, unit, stockMove, StockMoveLineService.TYPE_PURCHASES, purchaseOrder.getInAti(), taxRate, null, purchaseOrderLine);
}
Also used : PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) Product(com.axelor.apps.base.db.Product) Unit(com.axelor.apps.base.db.Unit) BigDecimal(java.math.BigDecimal) TaxLine(com.axelor.apps.account.db.TaxLine)

Example 48 with Product

use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.

the class AccountingCutOffServiceImpl method getStockMoveLines.

public List<Long> getStockMoveLines(Batch batch) {
    int offset = 0;
    Boolean includeNotStockManagedProduct = batch.getSupplychainBatch().getIncludeNotStockManagedProduct();
    List<StockMoveLine> stockMoveLineList;
    List<Long> stockMoveLineIdList = new ArrayList<>();
    Query<StockMove> stockMoveQuery = stockMoverepository.all().filter(":batch MEMBER OF self.batchSet").bind("batch", batch);
    List<Long> stockMoveIdList = stockMoveQuery.select("id").fetch(0, 0).stream().map(m -> (Long) m.get("id")).collect(Collectors.toList());
    if (stockMoveIdList.isEmpty()) {
        stockMoveLineIdList.add(0L);
    } else {
        Query<StockMoveLine> stockMoveLineQuery = stockMoveLineRepository.all().filter("self.stockMove.id IN :stockMoveIdList").bind("stockMoveIdList", stockMoveIdList).order("id");
        while (!(stockMoveLineList = stockMoveLineQuery.fetch(FETCH_LIMIT, offset)).isEmpty()) {
            offset += stockMoveLineList.size();
            for (StockMoveLine stockMoveLine : stockMoveLineList) {
                Product product = stockMoveLine.getProduct();
                if (!checkStockMoveLine(stockMoveLine, product, includeNotStockManagedProduct)) {
                    stockMoveLineIdList.add(stockMoveLine.getId());
                }
            }
            JPA.clear();
        }
    }
    return stockMoveLineIdList;
}
Also used : TaxAccountService(com.axelor.apps.account.service.TaxAccountService) AppAccountService(com.axelor.apps.account.service.app.AppAccountService) Move(com.axelor.apps.account.db.Move) Inject(com.google.inject.Inject) Transactional(com.google.inject.persist.Transactional) BigDecimal(java.math.BigDecimal) SaleOrderRepository(com.axelor.apps.sale.db.repo.SaleOrderRepository) TaxLine(com.axelor.apps.account.db.TaxLine) MoveCreateService(com.axelor.apps.account.service.move.MoveCreateService) MoveToolService(com.axelor.apps.account.service.move.MoveToolService) MoveValidateService(com.axelor.apps.account.service.move.MoveValidateService) SaleOrder(com.axelor.apps.sale.db.SaleOrder) RoundingMode(java.math.RoundingMode) AnalyticMoveLineRepository(com.axelor.apps.account.db.repo.AnalyticMoveLineRepository) AccountManagementAccountService(com.axelor.apps.account.service.AccountManagementAccountService) InvoiceLineManagement(com.axelor.apps.account.service.invoice.generator.line.InvoiceLineManagement) FETCH_LIMIT(com.axelor.apps.base.service.administration.AbstractBatch.FETCH_LIMIT) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository) Collectors(java.util.stream.Collectors) Currency(com.axelor.apps.base.db.Currency) List(java.util.List) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) Product(com.axelor.apps.base.db.Product) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) AccountConfigSupplychainService(com.axelor.apps.supplychain.service.config.AccountConfigSupplychainService) LocalDate(java.time.LocalDate) Partner(com.axelor.apps.base.db.Partner) Company(com.axelor.apps.base.db.Company) Query(com.axelor.db.Query) PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) StockMoveLineRepository(com.axelor.apps.stock.db.repo.StockMoveLineRepository) AccountConfig(com.axelor.apps.account.db.AccountConfig) PurchaseOrderRepository(com.axelor.apps.purchase.db.repo.PurchaseOrderRepository) AnalyticMoveLineService(com.axelor.apps.account.service.AnalyticMoveLineService) ArrayList(java.util.ArrayList) AxelorException(com.axelor.exception.AxelorException) MoveLine(com.axelor.apps.account.db.MoveLine) UnitConversionService(com.axelor.apps.base.service.UnitConversionService) Batch(com.axelor.apps.base.db.Batch) AppAccountRepository(com.axelor.apps.base.db.repo.AppAccountRepository) MoveLineService(com.axelor.apps.account.service.move.MoveLineService) JPA(com.axelor.db.JPA) Iterator(java.util.Iterator) SupplychainBatchRepository(com.axelor.apps.supplychain.db.repo.SupplychainBatchRepository) ReconcileService(com.axelor.apps.account.service.ReconcileService) AnalyticDistributionTemplate(com.axelor.apps.account.db.AnalyticDistributionTemplate) Account(com.axelor.apps.account.db.Account) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Comparator(java.util.Comparator) Collections(java.util.Collections) MoveRepository(com.axelor.apps.account.db.repo.MoveRepository) AnalyticMoveLine(com.axelor.apps.account.db.AnalyticMoveLine) Tax(com.axelor.apps.account.db.Tax) StockMove(com.axelor.apps.stock.db.StockMove) ArrayList(java.util.ArrayList) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Product(com.axelor.apps.base.db.Product)

Example 49 with Product

use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.

the class AccountingCutOffServiceImpl method generateProductMoveLine.

protected MoveLine generateProductMoveLine(Move move, StockMoveLine stockMoveLine, String origin, boolean isPurchase, boolean recoveredTax, boolean ati, String moveDescription, boolean isReverse, LocalDate originDate) throws AxelorException {
    SaleOrderLine saleOrderLine = stockMoveLine.getSaleOrderLine();
    PurchaseOrderLine purchaseOrderLine = stockMoveLine.getPurchaseOrderLine();
    Company company = move.getCompany();
    LocalDate moveDate = move.getDate();
    Partner partner = move.getPartner();
    boolean isFixedAssets = false;
    BigDecimal amountInCurrency = null;
    BigDecimal totalQty = null;
    BigDecimal notInvoicedQty = null;
    if (isPurchase && purchaseOrderLine != null) {
        totalQty = purchaseOrderLine.getQty();
        notInvoicedQty = unitConversionService.convert(stockMoveLine.getUnit(), purchaseOrderLine.getUnit(), stockMoveLine.getRealQty().subtract(stockMoveLine.getQtyInvoiced()), stockMoveLine.getRealQty().scale(), purchaseOrderLine.getProduct());
        isFixedAssets = purchaseOrderLine.getFixedAssets();
        if (ati && !recoveredTax) {
            amountInCurrency = purchaseOrderLine.getInTaxTotal();
        } else {
            amountInCurrency = purchaseOrderLine.getExTaxTotal();
        }
    }
    if (!isPurchase && saleOrderLine != null) {
        totalQty = saleOrderLine.getQty();
        notInvoicedQty = unitConversionService.convert(stockMoveLine.getUnit(), saleOrderLine.getUnit(), stockMoveLine.getRealQty().subtract(stockMoveLine.getQtyInvoiced()), stockMoveLine.getRealQty().scale(), saleOrderLine.getProduct());
        if (ati) {
            amountInCurrency = saleOrderLine.getInTaxTotal();
        } else {
            amountInCurrency = saleOrderLine.getExTaxTotal();
        }
    }
    if (totalQty == null || BigDecimal.ZERO.compareTo(totalQty) == 0) {
        return null;
    }
    BigDecimal qtyRate = notInvoicedQty.divide(totalQty, 10, RoundingMode.HALF_UP);
    amountInCurrency = amountInCurrency.multiply(qtyRate).setScale(2, RoundingMode.HALF_UP);
    if (amountInCurrency == null || amountInCurrency.compareTo(BigDecimal.ZERO) == 0) {
        return null;
    }
    Product product = stockMoveLine.getProduct();
    Account account = accountManagementAccountService.getProductAccount(product, company, partner.getFiscalPosition(), isPurchase, isFixedAssets);
    boolean isDebit = false;
    if ((isPurchase && amountInCurrency.compareTo(BigDecimal.ZERO) == 1) || !isPurchase && amountInCurrency.compareTo(BigDecimal.ZERO) == -1) {
        isDebit = true;
    }
    if (isReverse) {
        isDebit = !isDebit;
    }
    MoveLine moveLine = moveLineService.createMoveLine(move, partner, account, amountInCurrency, isDebit, originDate, ++counter, origin, moveDescription);
    moveLine.setDate(moveDate);
    moveLine.setDueDate(moveDate);
    getAndComputeAnalyticDistribution(product, move, moveLine);
    move.addMoveLineListItem(moveLine);
    if (recoveredTax) {
        TaxLine taxLine = accountManagementAccountService.getTaxLine(originDate, product, company, partner.getFiscalPosition(), isPurchase);
        if (taxLine != null) {
            moveLine.setTaxLine(taxLine);
            moveLine.setTaxRate(taxLine.getValue());
            moveLine.setTaxCode(taxLine.getTax().getCode());
            if (taxLine.getValue().compareTo(BigDecimal.ZERO) != 0) {
                generateTaxMoveLine(move, moveLine, origin, isPurchase, isFixedAssets, moveDescription);
            }
        }
    }
    return moveLine;
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) Account(com.axelor.apps.account.db.Account) Company(com.axelor.apps.base.db.Company) MoveLine(com.axelor.apps.account.db.MoveLine) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) AnalyticMoveLine(com.axelor.apps.account.db.AnalyticMoveLine) Product(com.axelor.apps.base.db.Product) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) LocalDate(java.time.LocalDate) Partner(com.axelor.apps.base.db.Partner) BigDecimal(java.math.BigDecimal) TaxLine(com.axelor.apps.account.db.TaxLine)

Example 50 with Product

use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.

the class ProductStockLocationServiceImpl method computeIndicators.

@Override
public Map<String, Object> computeIndicators(Long productId, Long companyId, Long stockLocationId) throws AxelorException {
    Map<String, Object> map = new HashMap<>();
    Product product = productRepository.find(productId);
    Company company = companyRepository.find(companyId);
    StockLocation stockLocation = stockLocationRepository.find(stockLocationId);
    int scale = appBaseService.getNbDecimalDigitForQty();
    if (stockLocationId != 0L && companyId != 0L) {
        List<StockLocation> stockLocationList = stockLocationService.getAllLocationAndSubLocation(stockLocation, false);
        if (!stockLocationList.isEmpty()) {
            BigDecimal realQty = BigDecimal.ZERO;
            BigDecimal futureQty = BigDecimal.ZERO;
            BigDecimal reservedQty = BigDecimal.ZERO;
            BigDecimal requestedReservedQty = BigDecimal.ZERO;
            BigDecimal saleOrderQty = BigDecimal.ZERO;
            BigDecimal purchaseOrderQty = BigDecimal.ZERO;
            BigDecimal availableQty = BigDecimal.ZERO;
            saleOrderQty = this.getSaleOrderQty(product, company, stockLocation);
            purchaseOrderQty = this.getPurchaseOrderQty(product, company, stockLocation);
            availableQty = this.getAvailableQty(product, company, stockLocation);
            requestedReservedQty = this.getRequestedReservedQty(product, company, stockLocation);
            for (StockLocation sl : stockLocationList) {
                realQty = realQty.add(stockLocationService.getRealQty(productId, sl.getId(), companyId));
                futureQty = futureQty.add(stockLocationService.getFutureQty(productId, sl.getId(), companyId));
                reservedQty = reservedQty.add(stockLocationServiceSupplychain.getReservedQty(productId, sl.getId(), companyId));
            }
            map.put("$realQty", realQty.setScale(scale, RoundingMode.HALF_UP));
            map.put("$futureQty", futureQty.setScale(scale, RoundingMode.HALF_UP));
            map.put("$reservedQty", reservedQty.setScale(scale, RoundingMode.HALF_UP));
            map.put("$requestedReservedQty", requestedReservedQty.setScale(scale, RoundingMode.HALF_UP));
            map.put("$saleOrderQty", saleOrderQty.setScale(scale, RoundingMode.HALF_UP));
            map.put("$purchaseOrderQty", purchaseOrderQty.setScale(scale, RoundingMode.HALF_UP));
            map.put("$availableQty", availableQty.subtract(reservedQty).setScale(scale, RoundingMode.HALF_UP));
            return map;
        }
    }
    BigDecimal reservedQty = stockLocationServiceSupplychain.getReservedQty(productId, stockLocationId, companyId).setScale(scale, RoundingMode.HALF_UP);
    map.put("$realQty", stockLocationService.getRealQty(productId, stockLocationId, companyId).setScale(scale, RoundingMode.HALF_UP));
    map.put("$futureQty", stockLocationService.getFutureQty(productId, stockLocationId, companyId).setScale(scale, RoundingMode.HALF_UP));
    map.put("$reservedQty", reservedQty);
    map.put("$requestedReservedQty", this.getRequestedReservedQty(product, company, null).setScale(scale, RoundingMode.HALF_UP));
    map.put("$saleOrderQty", this.getSaleOrderQty(product, company, null).setScale(scale, RoundingMode.HALF_UP));
    map.put("$purchaseOrderQty", this.getPurchaseOrderQty(product, company, null).setScale(scale, RoundingMode.HALF_UP));
    map.put("$availableQty", this.getAvailableQty(product, company, null).subtract(reservedQty).setScale(scale, RoundingMode.HALF_UP));
    return map;
}
Also used : Company(com.axelor.apps.base.db.Company) HashMap(java.util.HashMap) StockLocation(com.axelor.apps.stock.db.StockLocation) Product(com.axelor.apps.base.db.Product) BigDecimal(java.math.BigDecimal)

Aggregations

Product (com.axelor.apps.base.db.Product)189 BigDecimal (java.math.BigDecimal)91 AxelorException (com.axelor.exception.AxelorException)70 Transactional (com.google.inject.persist.Transactional)45 ArrayList (java.util.ArrayList)38 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)33 Company (com.axelor.apps.base.db.Company)24 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)24 Unit (com.axelor.apps.base.db.Unit)23 ProductRepository (com.axelor.apps.base.db.repo.ProductRepository)23 HashMap (java.util.HashMap)20 BillOfMaterial (com.axelor.apps.production.db.BillOfMaterial)19 StockLocation (com.axelor.apps.stock.db.StockLocation)19 List (java.util.List)19 ProdProduct (com.axelor.apps.production.db.ProdProduct)18 StockLocationLine (com.axelor.apps.stock.db.StockLocationLine)18 LocalDate (java.time.LocalDate)18 PurchaseOrderLine (com.axelor.apps.purchase.db.PurchaseOrderLine)16 StockMove (com.axelor.apps.stock.db.StockMove)16 Map (java.util.Map)16