use of com.axelor.apps.base.db.Unit 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;
}
use of com.axelor.apps.base.db.Unit in project axelor-open-suite by axelor.
the class PurchaseOrderStockServiceImpl method createProductStockMoveLine.
protected StockMoveLine createProductStockMoveLine(PurchaseOrderLine purchaseOrderLine, BigDecimal qty, StockMove stockMove) throws AxelorException {
PurchaseOrder purchaseOrder = purchaseOrderLine.getPurchaseOrder();
Product product = purchaseOrderLine.getProduct();
Unit unit = product.getUnit();
BigDecimal priceDiscounted = purchaseOrderLine.getPriceDiscounted();
BigDecimal companyUnitPriceUntaxed = purchaseOrderLine.getCompanyExTaxTotal();
if (purchaseOrderLine.getQty().compareTo(BigDecimal.ZERO) != 0) {
companyUnitPriceUntaxed = purchaseOrderLine.getCompanyExTaxTotal().divide(purchaseOrderLine.getQty(), appBaseService.getNbDecimalDigitForUnitPrice(), RoundingMode.HALF_UP);
}
if (unit != null && !unit.equals(purchaseOrderLine.getUnit())) {
qty = unitConversionService.convert(purchaseOrderLine.getUnit(), unit, qty, qty.scale(), product);
priceDiscounted = unitConversionService.convert(unit, purchaseOrderLine.getUnit(), priceDiscounted, appBaseService.getNbDecimalDigitForUnitPrice(), product);
companyUnitPriceUntaxed = unitConversionService.convert(unit, purchaseOrderLine.getUnit(), companyUnitPriceUntaxed, appBaseService.getNbDecimalDigitForUnitPrice(), product);
}
BigDecimal shippingCoef = shippingCoefService.getShippingCoef(product, purchaseOrder.getSupplierPartner(), purchaseOrder.getCompany(), qty);
BigDecimal companyPurchasePrice = priceDiscounted;
priceDiscounted = priceDiscounted.multiply(shippingCoef);
companyUnitPriceUntaxed = companyUnitPriceUntaxed.multiply(shippingCoef);
BigDecimal taxRate = BigDecimal.ZERO;
TaxLine taxLine = purchaseOrderLine.getTaxLine();
if (taxLine != null) {
taxRate = taxLine.getValue();
}
if (purchaseOrderLine.getReceiptState() == 0) {
purchaseOrderLine.setReceiptState(PurchaseOrderLineRepository.RECEIPT_STATE_NOT_RECEIVED);
}
return stockMoveLineServiceSupplychain.createStockMoveLine(product, purchaseOrderLine.getProductName(), purchaseOrderLine.getDescription(), qty, BigDecimal.ZERO, priceDiscounted, companyUnitPriceUntaxed, companyPurchasePrice, unit, stockMove, StockMoveLineService.TYPE_PURCHASES, purchaseOrder.getInAti(), taxRate, null, purchaseOrderLine);
}
use of com.axelor.apps.base.db.Unit in project axelor-open-suite by axelor.
the class ProductStockLocationServiceImpl method getRequestedReservedQty.
protected BigDecimal getRequestedReservedQty(Product product, Company company, StockLocation stockLocation) throws AxelorException {
if (product == null || product.getUnit() == null) {
return BigDecimal.ZERO;
}
Long companyId = 0L;
Long stockLocationId = 0L;
if (company != null) {
companyId = company.getId();
}
if (stockLocation != null) {
stockLocationId = stockLocation.getId();
}
String query = stockLocationLineService.getStockLocationLineListForAProduct(product.getId(), companyId, stockLocationId);
List<StockLocationLine> stockLocationLineList = stockLocationLineRepository.all().filter(query).fetch();
// Compute
BigDecimal sumRequestedReservedQty = BigDecimal.ZERO;
if (!stockLocationLineList.isEmpty()) {
Unit unitConversion = product.getUnit();
for (StockLocationLine stockLocationLine : stockLocationLineList) {
BigDecimal requestedReservedQty = stockLocationLine.getRequestedReservedQty();
requestedReservedQty = unitConversionService.convert(stockLocationLine.getUnit(), unitConversion, requestedReservedQty, requestedReservedQty.scale(), product);
sumRequestedReservedQty = sumRequestedReservedQty.add(requestedReservedQty);
}
}
return sumRequestedReservedQty;
}
use of com.axelor.apps.base.db.Unit in project axelor-open-suite by axelor.
the class ProductStockLocationServiceImpl method getSaleOrderQty.
protected BigDecimal getSaleOrderQty(Product product, Company company, StockLocation stockLocation) throws AxelorException {
if (product == null || product.getUnit() == null) {
return BigDecimal.ZERO;
}
Long companyId = 0L;
Long stockLocationId = 0L;
if (company != null) {
companyId = company.getId();
}
if (stockLocation != null) {
stockLocationId = stockLocation.getId();
}
String query = Beans.get(SaleOrderLineServiceSupplyChain.class).getSaleOrderLineListForAProduct(product.getId(), companyId, stockLocationId);
List<SaleOrderLine> saleOrderLineList = Beans.get(SaleOrderLineRepository.class).all().filter(query).fetch();
// Compute
BigDecimal sumSaleOrderQty = BigDecimal.ZERO;
if (!saleOrderLineList.isEmpty()) {
Unit unitConversion = product.getUnit();
for (SaleOrderLine saleOrderLine : saleOrderLineList) {
BigDecimal productSaleOrderQty = saleOrderLine.getQty();
if (saleOrderLine.getDeliveryState() == SaleOrderLineRepository.DELIVERY_STATE_PARTIALLY_DELIVERED) {
productSaleOrderQty = productSaleOrderQty.subtract(saleOrderLine.getDeliveredQty());
}
productSaleOrderQty = unitConversionService.convert(saleOrderLine.getUnit(), unitConversion, productSaleOrderQty, productSaleOrderQty.scale(), product);
sumSaleOrderQty = sumSaleOrderQty.add(productSaleOrderQty);
}
}
return sumSaleOrderQty;
}
use of com.axelor.apps.base.db.Unit in project axelor-open-suite by axelor.
the class ProductStockLocationServiceImpl method getPurchaseOrderQty.
protected BigDecimal getPurchaseOrderQty(Product product, Company company, StockLocation stockLocation) throws AxelorException {
if (product == null || product.getUnit() == null) {
return BigDecimal.ZERO;
}
Long companyId = 0L;
Long stockLocationId = 0L;
if (company != null) {
companyId = company.getId();
}
if (stockLocation != null) {
stockLocationId = stockLocation.getId();
}
String query = Beans.get(PurchaseOrderStockService.class).getPurchaseOrderLineListForAProduct(product.getId(), companyId, stockLocationId);
List<PurchaseOrderLine> purchaseOrderLineList = Beans.get(PurchaseOrderLineRepository.class).all().filter(query).fetch();
// Compute
BigDecimal sumPurchaseOrderQty = BigDecimal.ZERO;
if (!purchaseOrderLineList.isEmpty()) {
Unit unitConversion = product.getUnit();
for (PurchaseOrderLine purchaseOrderLine : purchaseOrderLineList) {
BigDecimal productPurchaseOrderQty = purchaseOrderLine.getQty();
if (purchaseOrderLine.getReceiptState() == PurchaseOrderLineRepository.RECEIPT_STATE_PARTIALLY_RECEIVED) {
productPurchaseOrderQty = productPurchaseOrderQty.subtract(purchaseOrderLine.getReceivedQty());
}
productPurchaseOrderQty = unitConversionService.convert(purchaseOrderLine.getUnit(), unitConversion, productPurchaseOrderQty, productPurchaseOrderQty.scale(), product);
sumPurchaseOrderQty = sumPurchaseOrderQty.add(productPurchaseOrderQty);
}
}
return sumPurchaseOrderQty;
}
Aggregations