use of com.axelor.apps.sale.db.SaleOrderLine in project axelor-open-suite by axelor.
the class IntercoServiceImpl method generateIntercoPurchaseFromSale.
@Override
@Transactional(rollbackOn = { Exception.class })
public PurchaseOrder generateIntercoPurchaseFromSale(SaleOrder saleOrder) throws AxelorException {
PurchaseOrderService purchaseOrderService = Beans.get(PurchaseOrderService.class);
Company intercoCompany = findIntercoCompany(saleOrder.getClientPartner());
// create purchase order
PurchaseOrder purchaseOrder = new PurchaseOrder();
purchaseOrder.setCompany(intercoCompany);
purchaseOrder.setContactPartner(saleOrder.getContactPartner());
purchaseOrder.setCurrency(saleOrder.getCurrency());
purchaseOrder.setDeliveryDate(saleOrder.getDeliveryDate());
purchaseOrder.setOrderDate(saleOrder.getCreationDate());
purchaseOrder.setPriceList(saleOrder.getPriceList());
purchaseOrder.setTradingName(saleOrder.getTradingName());
purchaseOrder.setPurchaseOrderLineList(new ArrayList<>());
purchaseOrder.setPrintingSettings(Beans.get(TradingNameService.class).getDefaultPrintingSettings(null, intercoCompany));
purchaseOrder.setStatusSelect(PurchaseOrderRepository.STATUS_DRAFT);
purchaseOrder.setSupplierPartner(saleOrder.getCompany().getPartner());
purchaseOrder.setTradingName(saleOrder.getTradingName());
// in ati
purchaseOrder.setInAti(saleOrder.getInAti());
// copy payments
PaymentMode intercoPaymentMode = Beans.get(PaymentModeService.class).reverseInOut(saleOrder.getPaymentMode());
purchaseOrder.setPaymentMode(intercoPaymentMode);
purchaseOrder.setPaymentCondition(saleOrder.getPaymentCondition());
// copy delivery info
purchaseOrder.setDeliveryDate(saleOrder.getDeliveryDate());
purchaseOrder.setStockLocation(Beans.get(StockLocationService.class).getDefaultReceiptStockLocation(intercoCompany));
purchaseOrder.setShipmentMode(saleOrder.getShipmentMode());
purchaseOrder.setFreightCarrierMode(saleOrder.getFreightCarrierMode());
// copy timetable info
purchaseOrder.setExpectedRealisationDate(saleOrder.getExpectedRealisationDate());
purchaseOrder.setAmountToBeSpreadOverTheTimetable(saleOrder.getAmountToBeSpreadOverTheTimetable());
// create lines
List<SaleOrderLine> saleOrderLineList = saleOrder.getSaleOrderLineList();
if (saleOrderLineList != null) {
for (SaleOrderLine saleOrderLine : saleOrderLineList) {
this.createIntercoPurchaseLineFromSaleLine(saleOrderLine, purchaseOrder);
}
}
purchaseOrder.setPrintingSettings(intercoCompany.getPrintingSettings());
// compute the purchase order
purchaseOrderService.computePurchaseOrder(purchaseOrder);
purchaseOrder.setCreatedByInterco(true);
Beans.get(PurchaseOrderRepository.class).save(purchaseOrder);
if (Beans.get(AppSupplychainService.class).getAppSupplychain().getIntercoPurchaseOrderCreateRequested()) {
Beans.get(PurchaseOrderService.class).requestPurchaseOrder(purchaseOrder);
}
saleOrder.setExternalReference(purchaseOrder.getPurchaseOrderSeq());
purchaseOrder.setExternalReference(saleOrder.getSaleOrderSeq());
return purchaseOrder;
}
use of com.axelor.apps.sale.db.SaleOrderLine 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.sale.db.SaleOrderLine 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.sale.db.SaleOrderLine in project axelor-open-suite by axelor.
the class SaleOrderLineProjectController method updateToInvoice.
/**
* Invert value of 'toInvoice' field and save the record
*
* @param request
* @param response
*/
@Transactional
public void updateToInvoice(ActionRequest request, ActionResponse response) {
SaleOrderLineRepository saleOrderLineRepository = Beans.get(SaleOrderLineRepository.class);
try {
SaleOrderLine saleOrderLine = request.getContext().asType(SaleOrderLine.class);
saleOrderLine = saleOrderLineRepository.find(saleOrderLine.getId());
saleOrderLine.setToInvoice(!saleOrderLine.getToInvoice());
saleOrderLineRepository.save(saleOrderLine);
response.setValue("toInvoice", saleOrderLine.getToInvoice());
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.sale.db.SaleOrderLine in project axelor-open-suite by axelor.
the class SaleOrderLineProjectController method updateAnalyticDistributionWithProject.
public void updateAnalyticDistributionWithProject(ActionRequest request, ActionResponse response) throws AxelorException {
try {
SaleOrderLine saleOrderLine = request.getContext().asType(SaleOrderLine.class);
if (saleOrderLine.getAnalyticMoveLineList() == null) {
return;
}
saleOrderLine = Beans.get(SaleOrderLineProjectService.class).updateAnalyticDistributionWithProject(saleOrderLine);
response.setValue("analyticMoveLineList", saleOrderLine.getAnalyticMoveLineList());
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
Aggregations