Search in sources :

Example 66 with PurchaseOrderLine

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

the class WorkflowVentilationServiceSupplychainImpl method purchaseOrderLineProcess.

private PurchaseOrder purchaseOrderLineProcess(Invoice invoice, InvoiceLine invoiceLine) throws AxelorException {
    PurchaseOrderLine purchaseOrderLine = invoiceLine.getPurchaseOrderLine();
    if (purchaseOrderLine == null) {
        return null;
    }
    PurchaseOrder purchaseOrder = purchaseOrderLine.getPurchaseOrder();
    BigDecimal invoicedAmountToAdd = invoiceLine.getExTaxTotal();
    // If is it a refund invoice, so we negate the amount invoiced
    if (InvoiceToolService.isRefund(invoiceLine.getInvoice())) {
        invoicedAmountToAdd = invoicedAmountToAdd.negate();
    }
    // Update invoiced amount on purchase order line
    if (!invoice.getCurrency().equals(purchaseOrder.getCurrency()) && purchaseOrderLine.getCompanyExTaxTotal().compareTo(BigDecimal.ZERO) != 0) {
        // If the purchase order currency is different from the invoice currency, use company currency
        // to calculate a rate. This rate will be applied to purchase order line
        BigDecimal currentCompanyInvoicedAmount = invoiceLine.getCompanyExTaxTotal();
        BigDecimal rate = currentCompanyInvoicedAmount.divide(purchaseOrderLine.getCompanyExTaxTotal(), 4, RoundingMode.HALF_UP);
        invoicedAmountToAdd = rate.multiply(purchaseOrderLine.getExTaxTotal());
    }
    purchaseOrderLine.setAmountInvoiced(purchaseOrderLine.getAmountInvoiced().add(invoicedAmountToAdd));
    return purchaseOrder;
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) BigDecimal(java.math.BigDecimal)

Example 67 with PurchaseOrderLine

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

the class ImportPurchaseOrderLine method importPurchaseOrderLine.

public Object importPurchaseOrderLine(Object bean, Map<String, Object> values) throws AxelorException {
    assert bean instanceof PurchaseOrderLine;
    PurchaseOrderLine purchaseOrderLine = (PurchaseOrderLine) bean;
    PurchaseOrderLineService purchaseOrderLineService = Beans.get(PurchaseOrderLineService.class);
    purchaseOrderLineService.compute(purchaseOrderLine, purchaseOrderLine.getPurchaseOrder());
    return purchaseOrderLine;
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) PurchaseOrderLineService(com.axelor.apps.purchase.service.PurchaseOrderLineService)

Example 68 with PurchaseOrderLine

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

the class ABCAnalysisServicePurchaseImpl method createABCAnalysisLine.

@Override
protected Optional<ABCAnalysisLine> createABCAnalysisLine(ABCAnalysis abcAnalysis, Product product) throws AxelorException {
    ABCAnalysisLine abcAnalysisLine = null;
    BigDecimal productQty = BigDecimal.ZERO;
    BigDecimal productWorth = BigDecimal.ZERO;
    List<PurchaseOrderLine> purchaseOrderLineList;
    int offset = 0;
    Query<PurchaseOrderLine> purchaseOrderLineQuery = purchaseOrderLineRepository.all().filter("(self.purchaseOrder.statusSelect = :statusValidated OR self.purchaseOrder.statusSelect = :statusFinished) AND self.purchaseOrder.validationDate >= :startDate AND self.purchaseOrder.validationDate <= :endDate AND self.product.id = :productId").bind("statusValidated", PurchaseOrderRepository.STATUS_VALIDATED).bind("statusFinished", PurchaseOrderRepository.STATUS_FINISHED).bind("startDate", abcAnalysis.getStartDate()).bind("endDate", abcAnalysis.getEndDate()).bind("productId", product.getId()).order("id");
    while (!(purchaseOrderLineList = purchaseOrderLineQuery.fetch(FETCH_LIMIT, offset)).isEmpty()) {
        offset += purchaseOrderLineList.size();
        abcAnalysis = abcAnalysisRepository.find(abcAnalysis.getId());
        if (abcAnalysisLine == null) {
            abcAnalysisLine = super.createABCAnalysisLine(abcAnalysis, product).get();
        }
        for (PurchaseOrderLine purchaseOrderLine : purchaseOrderLineList) {
            BigDecimal convertedQty = unitConversionService.convert(purchaseOrderLine.getUnit(), product.getUnit(), purchaseOrderLine.getQty(), 2, product);
            productQty = productQty.add(convertedQty);
            productWorth = productWorth.add(purchaseOrderLine.getCompanyExTaxTotal());
        }
        super.incTotalQty(productQty);
        super.incTotalWorth(productWorth);
        JPA.clear();
    }
    if (abcAnalysisLine != null) {
        setQtyWorth(abcAnalysisLineRepository.find(abcAnalysisLine.getId()), productQty, productWorth);
    }
    return Optional.ofNullable(abcAnalysisLine);
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) ABCAnalysisLine(com.axelor.apps.base.db.ABCAnalysisLine) BigDecimal(java.math.BigDecimal)

Example 69 with PurchaseOrderLine

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

the class PurchaseOrderLineServiceImpl method createPurchaseOrderLine.

@Override
public PurchaseOrderLine createPurchaseOrderLine(PurchaseOrder purchaseOrder, Product product, String productName, String description, BigDecimal qty, Unit unit) throws AxelorException {
    PurchaseOrderLine purchaseOrderLine = new PurchaseOrderLine();
    purchaseOrderLine.setPurchaseOrder(purchaseOrder);
    purchaseOrderLine.setEstimatedDelivDate(purchaseOrder.getDeliveryDate());
    if (product != null) {
        purchaseOrderLine.setProduct(product);
        fill(purchaseOrderLine, purchaseOrder);
    }
    if (description != null) {
        purchaseOrderLine.setDescription(description);
    }
    purchaseOrderLine.setIsOrdered(false);
    if (qty != null) {
        purchaseOrderLine.setQty(qty);
    }
    purchaseOrderLine.setSequence(sequence);
    sequence++;
    if (unit != null) {
        purchaseOrderLine.setUnit(unit);
    }
    if (productName != null) {
        purchaseOrderLine.setProductName(productName);
    }
    compute(purchaseOrderLine, purchaseOrder);
    return purchaseOrderLine;
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine)

Example 70 with PurchaseOrderLine

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

the class PurchaseOrderSupplierService method createPurchaseOrder.

@Transactional(rollbackOn = { Exception.class })
public void createPurchaseOrder(Partner supplierPartner, List<PurchaseOrderLine> purchaseOrderLineList, PurchaseOrder parentPurchaseOrder) throws AxelorException {
    LOG.debug("Création d'une commande fournisseur depuis le devis fournisseur : {} et le fournisseur : {}", parentPurchaseOrder.getPurchaseOrderSeq(), supplierPartner.getFullName());
    PurchaseOrder purchaseOrder = purchaseOrderSupplychainService.createPurchaseOrder(AuthUtils.getUser(), parentPurchaseOrder.getCompany(), null, supplierPartner.getCurrency(), null, parentPurchaseOrder.getPurchaseOrderSeq(), parentPurchaseOrder.getExternalReference(), Beans.get(StockLocationService.class).getDefaultReceiptStockLocation(parentPurchaseOrder.getCompany()), Beans.get(AppBaseService.class).getTodayDate(parentPurchaseOrder.getCompany()), Beans.get(PartnerPriceListService.class).getDefaultPriceList(supplierPartner, PriceListRepository.TYPE_PURCHASE), supplierPartner, parentPurchaseOrder.getTradingName());
    purchaseOrder.setParentPurchaseOrder(parentPurchaseOrder);
    for (PurchaseOrderLine purchaseOrderLine : purchaseOrderLineList) {
        purchaseOrder.addPurchaseOrderLineListItem(this.createPurchaseOrderLine(purchaseOrder, purchaseOrderLine));
    }
    purchaseOrderService.computePurchaseOrder(purchaseOrder);
    purchaseOrder.setStatusSelect(PurchaseOrderRepository.STATUS_REQUESTED);
    purchaseOrder.setReceiptState(PurchaseOrderRepository.STATE_NOT_RECEIVED);
    poRepo.save(purchaseOrder);
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) 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