Search in sources :

Example 1 with PurchaseOrderLine

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

the class PurchaseOrderLineServiceSupplychainImpl method createPurchaseOrderLine.

public PurchaseOrderLine createPurchaseOrderLine(PurchaseOrder purchaseOrder, SaleOrderLine saleOrderLine) throws AxelorException {
    LOG.debug("Création d'une ligne de commande fournisseur pour le produit : {}", saleOrderLine.getProductName());
    Unit unit = null;
    BigDecimal qty = BigDecimal.ZERO;
    if (saleOrderLine.getTypeSelect() == SaleOrderLineRepository.TYPE_NORMAL) {
        if (saleOrderLine.getProduct() != null) {
            unit = saleOrderLine.getProduct().getPurchasesUnit();
        }
        qty = saleOrderLine.getQty();
        if (unit == null) {
            unit = saleOrderLine.getUnit();
        } else {
            qty = unitConversionService.convert(saleOrderLine.getUnit(), unit, qty, qty.scale(), saleOrderLine.getProduct());
        }
    }
    PurchaseOrderLine purchaseOrderLine = super.createPurchaseOrderLine(purchaseOrder, saleOrderLine.getProduct(), saleOrderLine.getProductName(), null, qty, unit);
    purchaseOrderLine.setIsTitleLine(!(saleOrderLine.getTypeSelect() == SaleOrderLineRepository.TYPE_NORMAL));
    this.getAndComputeAnalyticDistribution(purchaseOrderLine, purchaseOrder);
    return purchaseOrderLine;
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) Unit(com.axelor.apps.base.db.Unit) BigDecimal(java.math.BigDecimal)

Example 2 with PurchaseOrderLine

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

the class PurchaseOrderServiceSupplychainImpl method removeShipmentCostLine.

@Override
@Transactional(rollbackOn = Exception.class)
public String removeShipmentCostLine(PurchaseOrder purchaseOrder) {
    List<PurchaseOrderLine> purchaseOrderLines = purchaseOrder.getPurchaseOrderLineList();
    if (purchaseOrderLines == null) {
        return null;
    }
    List<PurchaseOrderLine> linesToRemove = new ArrayList<PurchaseOrderLine>();
    for (PurchaseOrderLine purchaseOrderLine : purchaseOrderLines) {
        if (purchaseOrderLine.getProduct().getIsShippingCostsProduct()) {
            linesToRemove.add(purchaseOrderLine);
        }
    }
    if (linesToRemove.size() == 0) {
        return null;
    }
    for (PurchaseOrderLine lineToRemove : linesToRemove) {
        purchaseOrderLines.remove(lineToRemove);
        if (lineToRemove.getId() != null) {
            purchaseOrderLineRepository.remove(lineToRemove);
        }
    }
    purchaseOrder.setPurchaseOrderLineList(purchaseOrderLines);
    return I18n.get("Carriage paid threshold is exceeded, all shipment cost lines are removed");
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) ArrayList(java.util.ArrayList) Transactional(com.google.inject.persist.Transactional)

Example 3 with PurchaseOrderLine

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

the class PurchaseOrderServiceSupplychainImpl method applyToallBudgetDistribution.

@Transactional
@Override
public void applyToallBudgetDistribution(PurchaseOrder purchaseOrder) {
    for (PurchaseOrderLine purchaseOrderLine : purchaseOrder.getPurchaseOrderLineList()) {
        BudgetDistribution newBudgetDistribution = new BudgetDistribution();
        newBudgetDistribution.setAmount(purchaseOrderLine.getCompanyExTaxTotal());
        newBudgetDistribution.setBudget(purchaseOrder.getBudget());
        newBudgetDistribution.setPurchaseOrderLine(purchaseOrderLine);
        Beans.get(BudgetDistributionRepository.class).save(newBudgetDistribution);
        Beans.get(PurchaseOrderLineServiceSupplychainImpl.class).computeBudgetDistributionSumAmount(purchaseOrderLine, purchaseOrder);
    }
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) BudgetDistributionRepository(com.axelor.apps.account.db.repo.BudgetDistributionRepository) BudgetDistribution(com.axelor.apps.account.db.BudgetDistribution) Transactional(com.google.inject.persist.Transactional)

Example 4 with PurchaseOrderLine

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

the class PurchaseOrderStockServiceImpl method getAllPurchaseOrderLinePerDate.

protected Map<LocalDate, List<PurchaseOrderLine>> getAllPurchaseOrderLinePerDate(PurchaseOrder purchaseOrder) {
    Map<LocalDate, List<PurchaseOrderLine>> purchaseOrderLinePerDateMap = new HashMap<>();
    for (PurchaseOrderLine purchaseOrderLine : purchaseOrder.getPurchaseOrderLineList()) {
        if (purchaseOrderLineServiceSupplychainImpl.computeUndeliveredQty(purchaseOrderLine).signum() <= 0) {
            continue;
        }
        LocalDate dateKey = purchaseOrderLine.getEstimatedDelivDate();
        if (dateKey == null) {
            dateKey = purchaseOrderLine.getPurchaseOrder().getDeliveryDate();
        }
        List<PurchaseOrderLine> purchaseOrderLineLists = purchaseOrderLinePerDateMap.get(dateKey);
        if (purchaseOrderLineLists == null) {
            purchaseOrderLineLists = new ArrayList<>();
            purchaseOrderLinePerDateMap.put(dateKey, purchaseOrderLineLists);
        }
        purchaseOrderLineLists.add(purchaseOrderLine);
    }
    return purchaseOrderLinePerDateMap;
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) HashMap(java.util.HashMap) List(java.util.List) ArrayList(java.util.ArrayList) LocalDate(java.time.LocalDate)

Example 5 with PurchaseOrderLine

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

the class PurchaseOrderStockServiceImpl method createStockMoveFromPurchaseOrder.

/**
 * Méthode permettant de créer un StockMove à partir d'un PurchaseOrder.
 *
 * @param purchaseOrder une commande
 * @throws AxelorException Aucune séquence de StockMove n'a été configurée
 */
public List<Long> createStockMoveFromPurchaseOrder(PurchaseOrder purchaseOrder) throws AxelorException {
    List<Long> stockMoveIdList = new ArrayList<>();
    if (purchaseOrder.getPurchaseOrderLineList() == null || purchaseOrder.getCompany() == null) {
        return stockMoveIdList;
    }
    if (purchaseOrder.getStockLocation() == null) {
        throw new AxelorException(purchaseOrder, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.PO_MISSING_STOCK_LOCATION), purchaseOrder.getPurchaseOrderSeq());
    }
    Map<LocalDate, List<PurchaseOrderLine>> purchaseOrderLinePerDateMap = getAllPurchaseOrderLinePerDate(purchaseOrder);
    for (LocalDate estimatedDeliveryDate : purchaseOrderLinePerDateMap.keySet().stream().filter(x -> x != null).sorted((x, y) -> x.compareTo(y)).collect(Collectors.toList())) {
        List<PurchaseOrderLine> purchaseOrderLineList = purchaseOrderLinePerDateMap.get(estimatedDeliveryDate);
        List<Long> stockMoveId = createStockMove(purchaseOrder, estimatedDeliveryDate, purchaseOrderLineList);
        if (stockMoveId != null && !stockMoveId.isEmpty()) {
            stockMoveIdList.addAll(stockMoveId);
        }
    }
    Optional<List<PurchaseOrderLine>> purchaseOrderLineListDeliveryDateNull = Optional.ofNullable(purchaseOrderLinePerDateMap.get(null));
    if (purchaseOrderLineListDeliveryDateNull.isPresent()) {
        List<Long> stockMoveId = createStockMove(purchaseOrder, null, purchaseOrderLineListDeliveryDateNull.get());
        if (stockMoveId != null && !stockMoveId.isEmpty()) {
            stockMoveIdList.addAll(stockMoveId);
        }
    }
    return stockMoveIdList;
}
Also used : StockLocationRepository(com.axelor.apps.stock.db.repo.StockLocationRepository) IExceptionMessage(com.axelor.apps.supplychain.exception.IExceptionMessage) PartnerService(com.axelor.apps.base.service.PartnerService) Inject(com.google.inject.Inject) LoggerFactory(org.slf4j.LoggerFactory) ShippingCoefService(com.axelor.apps.base.service.ShippingCoefService) PurchaseOrderLineRepository(com.axelor.apps.purchase.db.repo.PurchaseOrderLineRepository) BigDecimal(java.math.BigDecimal) TaxLine(com.axelor.apps.account.db.TaxLine) Map(java.util.Map) StockMoveLineService(com.axelor.apps.stock.service.StockMoveLineService) StockLocationService(com.axelor.apps.stock.service.StockLocationService) RoundingMode(java.math.RoundingMode) StockConfig(com.axelor.apps.stock.db.StockConfig) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository) MethodHandles(java.lang.invoke.MethodHandles) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) StringUtils(com.axelor.common.StringUtils) Collectors(java.util.stream.Collectors) SupplyChainConfig(com.axelor.apps.supplychain.db.SupplyChainConfig) List(java.util.List) Product(com.axelor.apps.base.db.Product) PartnerStockSettingsService(com.axelor.apps.stock.service.PartnerStockSettingsService) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) LocalDate(java.time.LocalDate) Optional(java.util.Optional) Address(com.axelor.apps.base.db.Address) Partner(com.axelor.apps.base.db.Partner) SupplyChainConfigService(com.axelor.apps.supplychain.service.config.SupplyChainConfigService) Company(com.axelor.apps.base.db.Company) PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) StockMoveLineRepository(com.axelor.apps.stock.db.repo.StockMoveLineRepository) PurchaseOrderRepository(com.axelor.apps.purchase.db.repo.PurchaseOrderRepository) ProductRepository(com.axelor.apps.base.db.repo.ProductRepository) HashMap(java.util.HashMap) StockMoveService(com.axelor.apps.stock.service.StockMoveService) ArrayList(java.util.ArrayList) AxelorException(com.axelor.exception.AxelorException) UnitConversionService(com.axelor.apps.base.service.UnitConversionService) StockLocation(com.axelor.apps.stock.db.StockLocation) I18n(com.axelor.i18n.I18n) StringTool(com.axelor.apps.tool.StringTool) Logger(org.slf4j.Logger) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) StockConfigService(com.axelor.apps.stock.service.config.StockConfigService) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Beans(com.axelor.inject.Beans) Unit(com.axelor.apps.base.db.Unit) SupplyChainConfigRepository(com.axelor.apps.supplychain.db.repo.SupplyChainConfigRepository) AppSupplychainService(com.axelor.apps.supplychain.service.app.AppSupplychainService) PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) AxelorException(com.axelor.exception.AxelorException) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) LocalDate(java.time.LocalDate)

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