Search in sources :

Example 31 with PurchaseOrderLine

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

the class WorkflowCancelServiceSupplychainImpl method purchaseOrderLineProcess.

public 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().subtract(invoicedAmountToAdd));
    return purchaseOrder;
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) BigDecimal(java.math.BigDecimal)

Example 32 with PurchaseOrderLine

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

the class StockMoveServiceSupplychainImpl method updatePurchaseOrderLines.

protected void updatePurchaseOrderLines(StockMove stockMove, boolean qtyWasReceived) throws AxelorException {
    for (StockMoveLine stockMoveLine : stockMove.getStockMoveLineList()) {
        if (stockMoveLine.getPurchaseOrderLine() != null) {
            PurchaseOrderLine purchaseOrderLine = stockMoveLine.getPurchaseOrderLine();
            BigDecimal realQty = unitConversionService.convert(stockMoveLine.getUnit(), purchaseOrderLine.getUnit(), stockMoveLine.getRealQty(), stockMoveLine.getRealQty().scale(), purchaseOrderLine.getProduct());
            if (qtyWasReceived) {
                purchaseOrderLine.setReceivedQty(purchaseOrderLine.getReceivedQty().add(realQty));
            } else {
                purchaseOrderLine.setReceivedQty(purchaseOrderLine.getReceivedQty().subtract(realQty));
            }
            if (purchaseOrderLine.getReceivedQty().signum() == 0) {
                purchaseOrderLine.setReceiptState(PurchaseOrderRepository.STATE_NOT_RECEIVED);
            } else if (purchaseOrderLine.getReceivedQty().compareTo(purchaseOrderLine.getQty()) < 0) {
                purchaseOrderLine.setReceiptState(PurchaseOrderRepository.STATE_PARTIALLY_RECEIVED);
            } else {
                purchaseOrderLine.setReceiptState(PurchaseOrderRepository.STATE_RECEIVED);
            }
        }
    }
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) BigDecimal(java.math.BigDecimal)

Example 33 with PurchaseOrderLine

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

the class IntercoServiceImpl method generateIntercoSaleFromPurchase.

@Override
@Transactional(rollbackOn = { Exception.class })
public SaleOrder generateIntercoSaleFromPurchase(PurchaseOrder purchaseOrder) throws AxelorException {
    SaleOrderCreateService saleOrderCreateService = Beans.get(SaleOrderCreateService.class);
    SaleOrderComputeService saleOrderComputeService = Beans.get(SaleOrderComputeService.class);
    Company intercoCompany = findIntercoCompany(purchaseOrder.getSupplierPartner());
    // create sale order
    SaleOrder saleOrder = saleOrderCreateService.createSaleOrder(null, intercoCompany, purchaseOrder.getContactPartner(), purchaseOrder.getCurrency(), purchaseOrder.getDeliveryDate(), null, null, purchaseOrder.getPriceList(), purchaseOrder.getCompany().getPartner(), null);
    // in ati
    saleOrder.setInAti(purchaseOrder.getInAti());
    // copy date
    saleOrder.setOrderDate(purchaseOrder.getOrderDate());
    // copy payments
    PaymentMode intercoPaymentMode = Beans.get(PaymentModeService.class).reverseInOut(purchaseOrder.getPaymentMode());
    saleOrder.setPaymentMode(intercoPaymentMode);
    saleOrder.setPaymentCondition(purchaseOrder.getPaymentCondition());
    // copy delivery info
    saleOrder.setDeliveryDate(purchaseOrder.getDeliveryDate());
    saleOrder.setShipmentMode(purchaseOrder.getShipmentMode());
    saleOrder.setFreightCarrierMode(purchaseOrder.getFreightCarrierMode());
    // get stock location
    saleOrder.setStockLocation(Beans.get(StockLocationService.class).getPickupDefaultStockLocation(intercoCompany));
    // copy timetable info
    saleOrder.setExpectedRealisationDate(purchaseOrder.getExpectedRealisationDate());
    saleOrder.setAmountToBeSpreadOverTheTimetable(purchaseOrder.getAmountToBeSpreadOverTheTimetable());
    // create lines
    List<PurchaseOrderLine> purchaseOrderLineList = purchaseOrder.getPurchaseOrderLineList();
    if (purchaseOrderLineList != null) {
        for (PurchaseOrderLine purchaseOrderLine : purchaseOrderLineList) {
            this.createIntercoSaleLineFromPurchaseLine(purchaseOrderLine, saleOrder);
        }
    }
    saleOrder.setPrintingSettings(intercoCompany.getPrintingSettings());
    // compute the sale order
    saleOrderComputeService.computeSaleOrder(saleOrder);
    saleOrder.setCreatedByInterco(true);
    Beans.get(SaleOrderRepository.class).save(saleOrder);
    if (Beans.get(AppSupplychainService.class).getAppSupplychain().getIntercoSaleOrderCreateFinalized()) {
        Beans.get(SaleOrderWorkflowService.class).finalizeQuotation(saleOrder);
    }
    purchaseOrder.setExternalReference(saleOrder.getSaleOrderSeq());
    saleOrder.setExternalReference(purchaseOrder.getPurchaseOrderSeq());
    return saleOrder;
}
Also used : SaleOrderCreateService(com.axelor.apps.sale.service.saleorder.SaleOrderCreateService) PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) Company(com.axelor.apps.base.db.Company) PaymentModeService(com.axelor.apps.account.service.payment.PaymentModeService) SaleOrderWorkflowService(com.axelor.apps.sale.service.saleorder.SaleOrderWorkflowService) SaleOrderRepository(com.axelor.apps.sale.db.repo.SaleOrderRepository) SaleOrderComputeService(com.axelor.apps.sale.service.saleorder.SaleOrderComputeService) SaleOrder(com.axelor.apps.sale.db.SaleOrder) PaymentMode(com.axelor.apps.account.db.PaymentMode) Transactional(com.google.inject.persist.Transactional)

Example 34 with PurchaseOrderLine

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

the class IntercoServiceImpl method createIntercoPurchaseLineFromSaleLine.

/**
 * @param saleOrderLine the sale order line needed to create the purchase order line
 * @param purchaseOrder the purchase order line belongs to this purchase order
 * @return the created purchase order line
 */
protected PurchaseOrderLine createIntercoPurchaseLineFromSaleLine(SaleOrderLine saleOrderLine, PurchaseOrder purchaseOrder) throws AxelorException {
    PurchaseOrderLine purchaseOrderLine = Beans.get(PurchaseOrderLineService.class).createPurchaseOrderLine(purchaseOrder, saleOrderLine.getProduct(), saleOrderLine.getProductName(), saleOrderLine.getDescription(), saleOrderLine.getQty(), saleOrderLine.getUnit());
    // compute amount
    purchaseOrderLine.setPrice(saleOrderLine.getPrice());
    purchaseOrderLine.setInTaxPrice(saleOrderLine.getInTaxPrice());
    purchaseOrderLine.setExTaxTotal(saleOrderLine.getExTaxTotal());
    purchaseOrderLine.setDiscountTypeSelect(saleOrderLine.getDiscountTypeSelect());
    purchaseOrderLine.setDiscountAmount(saleOrderLine.getDiscountAmount());
    // delivery
    purchaseOrderLine.setEstimatedDelivDate(saleOrderLine.getEstimatedDelivDate());
    // compute price discounted
    BigDecimal priceDiscounted = Beans.get(PurchaseOrderLineService.class).computeDiscount(purchaseOrderLine, purchaseOrder.getInAti());
    purchaseOrderLine.setPriceDiscounted(priceDiscounted);
    // tax
    purchaseOrderLine.setTaxLine(saleOrderLine.getTaxLine());
    // analyticalDistribution
    purchaseOrderLine = Beans.get(PurchaseOrderLineServiceSupplychainImpl.class).getAndComputeAnalyticDistribution(purchaseOrderLine, purchaseOrder);
    purchaseOrder.addPurchaseOrderLineListItem(purchaseOrderLine);
    return purchaseOrderLine;
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) PurchaseOrderLineService(com.axelor.apps.purchase.service.PurchaseOrderLineService) BigDecimal(java.math.BigDecimal)

Example 35 with PurchaseOrderLine

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

the class InvoiceLineSupplychainService method computeBudgetDistributionSumAmount.

public void computeBudgetDistributionSumAmount(InvoiceLine invoiceLine, Invoice invoice) {
    List<BudgetDistribution> budgetDistributionList = invoiceLine.getBudgetDistributionList();
    PurchaseOrderLine purchaseOrderLine = invoiceLine.getPurchaseOrderLine();
    BigDecimal budgetDistributionSumAmount = BigDecimal.ZERO;
    LocalDate computeDate = invoice.getInvoiceDate();
    if (purchaseOrderLine != null && purchaseOrderLine.getPurchaseOrder().getOrderDate() != null) {
        computeDate = purchaseOrderLine.getPurchaseOrder().getOrderDate();
    }
    if (budgetDistributionList != null && !budgetDistributionList.isEmpty()) {
        for (BudgetDistribution budgetDistribution : budgetDistributionList) {
            budgetDistributionSumAmount = budgetDistributionSumAmount.add(budgetDistribution.getAmount());
            Beans.get(BudgetSupplychainService.class).computeBudgetDistributionSumAmount(budgetDistribution, computeDate);
        }
    }
    invoiceLine.setBudgetDistributionSumAmount(budgetDistributionSumAmount);
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) BudgetDistribution(com.axelor.apps.account.db.BudgetDistribution) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal)

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