Search in sources :

Example 41 with PurchaseOrderLine

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

the class PurchaseOrderServiceSupplychainImpl method createShippingCostLine.

@Override
public PurchaseOrderLine createShippingCostLine(PurchaseOrder purchaseOrder, Product shippingCostProduct) throws AxelorException {
    PurchaseOrderLine shippingCostLine = new PurchaseOrderLine();
    shippingCostLine.setPurchaseOrder(purchaseOrder);
    shippingCostLine.setProduct(shippingCostProduct);
    purchaseOrderLineService.fill(shippingCostLine, purchaseOrder);
    purchaseOrderLineService.compute(shippingCostLine, purchaseOrder);
    return shippingCostLine;
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine)

Example 42 with PurchaseOrderLine

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

the class PurchaseOrderServiceSupplychainImpl method requestPurchaseOrder.

@Override
@Transactional(rollbackOn = { Exception.class })
public void requestPurchaseOrder(PurchaseOrder purchaseOrder) throws AxelorException {
    if (!Beans.get(AppSupplychainService.class).isApp("supplychain")) {
        super.requestPurchaseOrder(purchaseOrder);
        return;
    }
    // budget control
    if (appAccountService.isApp("budget") && appAccountService.getAppBudget().getCheckAvailableBudget()) {
        List<PurchaseOrderLine> purchaseOrderLines = purchaseOrder.getPurchaseOrderLineList();
        Map<Budget, BigDecimal> amountPerBudget = new HashMap<>();
        if (appAccountService.getAppBudget().getManageMultiBudget()) {
            for (PurchaseOrderLine pol : purchaseOrderLines) {
                if (pol.getBudgetDistributionList() != null) {
                    for (BudgetDistribution bd : pol.getBudgetDistributionList()) {
                        Budget budget = bd.getBudget();
                        if (!amountPerBudget.containsKey(budget)) {
                            amountPerBudget.put(budget, bd.getAmount());
                        } else {
                            BigDecimal oldAmount = amountPerBudget.get(budget);
                            amountPerBudget.put(budget, oldAmount.add(bd.getAmount()));
                        }
                        isBudgetExceeded(budget, amountPerBudget.get(budget));
                    }
                }
            }
        } else {
            for (PurchaseOrderLine pol : purchaseOrderLines) {
                // getting Budget associated to POL
                Budget budget = pol.getBudget();
                if (!amountPerBudget.containsKey(budget)) {
                    amountPerBudget.put(budget, pol.getExTaxTotal());
                } else {
                    BigDecimal oldAmount = amountPerBudget.get(budget);
                    amountPerBudget.put(budget, oldAmount.add(pol.getExTaxTotal()));
                }
                isBudgetExceeded(budget, amountPerBudget.get(budget));
            }
        }
    }
    super.requestPurchaseOrder(purchaseOrder);
    int intercoPurchaseCreatingStatus = Beans.get(AppSupplychainService.class).getAppSupplychain().getIntercoPurchaseCreatingStatusSelect();
    if (purchaseOrder.getInterco() && intercoPurchaseCreatingStatus == PurchaseOrderRepository.STATUS_REQUESTED) {
        Beans.get(IntercoService.class).generateIntercoSaleFromPurchase(purchaseOrder);
    }
    if (purchaseOrder.getCreatedByInterco()) {
        fillIntercompanySaleOrderCounterpart(purchaseOrder);
    }
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) HashMap(java.util.HashMap) Budget(com.axelor.apps.account.db.Budget) BudgetDistribution(com.axelor.apps.account.db.BudgetDistribution) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Example 43 with PurchaseOrderLine

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

the class PurchaseOrderServiceSupplychainImpl method createShipmentCostLine.

@Override
public String createShipmentCostLine(PurchaseOrder purchaseOrder) throws AxelorException {
    List<PurchaseOrderLine> purchaseOrderLines = purchaseOrder.getPurchaseOrderLineList();
    ShipmentMode shipmentMode = purchaseOrder.getShipmentMode();
    if (shipmentMode == null) {
        return null;
    }
    Product shippingCostProduct = shipmentMode.getShippingCostsProduct();
    if (shipmentMode.getHasCarriagePaidPossibility()) {
        BigDecimal carriagePaidThreshold = shipmentMode.getCarriagePaidThreshold();
        if (computeExTaxTotalWithoutShippingLines(purchaseOrder).compareTo(carriagePaidThreshold) >= 0) {
            String message = removeShipmentCostLine(purchaseOrder);
            this.computePurchaseOrder(purchaseOrder);
            return message;
        }
    }
    if (alreadyHasShippingCostLine(purchaseOrder, shippingCostProduct)) {
        return null;
    }
    PurchaseOrderLine shippingCostLine = createShippingCostLine(purchaseOrder, shippingCostProduct);
    purchaseOrderLines.add(shippingCostLine);
    this.computePurchaseOrder(purchaseOrder);
    return null;
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) Product(com.axelor.apps.base.db.Product) ShipmentMode(com.axelor.apps.stock.db.ShipmentMode) BigDecimal(java.math.BigDecimal)

Example 44 with PurchaseOrderLine

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

the class PurchaseOrderStockServiceImpl method createStockMove.

protected List<Long> createStockMove(PurchaseOrder purchaseOrder, LocalDate estimatedDeliveryDate, List<PurchaseOrderLine> purchaseOrderLineList) throws AxelorException {
    List<Long> stockMoveIdList = new ArrayList<>();
    Partner supplierPartner = purchaseOrder.getSupplierPartner();
    Company company = purchaseOrder.getCompany();
    Address address = Beans.get(PartnerService.class).getDeliveryAddress(supplierPartner);
    StockLocation startLocation = getStartStockLocation(purchaseOrder);
    StockMove stockMove = stockMoveService.createStockMove(address, null, company, supplierPartner, startLocation, purchaseOrder.getStockLocation(), null, estimatedDeliveryDate, purchaseOrder.getNotes(), purchaseOrder.getShipmentMode(), purchaseOrder.getFreightCarrierMode(), null, null, null, StockMoveRepository.TYPE_INCOMING);
    StockMove qualityStockMove = stockMoveService.createStockMove(address, null, company, supplierPartner, startLocation, appBaseService.getAppBase().getEnableTradingNamesManagement() ? purchaseOrder.getTradingName().getQualityControlDefaultStockLocation() : company.getStockConfig().getQualityControlDefaultStockLocation(), null, estimatedDeliveryDate, purchaseOrder.getNotes(), purchaseOrder.getShipmentMode(), purchaseOrder.getFreightCarrierMode(), null, null, null, StockMoveRepository.TYPE_INCOMING);
    stockMove.setOriginId(purchaseOrder.getId());
    stockMove.setOriginTypeSelect(StockMoveRepository.ORIGIN_PURCHASE_ORDER);
    stockMove.setOrigin(purchaseOrder.getPurchaseOrderSeq());
    stockMove.setTradingName(purchaseOrder.getTradingName());
    stockMove.setGroupProductsOnPrintings(purchaseOrder.getGroupProductsOnPrintings());
    qualityStockMove.setOriginId(purchaseOrder.getId());
    qualityStockMove.setOriginTypeSelect(StockMoveRepository.ORIGIN_PURCHASE_ORDER);
    qualityStockMove.setOrigin(purchaseOrder.getPurchaseOrderSeq());
    qualityStockMove.setTradingName(purchaseOrder.getTradingName());
    qualityStockMove.setGroupProductsOnPrintings(purchaseOrder.getGroupProductsOnPrintings());
    SupplyChainConfig supplychainConfig = Beans.get(SupplyChainConfigService.class).getSupplyChainConfig(purchaseOrder.getCompany());
    if (supplychainConfig.getDefaultEstimatedDateForPurchaseOrder() == SupplyChainConfigRepository.CURRENT_DATE && stockMove.getEstimatedDate() == null) {
        stockMove.setEstimatedDate(appBaseService.getTodayDate(company));
    } else if (supplychainConfig.getDefaultEstimatedDateForPurchaseOrder() == SupplyChainConfigRepository.CURRENT_DATE_PLUS_DAYS && stockMove.getEstimatedDate() == null) {
        stockMove.setEstimatedDate(appBaseService.getTodayDate(company).plusDays(supplychainConfig.getNumberOfDaysForPurchaseOrder().longValue()));
    }
    for (PurchaseOrderLine purchaseOrderLine : purchaseOrderLineList) {
        BigDecimal qty = purchaseOrderLineServiceSupplychainImpl.computeUndeliveredQty(purchaseOrderLine);
        if (qty.signum() > 0 && !existActiveStockMoveForPurchaseOrderLine(purchaseOrderLine)) {
            this.createStockMoveLine(stockMove, qualityStockMove, purchaseOrderLine, qty);
        }
    }
    if (stockMove.getStockMoveLineList() != null && !stockMove.getStockMoveLineList().isEmpty()) {
        stockMoveService.plan(stockMove);
        stockMoveIdList.add(stockMove.getId());
    }
    if (qualityStockMove.getStockMoveLineList() != null && !qualityStockMove.getStockMoveLineList().isEmpty()) {
        stockMoveService.plan(qualityStockMove);
        stockMoveIdList.add(qualityStockMove.getId());
    }
    return stockMoveIdList;
}
Also used : Company(com.axelor.apps.base.db.Company) StockMove(com.axelor.apps.stock.db.StockMove) Address(com.axelor.apps.base.db.Address) StockLocation(com.axelor.apps.stock.db.StockLocation) ArrayList(java.util.ArrayList) SupplyChainConfigService(com.axelor.apps.supplychain.service.config.SupplyChainConfigService) PartnerService(com.axelor.apps.base.service.PartnerService) BigDecimal(java.math.BigDecimal) PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) SupplyChainConfig(com.axelor.apps.supplychain.db.SupplyChainConfig) Partner(com.axelor.apps.base.db.Partner)

Example 45 with PurchaseOrderLine

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

the class PurchaseOrderInvoiceServiceImpl method createInvoiceLines.

public List<InvoiceLine> createInvoiceLines(Invoice invoice, List<PurchaseOrderLine> purchaseOrderLineList, Map<Long, BigDecimal> qtyToInvoiceMap) throws AxelorException {
    List<InvoiceLine> invoiceLineList = new ArrayList<>();
    for (PurchaseOrderLine purchaseOrderLine : purchaseOrderLineList) {
        if (qtyToInvoiceMap.containsKey(purchaseOrderLine.getId())) {
            List<InvoiceLine> invoiceLines = this.createInvoiceLine(invoice, purchaseOrderLine, qtyToInvoiceMap.get(purchaseOrderLine.getId()));
            invoiceLineList.addAll(invoiceLines);
            purchaseOrderLine.setInvoiced(true);
        }
    }
    return invoiceLineList;
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) ArrayList(java.util.ArrayList)

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