Search in sources :

Example 6 with PurchaseOrderLine

use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.

the class BudgetSupplychainService method updateBudgetLinesFromPurchaseOrder.

public void updateBudgetLinesFromPurchaseOrder(PurchaseOrder purchaseOrder) {
    List<PurchaseOrderLine> purchaseOrderLineList = purchaseOrder.getPurchaseOrderLineList();
    if (purchaseOrderLineList == null) {
        return;
    }
    purchaseOrderLineList.stream().flatMap(x -> x.getBudgetDistributionList().stream()).forEach(budgetDistribution -> {
        Budget budget = budgetDistribution.getBudget();
        updateLines(budget);
        computeTotalAmountCommitted(budget);
    });
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) BudgetLineRepository(com.axelor.apps.account.db.repo.BudgetLineRepository) Budget(com.axelor.apps.account.db.Budget) PurchaseOrderRepository(com.axelor.apps.purchase.db.repo.PurchaseOrderRepository) BudgetDistributionRepository(com.axelor.apps.account.db.repo.BudgetDistributionRepository) Inject(com.google.inject.Inject) Invoice(com.axelor.apps.account.db.Invoice) Transactional(com.google.inject.persist.Transactional) BigDecimal(java.math.BigDecimal) BudgetService(com.axelor.apps.account.service.BudgetService) List(java.util.List) BudgetLine(com.axelor.apps.account.db.BudgetLine) InvoiceRepository(com.axelor.apps.account.db.repo.InvoiceRepository) Beans(com.axelor.inject.Beans) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) BudgetRepository(com.axelor.apps.account.db.repo.BudgetRepository) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) LocalDate(java.time.LocalDate) Optional(java.util.Optional) AppSupplychainService(com.axelor.apps.supplychain.service.app.AppSupplychainService) BudgetDistribution(com.axelor.apps.account.db.BudgetDistribution) DateTool(com.axelor.apps.tool.date.DateTool) Budget(com.axelor.apps.account.db.Budget)

Example 7 with PurchaseOrderLine

use of com.axelor.apps.purchase.db.PurchaseOrderLine 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 8 with PurchaseOrderLine

use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.

the class ProductStockLocationServiceImpl method getPurchaseOrderQty.

protected BigDecimal getPurchaseOrderQty(Product product, Company company, StockLocation stockLocation) throws AxelorException {
    if (product == null || product.getUnit() == null) {
        return BigDecimal.ZERO;
    }
    Long companyId = 0L;
    Long stockLocationId = 0L;
    if (company != null) {
        companyId = company.getId();
    }
    if (stockLocation != null) {
        stockLocationId = stockLocation.getId();
    }
    String query = Beans.get(PurchaseOrderStockService.class).getPurchaseOrderLineListForAProduct(product.getId(), companyId, stockLocationId);
    List<PurchaseOrderLine> purchaseOrderLineList = Beans.get(PurchaseOrderLineRepository.class).all().filter(query).fetch();
    // Compute
    BigDecimal sumPurchaseOrderQty = BigDecimal.ZERO;
    if (!purchaseOrderLineList.isEmpty()) {
        Unit unitConversion = product.getUnit();
        for (PurchaseOrderLine purchaseOrderLine : purchaseOrderLineList) {
            BigDecimal productPurchaseOrderQty = purchaseOrderLine.getQty();
            if (purchaseOrderLine.getReceiptState() == PurchaseOrderLineRepository.RECEIPT_STATE_PARTIALLY_RECEIVED) {
                productPurchaseOrderQty = productPurchaseOrderQty.subtract(purchaseOrderLine.getReceivedQty());
            }
            productPurchaseOrderQty = unitConversionService.convert(purchaseOrderLine.getUnit(), unitConversion, productPurchaseOrderQty, productPurchaseOrderQty.scale(), product);
            sumPurchaseOrderQty = sumPurchaseOrderQty.add(productPurchaseOrderQty);
        }
    }
    return sumPurchaseOrderQty;
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) PurchaseOrderLineRepository(com.axelor.apps.purchase.db.repo.PurchaseOrderLineRepository) Unit(com.axelor.apps.base.db.Unit) BigDecimal(java.math.BigDecimal)

Example 9 with PurchaseOrderLine

use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.

the class PurchaseOrderLineProjectController method updateAnalyticDistributionWithProject.

public void updateAnalyticDistributionWithProject(ActionRequest request, ActionResponse response) throws AxelorException {
    try {
        PurchaseOrderLine purchaseOrderLine = request.getContext().asType(PurchaseOrderLine.class);
        if (purchaseOrderLine.getAnalyticMoveLineList() == null) {
            return;
        }
        purchaseOrderLine = Beans.get(PurchaseOrderLineProjectService.class).updateAnalyticDistributionWithProject(purchaseOrderLine);
        response.setValue("analyticMoveLineList", purchaseOrderLine.getAnalyticMoveLineList());
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) AxelorException(com.axelor.exception.AxelorException)

Example 10 with PurchaseOrderLine

use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.

the class PurchaseOrderLineProjectController method updateToInvoice.

/**
 * Invert value of 'toInvoice' field and save the record
 *
 * @param request
 * @param response
 */
@Transactional
public void updateToInvoice(ActionRequest request, ActionResponse response) {
    PurchaseOrderLineRepository purchaseOrderLineRepository = Beans.get(PurchaseOrderLineRepository.class);
    try {
        PurchaseOrderLine purchaseOrderLine = request.getContext().asType(PurchaseOrderLine.class);
        purchaseOrderLine = purchaseOrderLineRepository.find(purchaseOrderLine.getId());
        purchaseOrderLine.setToInvoice(!purchaseOrderLine.getToInvoice());
        purchaseOrderLineRepository.save(purchaseOrderLine);
        response.setValue("toInvoice", purchaseOrderLine.getToInvoice());
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : PurchaseOrderLineRepository(com.axelor.apps.purchase.db.repo.PurchaseOrderLineRepository) PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) AxelorException(com.axelor.exception.AxelorException) Transactional(com.google.inject.persist.Transactional)

Aggregations

PurchaseOrderLine (com.axelor.apps.purchase.db.PurchaseOrderLine)76 BigDecimal (java.math.BigDecimal)28 PurchaseOrder (com.axelor.apps.purchase.db.PurchaseOrder)26 Transactional (com.google.inject.persist.Transactional)18 Product (com.axelor.apps.base.db.Product)14 ArrayList (java.util.ArrayList)13 AxelorException (com.axelor.exception.AxelorException)11 Context (com.axelor.rpc.Context)10 Company (com.axelor.apps.base.db.Company)9 Unit (com.axelor.apps.base.db.Unit)9 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)9 PurchaseOrderLineService (com.axelor.apps.purchase.service.PurchaseOrderLineService)8 LocalDate (java.time.LocalDate)8 Partner (com.axelor.apps.base.db.Partner)7 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)7 HashMap (java.util.HashMap)7 BudgetDistribution (com.axelor.apps.account.db.BudgetDistribution)5 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)5 TaxLine (com.axelor.apps.account.db.TaxLine)5 List (java.util.List)5