use of com.axelor.apps.sale.db.SaleOrder in project axelor-open-suite by axelor.
the class WorkflowCancelServiceSupplychainImpl method saleOrderProcess.
public void saleOrderProcess(Invoice invoice) throws AxelorException {
SaleOrder invoiceSaleOrder = invoice.getSaleOrder();
if (invoiceSaleOrder != null) {
log.debug("Update the invoiced amount of the sale order : {}", invoiceSaleOrder.getSaleOrderSeq());
invoiceSaleOrder.setAmountInvoiced(saleOrderInvoiceService.getInvoicedAmount(invoiceSaleOrder, invoice.getId(), true));
} else {
// Get all different saleOrders from invoice
List<SaleOrder> saleOrderList = Lists.newArrayList();
for (InvoiceLine invoiceLine : invoice.getInvoiceLineList()) {
SaleOrder saleOrder = this.saleOrderLineProcess(invoice, invoiceLine);
if (saleOrder != null && !saleOrderList.contains(saleOrder)) {
saleOrderList.add(saleOrder);
}
}
for (SaleOrder saleOrder : saleOrderList) {
log.debug("Update the invoiced amount of the sale order : {}", saleOrder.getSaleOrderSeq());
saleOrder.setAmountInvoiced(saleOrderInvoiceService.getInvoicedAmount(saleOrder, invoice.getId(), true));
saleOrderRepository.save(saleOrder);
}
}
}
use of com.axelor.apps.sale.db.SaleOrder in project axelor-open-suite by axelor.
the class WorkflowVentilationServiceSupplychainImpl method saleOrderLineProcess.
private SaleOrder saleOrderLineProcess(Invoice invoice, InvoiceLine invoiceLine) throws AxelorException {
SaleOrderLine saleOrderLine = invoiceLine.getSaleOrderLine();
if (saleOrderLine == null) {
return null;
}
SaleOrder saleOrder = saleOrderLine.getSaleOrder();
// Update invoiced amount on sale order line
BigDecimal invoicedAmountToAdd = invoiceLine.getExTaxTotal();
// If is it a refund invoice, so we negate the amount invoiced
if (InvoiceToolService.isRefund(invoiceLine.getInvoice())) {
invoicedAmountToAdd = invoicedAmountToAdd.negate();
}
if (!invoice.getCurrency().equals(saleOrder.getCurrency()) && saleOrderLine.getCompanyExTaxTotal().compareTo(BigDecimal.ZERO) != 0) {
// If the sale order currency is different from the invoice currency, use company currency to
// calculate a rate. This rate will be applied to sale order line
BigDecimal currentCompanyInvoicedAmount = invoiceLine.getCompanyExTaxTotal();
BigDecimal rate = currentCompanyInvoicedAmount.divide(saleOrderLine.getCompanyExTaxTotal(), 4, RoundingMode.HALF_UP);
invoicedAmountToAdd = rate.multiply(saleOrderLine.getExTaxTotal());
}
saleOrderLine.setAmountInvoiced(saleOrderLine.getAmountInvoiced().add(invoicedAmountToAdd));
return saleOrder;
}
use of com.axelor.apps.sale.db.SaleOrder in project axelor-open-suite by axelor.
the class BatchOrderInvoicingSale method process.
@Override
protected void process() {
SupplychainBatch supplychainBatch = batch.getSupplychainBatch();
List<String> filterList = new ArrayList<>();
Query<SaleOrder> query = Beans.get(SaleOrderRepository.class).all();
if (supplychainBatch.getCompany() != null) {
filterList.add("self.company = :company");
query.bind("company", supplychainBatch.getCompany());
}
if (supplychainBatch.getSalespersonOrBuyerSet() != null && !supplychainBatch.getSalespersonOrBuyerSet().isEmpty()) {
filterList.add("self.salespersonUser IN (:salespersonSet)");
query.bind("salespersonSet", supplychainBatch.getSalespersonOrBuyerSet());
}
if (supplychainBatch.getTeam() != null) {
filterList.add("self.team = :team " + "OR self.team IS NULL AND self.salespersonUser IS NOT NULL AND self.salespersonUser.activeTeam = :team");
query.bind("team", supplychainBatch.getTeam());
}
if (!Strings.isNullOrEmpty(supplychainBatch.getDeliveryOrReceiptState())) {
List<Integer> delivereyStateList = StringTool.getIntegerList(supplychainBatch.getDeliveryOrReceiptState());
filterList.add("self.deliveryState IN (:delivereyStateList)");
query.bind("delivereyStateList", delivereyStateList);
}
if (!Strings.isNullOrEmpty(supplychainBatch.getStatusSelect())) {
List<Integer> statusSelectList = StringTool.getIntegerList(supplychainBatch.getStatusSelect());
filterList.add("self.statusSelect IN (:statusSelectList)");
query.bind("statusSelectList", statusSelectList);
}
if (supplychainBatch.getOrderUpToDate() != null) {
filterList.add("self.orderDate <= :orderUpToDate");
query.bind("orderUpToDate", supplychainBatch.getOrderUpToDate());
}
filterList.add("self.amountInvoiced < self.exTaxTotal");
filterList.add("NOT EXISTS (SELECT 1 FROM Invoice invoice WHERE invoice.statusSelect != :invoiceStatusSelect " + "AND (invoice.saleOrder = self " + "OR invoice.saleOrder IS NULL AND EXISTS (SELECT 1 FROM invoice.invoiceLineList invoiceLine " + "WHERE invoiceLine.saleOrderLine MEMBER OF self.saleOrderLineList)))");
filterList.add("self.clientPartner.id NOT IN (" + Beans.get(BlockingService.class).listOfBlockedPartner(supplychainBatch.getCompany(), BlockingRepository.INVOICING_BLOCKING) + ")");
query.bind("invoiceStatusSelect", InvoiceRepository.STATUS_CANCELED);
List<Long> anomalyList = Lists.newArrayList(0L);
filterList.add("self.id NOT IN (:anomalyList)");
query.bind("anomalyList", anomalyList);
String filter = filterList.stream().map(item -> String.format("(%s)", item)).collect(Collectors.joining(" AND "));
query.filter(filter);
SaleOrderInvoiceService saleOrderInvoiceService = Beans.get(SaleOrderInvoiceService.class);
Set<Long> treatedSet = new HashSet<>();
for (List<SaleOrder> saleOrderList; !(saleOrderList = query.fetch(FETCH_LIMIT)).isEmpty(); JPA.clear()) {
for (SaleOrder saleOrder : saleOrderList) {
if (treatedSet.contains(saleOrder.getId())) {
throw new IllegalArgumentException("Invoice generation error");
}
treatedSet.add(saleOrder.getId());
try {
saleOrderInvoiceService.generateInvoice(saleOrder);
incrementDone();
} catch (Exception e) {
incrementAnomaly();
anomalyList.add(saleOrder.getId());
query.bind("anomalyList", anomalyList);
TraceBackService.trace(e, ExceptionOriginRepository.INVOICE_ORIGIN, batch.getId());
e.printStackTrace();
break;
}
}
}
}
use of com.axelor.apps.sale.db.SaleOrder in project axelor-open-suite by axelor.
the class StockMoveServiceSupplychainImpl method updateSaleOrderOnCancel.
@Transactional(rollbackOn = { Exception.class })
public void updateSaleOrderOnCancel(StockMove stockMove) throws AxelorException {
SaleOrder so = saleOrderRepo.find(stockMove.getOriginId());
updateSaleOrderLinesDeliveryState(stockMove, stockMove.getIsReversion());
Beans.get(SaleOrderStockService.class).updateDeliveryState(so);
if (Beans.get(AppSupplychainService.class).getAppSupplychain().getTerminateSaleOrderOnDelivery()) {
terminateOrConfirmSaleOrderStatus(so);
}
}
use of com.axelor.apps.sale.db.SaleOrder in project axelor-open-suite by axelor.
the class TimetableServiceImpl method createInvoice.
@Override
public Invoice createInvoice(Timetable timetable) throws AxelorException {
SaleOrder saleOrder = timetable.getSaleOrder();
PurchaseOrder purchaseOrder = timetable.getPurchaseOrder();
if (saleOrder != null) {
if (saleOrder.getCurrency() == null) {
throw new AxelorException(timetable, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.SO_INVOICE_6), saleOrder.getSaleOrderSeq());
}
List<Long> timetableId = new ArrayList<>();
timetableId.add(timetable.getId());
Invoice invoice = saleOrderInvoiceService.generateInvoice(saleOrder, SaleOrderRepository.INVOICE_TIMETABLES, BigDecimal.ZERO, true, null, timetableId);
return invoice;
}
if (purchaseOrder != null) {
if (purchaseOrder.getCurrency() == null) {
throw new AxelorException(timetable, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.SO_INVOICE_6), purchaseOrder.getPurchaseOrderSeq());
}
List<Long> timetableId = new ArrayList<>();
timetableId.add(timetable.getId());
return Beans.get(PurchaseOrderInvoiceServiceImpl.class).generateInvoiceFromTimetableForPurchaseOrder(purchaseOrder, timetableId);
}
return null;
}
Aggregations