Search in sources :

Example 56 with PurchaseOrderLine

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

the class PurchaseOrderServiceImpl method updateCostPrice.

@Override
@Transactional(rollbackOn = { Exception.class })
public void updateCostPrice(PurchaseOrder purchaseOrder) throws AxelorException {
    if (purchaseOrder.getPurchaseOrderLineList() != null) {
        for (PurchaseOrderLine purchaseOrderLine : purchaseOrder.getPurchaseOrderLineList()) {
            Product product = purchaseOrderLine.getProduct();
            if (product != null) {
                BigDecimal lastPurchasePrice = (Boolean) productCompanyService.get(product, "inAti", purchaseOrder.getCompany()) ? purchaseOrderLine.getInTaxPrice() : purchaseOrderLine.getPrice();
                lastPurchasePrice = currencyService.getAmountCurrencyConvertedAtDate(purchaseOrder.getCurrency(), purchaseOrder.getCompany().getCurrency(), lastPurchasePrice, currencyService.getDateToConvert(null));
                productCompanyService.set(product, "lastPurchasePrice", lastPurchasePrice, purchaseOrder.getCompany());
                LocalDate lastPurchaseDate = Beans.get(AppBaseService.class).getTodayDate(Optional.ofNullable(AuthUtils.getUser()).map(User::getActiveCompany).orElse(null));
                productCompanyService.set(product, "lastPurchaseDate", lastPurchaseDate, purchaseOrder.getCompany());
                if ((Boolean) productCompanyService.get(product, "defShipCoefByPartner", purchaseOrder.getCompany())) {
                    Unit productPurchaseUnit = (Unit) productCompanyService.get(product, "purchasesUnit", purchaseOrder.getCompany());
                    productPurchaseUnit = productPurchaseUnit != null ? productPurchaseUnit : (Unit) productCompanyService.get(product, "unit", purchaseOrder.getCompany());
                    BigDecimal convertedQty = Beans.get(UnitConversionService.class).convert(purchaseOrderLine.getUnit(), productPurchaseUnit, purchaseOrderLine.getQty(), purchaseOrderLine.getQty().scale(), product);
                    BigDecimal shippingCoef = Beans.get(ShippingCoefService.class).getShippingCoefDefByPartner(product, purchaseOrder.getSupplierPartner(), purchaseOrder.getCompany(), convertedQty);
                    if (shippingCoef.compareTo(BigDecimal.ZERO) != 0) {
                        productCompanyService.set(product, "shippingCoef", shippingCoef, purchaseOrder.getCompany());
                    }
                }
                if ((Integer) productCompanyService.get(product, "costTypeSelect", purchaseOrder.getCompany()) == ProductRepository.COST_TYPE_LAST_PURCHASE_PRICE) {
                    productCompanyService.set(product, "costPrice", lastPurchasePrice, purchaseOrder.getCompany());
                    if ((Boolean) productCompanyService.get(product, "autoUpdateSalePrice", purchaseOrder.getCompany())) {
                        Beans.get(ProductService.class).updateSalePrice(product, purchaseOrder.getCompany());
                    }
                }
            }
        }
        purchaseOrderRepo.save(purchaseOrder);
    }
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) UnitConversionService(com.axelor.apps.base.service.UnitConversionService) User(com.axelor.auth.db.User) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) ProductService(com.axelor.apps.base.service.ProductService) ShippingCoefService(com.axelor.apps.base.service.ShippingCoefService) Product(com.axelor.apps.base.db.Product) Unit(com.axelor.apps.base.db.Unit) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Example 57 with PurchaseOrderLine

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

the class PurchaseOrderServiceImpl method attachToNewPurchaseOrder.

// Attachment of all purchase order lines to new purchase order
public void attachToNewPurchaseOrder(List<PurchaseOrder> purchaseOrderList, PurchaseOrder purchaseOrderMerged) {
    for (PurchaseOrder purchaseOrder : purchaseOrderList) {
        int countLine = 1;
        for (PurchaseOrderLine purchaseOrderLine : purchaseOrder.getPurchaseOrderLineList()) {
            purchaseOrderLine.setSequence(countLine * 10);
            purchaseOrderMerged.addPurchaseOrderLineListItem(purchaseOrderLine);
            countLine++;
        }
    }
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder)

Example 58 with PurchaseOrderLine

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

the class PurchaseProductServiceImpl method getLastShippingCoef.

@Override
public BigDecimal getLastShippingCoef(Product product) throws AxelorException {
    PurchaseOrderLine lastPurchaseOrderLine = Beans.get(PurchaseOrderLineRepository.class).all().filter("self.product.id = :productId " + "AND (self.purchaseOrder.statusSelect = :validated " + "OR self.purchaseOrder.statusSelect = :finished)").bind("productId", product.getId()).bind("validated", PurchaseOrderRepository.STATUS_VALIDATED).bind("finished", PurchaseOrderRepository.STATUS_FINISHED).order("-purchaseOrder.validationDate").fetchOne();
    if (lastPurchaseOrderLine != null) {
        Partner partner = lastPurchaseOrderLine.getPurchaseOrder().getSupplierPartner();
        Company company = lastPurchaseOrderLine.getPurchaseOrder().getCompany();
        Unit productUnit = Beans.get(PurchaseOrderLineService.class).getPurchaseUnit(lastPurchaseOrderLine);
        BigDecimal qty = Beans.get(UnitConversionService.class).convert(lastPurchaseOrderLine.getUnit(), productUnit, lastPurchaseOrderLine.getQty(), lastPurchaseOrderLine.getQty().scale(), product);
        return Beans.get(ShippingCoefService.class).getShippingCoef(product, partner, company, qty);
    } else {
        return BigDecimal.ONE;
    }
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) PurchaseOrderLineRepository(com.axelor.apps.purchase.db.repo.PurchaseOrderLineRepository) Company(com.axelor.apps.base.db.Company) UnitConversionService(com.axelor.apps.base.service.UnitConversionService) ShippingCoefService(com.axelor.apps.base.service.ShippingCoefService) Unit(com.axelor.apps.base.db.Unit) Partner(com.axelor.apps.base.db.Partner) BigDecimal(java.math.BigDecimal)

Example 59 with PurchaseOrderLine

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

the class PurchaseRequestServiceImpl method generatePo.

@Transactional(rollbackOn = { Exception.class })
@Override
public List<PurchaseOrder> generatePo(List<PurchaseRequest> purchaseRequests, Boolean groupBySupplier, Boolean groupByProduct) throws AxelorException {
    List<PurchaseOrderLine> purchaseOrderLineList = new ArrayList<PurchaseOrderLine>();
    Map<String, PurchaseOrder> purchaseOrderMap = new HashMap<>();
    for (PurchaseRequest purchaseRequest : purchaseRequests) {
        PurchaseOrder purchaseOrder;
        String key = groupBySupplier ? getPurchaseOrderGroupBySupplierKey(purchaseRequest) : null;
        if (key != null && purchaseOrderMap.containsKey(key)) {
            purchaseOrder = purchaseOrderMap.get(key);
        } else {
            purchaseOrder = createPurchaseOrder(purchaseRequest);
            key = key == null ? purchaseRequest.getId().toString() : key;
            purchaseOrderMap.put(key, purchaseOrder);
        }
        if (purchaseOrder == null) {
            purchaseOrder = createPurchaseOrder(purchaseRequest);
        }
        for (PurchaseRequestLine purchaseRequestLine : purchaseRequest.getPurchaseRequestLineList()) {
            PurchaseOrderLine purchaseOrderLine = new PurchaseOrderLine();
            Product product = purchaseRequestLine.getProduct();
            purchaseOrderLine = groupByProduct && purchaseOrder != null ? getPoLineByProduct(product, purchaseOrder) : null;
            purchaseOrderLine = purchaseOrderLineService.createPurchaseOrderLine(purchaseOrder, product, purchaseRequestLine.getNewProduct() ? purchaseRequestLine.getProductTitle() : null, null, purchaseRequestLine.getQuantity(), purchaseRequestLine.getUnit());
            purchaseOrder.addPurchaseOrderLineListItem(purchaseOrderLine);
            purchaseOrderLineList.add(purchaseOrderLine);
            purchaseOrderLineService.compute(purchaseOrderLine, purchaseOrder);
        }
        purchaseOrder.getPurchaseOrderLineList().addAll(purchaseOrderLineList);
        purchaseOrderService.computePurchaseOrder(purchaseOrder);
        purchaseOrderRepo.save(purchaseOrder);
        purchaseRequest.setPurchaseOrder(purchaseOrder);
        purchaseRequestRepo.save(purchaseRequest);
    }
    List<PurchaseOrder> purchaseOrders = purchaseOrderMap.values().stream().collect(Collectors.toList());
    return purchaseOrders;
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PurchaseRequestLine(com.axelor.apps.purchase.db.PurchaseRequestLine) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) Product(com.axelor.apps.base.db.Product) PurchaseRequest(com.axelor.apps.purchase.db.PurchaseRequest) Transactional(com.google.inject.persist.Transactional)

Example 60 with PurchaseOrderLine

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

the class FixedAssetServiceSupplyChainImpl method createFixedAssets.

@Transactional
@Override
public List<FixedAsset> createFixedAssets(Invoice invoice) throws AxelorException {
    List<FixedAsset> fixedAssetList = super.createFixedAssets(invoice);
    if (!Beans.get(AppSupplychainService.class).isApp("supplychain")) {
        return fixedAssetList;
    }
    if (fixedAssetList.isEmpty()) {
        return new ArrayList<>();
    }
    StockLocation stockLocation = invoice.getPurchaseOrder() != null ? invoice.getPurchaseOrder().getStockLocation() : null;
    for (FixedAsset fixedAsset : fixedAssetList) {
        PurchaseOrderLine pol = fixedAsset.getInvoiceLine().getPurchaseOrderLine();
        fixedAsset.setStockLocation(stockLocation);
        if (fixedAsset.getInvoiceLine().getIncomingStockMove() != null && CollectionUtils.isNotEmpty(fixedAsset.getInvoiceLine().getIncomingStockMove().getStockMoveLineList())) {
            fixedAsset.setTrackingNumber(fixedAsset.getInvoiceLine().getIncomingStockMove().getStockMoveLineList().stream().filter(l -> pol.equals(l.getPurchaseOrderLine())).findFirst().map(StockMoveLine::getTrackingNumber).orElse(null));
            fixedAsset.setStockLocation(fixedAsset.getInvoiceLine().getIncomingStockMove().getToStockLocation());
        }
    }
    return fixedAssetList;
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) StockLocation(com.axelor.apps.stock.db.StockLocation) ArrayList(java.util.ArrayList) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) FixedAsset(com.axelor.apps.account.db.FixedAsset) 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