Search in sources :

Example 11 with Product

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

the class InventoryService method generateStockMoveLines.

/**
 * Generate lines for the given stock move. Depending if we are creating an incoming or outgoing
 * stock move, we only create stock move line with positive quantity.
 *
 * @param inventoryLine an inventory line
 * @param stockMove a stock move being created
 * @param isEnteringStock whether we are creating an incoming or outgoing stock move.
 * @throws AxelorException
 */
protected void generateStockMoveLines(InventoryLine inventoryLine, StockMove stockMove, boolean isEnteringStock) throws AxelorException {
    Product product = inventoryLine.getProduct();
    TrackingNumber trackingNumber = inventoryLine.getTrackingNumber();
    BigDecimal diff = inventoryLine.getRealQty().subtract(inventoryLine.getCurrentQty());
    if (!isEnteringStock) {
        diff = diff.negate();
    }
    if (diff.signum() > 0) {
        BigDecimal avgPrice;
        StockLocationLine stockLocationLine = stockLocationLineService.getStockLocationLine(stockMove.getToStockLocation(), product);
        if (stockLocationLine != null) {
            avgPrice = stockLocationLine.getAvgPrice();
        } else {
            avgPrice = BigDecimal.ZERO;
        }
        StockMoveLine stockMoveLine = stockMoveLineService.createStockMoveLine(product, product.getName(), product.getDescription(), diff, avgPrice, avgPrice, product.getUnit(), stockMove, StockMoveLineService.TYPE_NULL, false, BigDecimal.ZERO);
        if (stockMoveLine == null) {
            throw new AxelorException(inventoryLine.getInventory(), TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.INVENTORY_7) + " " + inventoryLine.getInventory().getInventorySeq());
        }
        if (trackingNumber != null && stockMoveLine.getTrackingNumber() == null) {
            stockMoveLine.setTrackingNumber(trackingNumber);
        }
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) TrackingNumber(com.axelor.apps.stock.db.TrackingNumber) Product(com.axelor.apps.base.db.Product) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) BigDecimal(java.math.BigDecimal)

Example 12 with Product

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

the class StockLocationLineServiceImpl method computeFutureQty.

@Override
public BigDecimal computeFutureQty(StockLocationLine stockLocationLine) throws AxelorException {
    // future quantity is current quantity minus planned outgoing stock move lines plus planned
    // incoming stock move lines.
    Product product = stockLocationLine.getProduct();
    BigDecimal futureQty = stockLocationLine.getCurrentQty();
    List<StockMoveLine> incomingStockMoveLineList = findIncomingPlannedStockMoveLines(stockLocationLine);
    List<StockMoveLine> outgoingStockMoveLineList = findOutgoingPlannedStockMoveLines(stockLocationLine);
    if (stockLocationLine.getUnit() == null) {
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.LOCATION_LINE_MISSING_UNIT), stockLocationLine.getStockLocation().getName(), product.getFullName());
    }
    for (StockMoveLine incomingStockMoveLine : incomingStockMoveLineList) {
        BigDecimal qtyToAdd = unitConversionService.convert(incomingStockMoveLine.getUnit(), stockLocationLine.getUnit(), incomingStockMoveLine.getRealQty(), incomingStockMoveLine.getRealQty().scale(), product);
        futureQty = futureQty.add(qtyToAdd);
    }
    for (StockMoveLine outgoingStockMoveLine : outgoingStockMoveLineList) {
        BigDecimal qtyToSubtract = unitConversionService.convert(outgoingStockMoveLine.getUnit(), stockLocationLine.getUnit(), outgoingStockMoveLine.getRealQty(), outgoingStockMoveLine.getRealQty().scale(), product);
        futureQty = futureQty.subtract(qtyToSubtract);
    }
    return futureQty;
}
Also used : AxelorException(com.axelor.exception.AxelorException) Product(com.axelor.apps.base.db.Product) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) BigDecimal(java.math.BigDecimal)

Example 13 with Product

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

the class ProductStockRepository method copy.

@Override
public Product copy(Product product, boolean deep) {
    Product copy = super.copy(product, deep);
    copy.setAvgPrice(BigDecimal.ZERO);
    return copy;
}
Also used : Product(com.axelor.apps.base.db.Product)

Example 14 with Product

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

the class ProductStockRepository method setAvailableQty.

@SuppressWarnings({ "unchecked", "rawtypes" })
private void setAvailableQty(Map<String, Object> json, Map<String, Object> context) {
    try {
        Long productId = (Long) json.get("id");
        Product product = find(productId);
        if (context.get("_parent") != null) {
            Map<String, Object> _parent = (Map<String, Object>) context.get("_parent");
            StockLocation stockLocation = null;
            if (context.get("_model").toString().equals("com.axelor.apps.stock.db.StockMoveLine")) {
                if (_parent.get("fromStockLocation") != null) {
                    stockLocation = stockLocationRepo.find(Long.parseLong(((Map) _parent.get("fromStockLocation")).get("id").toString()));
                }
            } else {
                if (_parent.get("stockLocation") != null) {
                    stockLocation = stockLocationRepo.find(Long.parseLong(((Map) _parent.get("stockLocation")).get("id").toString()));
                }
            }
            if (stockLocation != null) {
                BigDecimal availableQty = stockLocationLineService.getAvailableQty(stockLocation, product);
                json.put("$availableQty", availableQty);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : StockLocation(com.axelor.apps.stock.db.StockLocation) Product(com.axelor.apps.base.db.Product) Map(java.util.Map) BigDecimal(java.math.BigDecimal)

Example 15 with Product

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

the class PartnerSaleController method displayValues.

public void displayValues(ActionRequest request, ActionResponse response) {
    Partner customer = request.getContext().asType(Partner.class);
    try {
        customer = Beans.get(PartnerRepository.class).find(customer.getId());
        SortedSet<Map<String, Object>> saleDetailsByProduct = new TreeSet<Map<String, Object>>(Comparator.comparing(m -> (String) m.get("name")));
        PartnerSaleService partnerSaleService = Beans.get(PartnerSaleService.class);
        List<Product> productList = partnerSaleService.getProductBoughtByCustomer(customer);
        if (productList.isEmpty()) {
            response.setAttr("$saleDetailsByProduct", "hidden", true);
            return;
        }
        response.setAttr("$saleDetailsByProduct", "hidden", false);
        HashMap<String, BigDecimal> qtyAndPrice;
        for (Product product : productList) {
            qtyAndPrice = partnerSaleService.getTotalSaleQuantityAndPrice(customer, product);
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("name", product.getName());
            map.put("$quantitySold", qtyAndPrice.get("qty"));
            map.put("$totalPrice", qtyAndPrice.get("price"));
            map.put("$averagePrice", qtyAndPrice.get("price").divide(qtyAndPrice.get("qty"), AppBaseService.DEFAULT_NB_DECIMAL_DIGITS, RoundingMode.HALF_EVEN));
            saleDetailsByProduct.add(map);
        }
        response.setValue("$saleDetailsByProduct", saleDetailsByProduct);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : SortedSet(java.util.SortedSet) TraceBackService(com.axelor.exception.service.TraceBackService) PartnerRepository(com.axelor.apps.base.db.repo.PartnerRepository) HashMap(java.util.HashMap) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) TreeSet(java.util.TreeSet) PartnerSaleService(com.axelor.apps.sale.service.PartnerSaleService) BigDecimal(java.math.BigDecimal) List(java.util.List) Beans(com.axelor.inject.Beans) Product(com.axelor.apps.base.db.Product) ActionResponse(com.axelor.rpc.ActionResponse) Map(java.util.Map) ActionRequest(com.axelor.rpc.ActionRequest) Comparator(java.util.Comparator) Partner(com.axelor.apps.base.db.Partner) Context(com.axelor.rpc.Context) Singleton(com.google.inject.Singleton) RoundingMode(java.math.RoundingMode) HashMap(java.util.HashMap) Product(com.axelor.apps.base.db.Product) BigDecimal(java.math.BigDecimal) TreeSet(java.util.TreeSet) PartnerSaleService(com.axelor.apps.sale.service.PartnerSaleService) Partner(com.axelor.apps.base.db.Partner) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Product (com.axelor.apps.base.db.Product)189 BigDecimal (java.math.BigDecimal)91 AxelorException (com.axelor.exception.AxelorException)70 Transactional (com.google.inject.persist.Transactional)45 ArrayList (java.util.ArrayList)38 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)33 Company (com.axelor.apps.base.db.Company)24 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)24 Unit (com.axelor.apps.base.db.Unit)23 ProductRepository (com.axelor.apps.base.db.repo.ProductRepository)23 HashMap (java.util.HashMap)20 BillOfMaterial (com.axelor.apps.production.db.BillOfMaterial)19 StockLocation (com.axelor.apps.stock.db.StockLocation)19 List (java.util.List)19 ProdProduct (com.axelor.apps.production.db.ProdProduct)18 StockLocationLine (com.axelor.apps.stock.db.StockLocationLine)18 LocalDate (java.time.LocalDate)18 PurchaseOrderLine (com.axelor.apps.purchase.db.PurchaseOrderLine)16 StockMove (com.axelor.apps.stock.db.StockMove)16 Map (java.util.Map)16