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);
}
}
}
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;
}
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;
}
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();
}
}
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);
}
}
Aggregations