use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.
the class BudgetSupplychainService method updateBudgetLinesFromPurchaseOrder.
public void updateBudgetLinesFromPurchaseOrder(PurchaseOrder purchaseOrder) {
List<PurchaseOrderLine> purchaseOrderLineList = purchaseOrder.getPurchaseOrderLineList();
if (purchaseOrderLineList == null) {
return;
}
purchaseOrderLineList.stream().flatMap(x -> x.getBudgetDistributionList().stream()).forEach(budgetDistribution -> {
Budget budget = budgetDistribution.getBudget();
updateLines(budget);
computeTotalAmountCommitted(budget);
});
}
use of com.axelor.apps.purchase.db.PurchaseOrderLine 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.purchase.db.PurchaseOrderLine 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;
}
use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.
the class PurchaseOrderLineProjectController method updateAnalyticDistributionWithProject.
public void updateAnalyticDistributionWithProject(ActionRequest request, ActionResponse response) throws AxelorException {
try {
PurchaseOrderLine purchaseOrderLine = request.getContext().asType(PurchaseOrderLine.class);
if (purchaseOrderLine.getAnalyticMoveLineList() == null) {
return;
}
purchaseOrderLine = Beans.get(PurchaseOrderLineProjectService.class).updateAnalyticDistributionWithProject(purchaseOrderLine);
response.setValue("analyticMoveLineList", purchaseOrderLine.getAnalyticMoveLineList());
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.
the class PurchaseOrderLineProjectController method updateToInvoice.
/**
* Invert value of 'toInvoice' field and save the record
*
* @param request
* @param response
*/
@Transactional
public void updateToInvoice(ActionRequest request, ActionResponse response) {
PurchaseOrderLineRepository purchaseOrderLineRepository = Beans.get(PurchaseOrderLineRepository.class);
try {
PurchaseOrderLine purchaseOrderLine = request.getContext().asType(PurchaseOrderLine.class);
purchaseOrderLine = purchaseOrderLineRepository.find(purchaseOrderLine.getId());
purchaseOrderLine.setToInvoice(!purchaseOrderLine.getToInvoice());
purchaseOrderLineRepository.save(purchaseOrderLine);
response.setValue("toInvoice", purchaseOrderLine.getToInvoice());
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
Aggregations