Search in sources :

Example 31 with Unit

use of com.axelor.apps.base.db.Unit 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 32 with Unit

use of com.axelor.apps.base.db.Unit in project axelor-open-suite by axelor.

the class SaleOrderStockServiceImpl method createStockMoveLine.

@Override
public StockMoveLine createStockMoveLine(StockMove stockMove, SaleOrderLine saleOrderLine, BigDecimal qty) throws AxelorException {
    if (this.isStockMoveProduct(saleOrderLine)) {
        Unit unit = saleOrderLine.getProduct().getUnit();
        BigDecimal priceDiscounted = saleOrderLine.getPriceDiscounted();
        BigDecimal requestedReservedQty = saleOrderLine.getRequestedReservedQty().subtract(saleOrderLine.getDeliveredQty());
        BigDecimal companyUnitPriceUntaxed = (BigDecimal) productCompanyService.get(saleOrderLine.getProduct(), "costPrice", saleOrderLine.getSaleOrder() != null ? saleOrderLine.getSaleOrder().getCompany() : null);
        if (unit != null && !unit.equals(saleOrderLine.getUnit())) {
            qty = unitConversionService.convert(saleOrderLine.getUnit(), unit, qty, qty.scale(), saleOrderLine.getProduct());
            priceDiscounted = unitConversionService.convert(unit, saleOrderLine.getUnit(), priceDiscounted, appBaseService.getNbDecimalDigitForUnitPrice(), saleOrderLine.getProduct());
            requestedReservedQty = unitConversionService.convert(saleOrderLine.getUnit(), unit, requestedReservedQty, requestedReservedQty.scale(), saleOrderLine.getProduct());
        }
        BigDecimal taxRate = BigDecimal.ZERO;
        TaxLine taxLine = saleOrderLine.getTaxLine();
        if (taxLine != null) {
            taxRate = taxLine.getValue();
        }
        if (saleOrderLine.getQty().signum() != 0) {
            companyUnitPriceUntaxed = saleOrderLine.getCompanyExTaxTotal().divide(saleOrderLine.getQty(), Beans.get(AppBaseService.class).getNbDecimalDigitForUnitPrice(), RoundingMode.HALF_UP);
        }
        StockMoveLine stockMoveLine = stockMoveLineSupplychainService.createStockMoveLine(saleOrderLine.getProduct(), saleOrderLine.getProductName(), saleOrderLine.getDescription(), qty, requestedReservedQty, priceDiscounted, companyUnitPriceUntaxed, null, unit, stockMove, StockMoveLineService.TYPE_SALES, saleOrderLine.getSaleOrder().getInAti(), taxRate, saleOrderLine, null);
        if (saleOrderLine.getDeliveryState() == 0) {
            saleOrderLine.setDeliveryState(SaleOrderLineRepository.DELIVERY_STATE_NOT_DELIVERED);
        }
        return stockMoveLine;
    }
    return null;
}
Also used : AppBaseService(com.axelor.apps.base.service.app.AppBaseService) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Unit(com.axelor.apps.base.db.Unit) BigDecimal(java.math.BigDecimal) TaxLine(com.axelor.apps.account.db.TaxLine)

Example 33 with Unit

use of com.axelor.apps.base.db.Unit in project axelor-open-suite by axelor.

the class StockMoveLineServiceSupplychainImpl method computeFromOrder.

protected StockMoveLine computeFromOrder(StockMoveLine stockMoveLine, StockMove stockMove) throws AxelorException {
    BigDecimal unitPriceUntaxed = stockMoveLine.getUnitPriceUntaxed();
    BigDecimal unitPriceTaxed = stockMoveLine.getUnitPriceTaxed();
    Unit orderUnit = null;
    if (StockMoveRepository.ORIGIN_SALE_ORDER.equals(stockMove.getOriginTypeSelect())) {
        SaleOrderLine saleOrderLine = stockMoveLine.getSaleOrderLine();
        if (saleOrderLine == null) {
            // log the exception
            TraceBackService.trace(new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, IExceptionMessage.STOCK_MOVE_MISSING_SALE_ORDER, stockMove.getOriginId(), stockMove.getName()));
        } else {
            unitPriceUntaxed = saleOrderLine.getPriceDiscounted();
            unitPriceTaxed = saleOrderLine.getInTaxPrice();
            orderUnit = saleOrderLine.getUnit();
        }
    } else if (StockMoveRepository.ORIGIN_PURCHASE_ORDER.equals(stockMove.getOriginTypeSelect())) {
        PurchaseOrderLine purchaseOrderLine = stockMoveLine.getPurchaseOrderLine();
        if (purchaseOrderLine == null) {
            // log the exception
            TraceBackService.trace(new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, IExceptionMessage.STOCK_MOVE_MISSING_PURCHASE_ORDER, stockMove.getOriginId(), stockMove.getName()));
        } else {
            unitPriceUntaxed = purchaseOrderLine.getPrice();
            unitPriceTaxed = purchaseOrderLine.getInTaxPrice();
            orderUnit = purchaseOrderLine.getUnit();
        }
    }
    stockMoveLine.setUnitPriceUntaxed(unitPriceUntaxed);
    stockMoveLine.setUnitPriceTaxed(unitPriceTaxed);
    Unit stockUnit = getStockUnit(stockMoveLine);
    return convertUnitPrice(stockMoveLine, orderUnit, stockUnit);
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) AxelorException(com.axelor.exception.AxelorException) Unit(com.axelor.apps.base.db.Unit) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) BigDecimal(java.math.BigDecimal)

Example 34 with Unit

use of com.axelor.apps.base.db.Unit in project axelor-open-suite by axelor.

the class StockMoveLineServiceSupplychainImpl method getMergedStockMoveLine.

@Override
public StockMoveLine getMergedStockMoveLine(List<StockMoveLine> stockMoveLineList) throws AxelorException {
    if (stockMoveLineList == null || stockMoveLineList.isEmpty()) {
        return null;
    }
    if (stockMoveLineList.size() == 1) {
        return stockMoveLineList.get(0);
    }
    StockMove stockMove = stockMoveLineList.get(0).getStockMove();
    SaleOrderLine saleOrderLine = stockMoveLineList.get(0).getSaleOrderLine();
    PurchaseOrderLine purchaseOrderLine = stockMoveLineList.get(0).getPurchaseOrderLine();
    Product product;
    String productName;
    String description;
    BigDecimal quantity = BigDecimal.ZERO;
    Unit unit;
    if (saleOrderLine != null) {
        product = saleOrderLine.getProduct();
        productName = saleOrderLine.getProductName();
        description = saleOrderLine.getDescription();
        unit = saleOrderLine.getUnit();
    } else if (purchaseOrderLine != null) {
        product = purchaseOrderLine.getProduct();
        productName = purchaseOrderLine.getProductName();
        description = purchaseOrderLine.getDescription();
        unit = purchaseOrderLine.getUnit();
    } else {
        // shouldn't ever happen or you misused this function
        return null;
    }
    for (StockMoveLine stockMoveLine : stockMoveLineList) {
        quantity = quantity.add(stockMoveLine.getRealQty());
    }
    StockMoveLine generatedStockMoveLine = createStockMoveLine(product, productName, description, quantity, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, unit, stockMove, null);
    generatedStockMoveLine.setSaleOrderLine(saleOrderLine);
    generatedStockMoveLine.setPurchaseOrderLine(purchaseOrderLine);
    generatedStockMoveLine.setIsMergedStockMoveLine(true);
    return generatedStockMoveLine;
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) StockMove(com.axelor.apps.stock.db.StockMove) Product(com.axelor.apps.base.db.Product) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) Unit(com.axelor.apps.base.db.Unit) BigDecimal(java.math.BigDecimal)

Example 35 with Unit

use of com.axelor.apps.base.db.Unit in project axelor-open-suite by axelor.

the class ProjectGeneratorFactoryTaskTemplate method updateTask.

private void updateTask(ProjectTask root, ProjectTask childTask, SaleOrderLine orderLine) throws AxelorException {
    childTask.setParentTask(root);
    childTask.setQuantity(orderLine.getQty());
    Product product = orderLine.getProduct();
    childTask.setProduct(product);
    childTask.setExTaxTotal(orderLine.getExTaxTotal());
    Company company = orderLine.getSaleOrder() != null ? orderLine.getSaleOrder().getCompany() : null;
    childTask.setUnitPrice(product != null ? (BigDecimal) productCompanyService.get(product, "salePrice", company) : null);
    childTask.setUnit(product != null ? (Unit) productCompanyService.get(product, "unit", company) : null);
    childTask.setSaleOrderLine(orderLine);
    if (orderLine.getSaleOrder().getToInvoiceViaTask()) {
        childTask.setToInvoice(true);
        childTask.setInvoicingType(ProjectTaskRepository.INVOICING_TYPE_PACKAGE);
    }
}
Also used : Company(com.axelor.apps.base.db.Company) Product(com.axelor.apps.base.db.Product) Unit(com.axelor.apps.base.db.Unit) BigDecimal(java.math.BigDecimal)

Aggregations

Unit (com.axelor.apps.base.db.Unit)45 BigDecimal (java.math.BigDecimal)38 Product (com.axelor.apps.base.db.Product)19 AxelorException (com.axelor.exception.AxelorException)13 Transactional (com.google.inject.persist.Transactional)12 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)11 UnitConversionService (com.axelor.apps.base.service.UnitConversionService)9 Company (com.axelor.apps.base.db.Company)8 PurchaseOrderLine (com.axelor.apps.purchase.db.PurchaseOrderLine)8 StockLocationLine (com.axelor.apps.stock.db.StockLocationLine)8 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)6 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)6 StockLocation (com.axelor.apps.stock.db.StockLocation)6 StockMove (com.axelor.apps.stock.db.StockMove)6 LocalDate (java.time.LocalDate)6 List (java.util.List)6 ProdProduct (com.axelor.apps.production.db.ProdProduct)5 ProdResidualProduct (com.axelor.apps.production.db.ProdResidualProduct)5 ArrayList (java.util.ArrayList)5 BillOfMaterial (com.axelor.apps.production.db.BillOfMaterial)4