use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.
the class PurchaseOrderStockServiceImpl method needControlOnReceipt.
/**
* @param product
* @param purchaseOrder
* @return true if product needs a control on receipt and if the purchase order is not a direct
* order
*/
protected boolean needControlOnReceipt(PurchaseOrderLine purchaseOrderLine) {
Product product = purchaseOrderLine.getProduct();
PurchaseOrder purchaseOrder = purchaseOrderLine.getPurchaseOrder();
if (product.getControlOnReceipt() && !purchaseOrder.getStockLocation().getDirectOrderLocation()) {
return true;
}
return false;
}
use of com.axelor.apps.base.db.Product 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.Product in project axelor-open-suite by axelor.
the class AccountingCutOffServiceImpl method getStockMoveLines.
public List<Long> getStockMoveLines(Batch batch) {
int offset = 0;
Boolean includeNotStockManagedProduct = batch.getSupplychainBatch().getIncludeNotStockManagedProduct();
List<StockMoveLine> stockMoveLineList;
List<Long> stockMoveLineIdList = new ArrayList<>();
Query<StockMove> stockMoveQuery = stockMoverepository.all().filter(":batch MEMBER OF self.batchSet").bind("batch", batch);
List<Long> stockMoveIdList = stockMoveQuery.select("id").fetch(0, 0).stream().map(m -> (Long) m.get("id")).collect(Collectors.toList());
if (stockMoveIdList.isEmpty()) {
stockMoveLineIdList.add(0L);
} else {
Query<StockMoveLine> stockMoveLineQuery = stockMoveLineRepository.all().filter("self.stockMove.id IN :stockMoveIdList").bind("stockMoveIdList", stockMoveIdList).order("id");
while (!(stockMoveLineList = stockMoveLineQuery.fetch(FETCH_LIMIT, offset)).isEmpty()) {
offset += stockMoveLineList.size();
for (StockMoveLine stockMoveLine : stockMoveLineList) {
Product product = stockMoveLine.getProduct();
if (!checkStockMoveLine(stockMoveLine, product, includeNotStockManagedProduct)) {
stockMoveLineIdList.add(stockMoveLine.getId());
}
}
JPA.clear();
}
}
return stockMoveLineIdList;
}
use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.
the class AccountingCutOffServiceImpl method generateProductMoveLine.
protected MoveLine generateProductMoveLine(Move move, StockMoveLine stockMoveLine, String origin, boolean isPurchase, boolean recoveredTax, boolean ati, String moveDescription, boolean isReverse, LocalDate originDate) throws AxelorException {
SaleOrderLine saleOrderLine = stockMoveLine.getSaleOrderLine();
PurchaseOrderLine purchaseOrderLine = stockMoveLine.getPurchaseOrderLine();
Company company = move.getCompany();
LocalDate moveDate = move.getDate();
Partner partner = move.getPartner();
boolean isFixedAssets = false;
BigDecimal amountInCurrency = null;
BigDecimal totalQty = null;
BigDecimal notInvoicedQty = null;
if (isPurchase && purchaseOrderLine != null) {
totalQty = purchaseOrderLine.getQty();
notInvoicedQty = unitConversionService.convert(stockMoveLine.getUnit(), purchaseOrderLine.getUnit(), stockMoveLine.getRealQty().subtract(stockMoveLine.getQtyInvoiced()), stockMoveLine.getRealQty().scale(), purchaseOrderLine.getProduct());
isFixedAssets = purchaseOrderLine.getFixedAssets();
if (ati && !recoveredTax) {
amountInCurrency = purchaseOrderLine.getInTaxTotal();
} else {
amountInCurrency = purchaseOrderLine.getExTaxTotal();
}
}
if (!isPurchase && saleOrderLine != null) {
totalQty = saleOrderLine.getQty();
notInvoicedQty = unitConversionService.convert(stockMoveLine.getUnit(), saleOrderLine.getUnit(), stockMoveLine.getRealQty().subtract(stockMoveLine.getQtyInvoiced()), stockMoveLine.getRealQty().scale(), saleOrderLine.getProduct());
if (ati) {
amountInCurrency = saleOrderLine.getInTaxTotal();
} else {
amountInCurrency = saleOrderLine.getExTaxTotal();
}
}
if (totalQty == null || BigDecimal.ZERO.compareTo(totalQty) == 0) {
return null;
}
BigDecimal qtyRate = notInvoicedQty.divide(totalQty, 10, RoundingMode.HALF_UP);
amountInCurrency = amountInCurrency.multiply(qtyRate).setScale(2, RoundingMode.HALF_UP);
if (amountInCurrency == null || amountInCurrency.compareTo(BigDecimal.ZERO) == 0) {
return null;
}
Product product = stockMoveLine.getProduct();
Account account = accountManagementAccountService.getProductAccount(product, company, partner.getFiscalPosition(), isPurchase, isFixedAssets);
boolean isDebit = false;
if ((isPurchase && amountInCurrency.compareTo(BigDecimal.ZERO) == 1) || !isPurchase && amountInCurrency.compareTo(BigDecimal.ZERO) == -1) {
isDebit = true;
}
if (isReverse) {
isDebit = !isDebit;
}
MoveLine moveLine = moveLineService.createMoveLine(move, partner, account, amountInCurrency, isDebit, originDate, ++counter, origin, moveDescription);
moveLine.setDate(moveDate);
moveLine.setDueDate(moveDate);
getAndComputeAnalyticDistribution(product, move, moveLine);
move.addMoveLineListItem(moveLine);
if (recoveredTax) {
TaxLine taxLine = accountManagementAccountService.getTaxLine(originDate, product, company, partner.getFiscalPosition(), isPurchase);
if (taxLine != null) {
moveLine.setTaxLine(taxLine);
moveLine.setTaxRate(taxLine.getValue());
moveLine.setTaxCode(taxLine.getTax().getCode());
if (taxLine.getValue().compareTo(BigDecimal.ZERO) != 0) {
generateTaxMoveLine(move, moveLine, origin, isPurchase, isFixedAssets, moveDescription);
}
}
}
return moveLine;
}
use of com.axelor.apps.base.db.Product in project axelor-open-suite by axelor.
the class ProductStockLocationServiceImpl method computeIndicators.
@Override
public Map<String, Object> computeIndicators(Long productId, Long companyId, Long stockLocationId) throws AxelorException {
Map<String, Object> map = new HashMap<>();
Product product = productRepository.find(productId);
Company company = companyRepository.find(companyId);
StockLocation stockLocation = stockLocationRepository.find(stockLocationId);
int scale = appBaseService.getNbDecimalDigitForQty();
if (stockLocationId != 0L && companyId != 0L) {
List<StockLocation> stockLocationList = stockLocationService.getAllLocationAndSubLocation(stockLocation, false);
if (!stockLocationList.isEmpty()) {
BigDecimal realQty = BigDecimal.ZERO;
BigDecimal futureQty = BigDecimal.ZERO;
BigDecimal reservedQty = BigDecimal.ZERO;
BigDecimal requestedReservedQty = BigDecimal.ZERO;
BigDecimal saleOrderQty = BigDecimal.ZERO;
BigDecimal purchaseOrderQty = BigDecimal.ZERO;
BigDecimal availableQty = BigDecimal.ZERO;
saleOrderQty = this.getSaleOrderQty(product, company, stockLocation);
purchaseOrderQty = this.getPurchaseOrderQty(product, company, stockLocation);
availableQty = this.getAvailableQty(product, company, stockLocation);
requestedReservedQty = this.getRequestedReservedQty(product, company, stockLocation);
for (StockLocation sl : stockLocationList) {
realQty = realQty.add(stockLocationService.getRealQty(productId, sl.getId(), companyId));
futureQty = futureQty.add(stockLocationService.getFutureQty(productId, sl.getId(), companyId));
reservedQty = reservedQty.add(stockLocationServiceSupplychain.getReservedQty(productId, sl.getId(), companyId));
}
map.put("$realQty", realQty.setScale(scale, RoundingMode.HALF_UP));
map.put("$futureQty", futureQty.setScale(scale, RoundingMode.HALF_UP));
map.put("$reservedQty", reservedQty.setScale(scale, RoundingMode.HALF_UP));
map.put("$requestedReservedQty", requestedReservedQty.setScale(scale, RoundingMode.HALF_UP));
map.put("$saleOrderQty", saleOrderQty.setScale(scale, RoundingMode.HALF_UP));
map.put("$purchaseOrderQty", purchaseOrderQty.setScale(scale, RoundingMode.HALF_UP));
map.put("$availableQty", availableQty.subtract(reservedQty).setScale(scale, RoundingMode.HALF_UP));
return map;
}
}
BigDecimal reservedQty = stockLocationServiceSupplychain.getReservedQty(productId, stockLocationId, companyId).setScale(scale, RoundingMode.HALF_UP);
map.put("$realQty", stockLocationService.getRealQty(productId, stockLocationId, companyId).setScale(scale, RoundingMode.HALF_UP));
map.put("$futureQty", stockLocationService.getFutureQty(productId, stockLocationId, companyId).setScale(scale, RoundingMode.HALF_UP));
map.put("$reservedQty", reservedQty);
map.put("$requestedReservedQty", this.getRequestedReservedQty(product, company, null).setScale(scale, RoundingMode.HALF_UP));
map.put("$saleOrderQty", this.getSaleOrderQty(product, company, null).setScale(scale, RoundingMode.HALF_UP));
map.put("$purchaseOrderQty", this.getPurchaseOrderQty(product, company, null).setScale(scale, RoundingMode.HALF_UP));
map.put("$availableQty", this.getAvailableQty(product, company, null).subtract(reservedQty).setScale(scale, RoundingMode.HALF_UP));
return map;
}
Aggregations