use of com.axelor.apps.supplychain.db.SupplychainBatch in project axelor-open-suite by axelor.
the class SupplychainBatchSupplychainRepository method copy.
@Override
public SupplychainBatch copy(SupplychainBatch entity, boolean deep) {
SupplychainBatch copy = super.copy(entity, deep);
copy.setBatchList(null);
return copy;
}
use of com.axelor.apps.supplychain.db.SupplychainBatch 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.supplychain.db.SupplychainBatch in project axelor-open-suite by axelor.
the class SupplychainBatchService method run.
@Override
public Batch run(Model batchModel) throws AxelorException {
Batch batch;
SupplychainBatch supplychainBatch = (SupplychainBatch) batchModel;
switch(supplychainBatch.getActionSelect()) {
case SupplychainBatchRepository.ACTION_ACCOUNTING_CUT_OFF:
batch = accountingCutOff(supplychainBatch);
break;
case SupplychainBatchRepository.ACTION_INVOICE_OUTGOING_STOCK_MOVES:
batch = invoiceOutgoingStockMoves(supplychainBatch);
break;
case SupplychainBatchRepository.ACTION_INVOICE_ORDERS:
batch = invoiceOrders(supplychainBatch);
break;
default:
throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.BASE_BATCH_1), supplychainBatch.getActionSelect(), supplychainBatch.getCode());
}
return batch;
}
use of com.axelor.apps.supplychain.db.SupplychainBatch in project axelor-open-suite by axelor.
the class BatchAccountingCutOff method process.
@Override
protected void process() {
int offset = 0;
SupplychainBatch supplychainBatch = batch.getSupplychainBatch();
LocalDate moveDate = supplychainBatch.getMoveDate();
LocalDate reverseMoveDate = supplychainBatch.getReverseMoveDate();
boolean recoveredTax = supplychainBatch.getRecoveredTax();
boolean ati = supplychainBatch.getAti();
String moveDescription = supplychainBatch.getMoveDescription();
int accountingCutOffTypeSelect = supplychainBatch.getAccountingCutOffTypeSelect();
updateBatch(moveDate, accountingCutOffTypeSelect);
Company company = supplychainBatch.getCompany();
boolean includeNotStockManagedProduct = supplychainBatch.getIncludeNotStockManagedProduct();
if (accountingCutOffTypeSelect == 0) {
return;
}
List<StockMove> stockMoveList;
while (!(stockMoveList = cutOffService.getStockMoves(company, accountingCutOffTypeSelect, moveDate, FETCH_LIMIT, offset)).isEmpty()) {
findBatch();
for (StockMove stockMove : stockMoveList) {
++offset;
try {
List<Move> moveList = cutOffService.generateCutOffMoves(stockMove, moveDate, reverseMoveDate, accountingCutOffTypeSelect, recoveredTax, ati, moveDescription, includeNotStockManagedProduct);
if (moveList != null && !moveList.isEmpty()) {
updateStockMove(stockMove);
for (Move move : moveList) {
updateAccountMove(move, false);
}
}
} catch (AxelorException e) {
TraceBackService.trace(new AxelorException(e, e.getCategory(), I18n.get("StockMove") + " %s", stockMove.getStockMoveSeq()), ExceptionOriginRepository.INVOICE_ORIGIN, batch.getId());
incrementAnomaly();
break;
} catch (Exception e) {
TraceBackService.trace(new Exception(String.format(I18n.get("StockMove") + " %s", stockMove.getStockMoveSeq()), e), ExceptionOriginRepository.INVOICE_ORIGIN, batch.getId());
incrementAnomaly();
LOG.error("Anomaly generated for the stock move {}", stockMove.getStockMoveSeq());
break;
}
}
JPA.clear();
}
}
use of com.axelor.apps.supplychain.db.SupplychainBatch in project axelor-open-suite by axelor.
the class SupplychainBatchController method accountingCutOff.
public void accountingCutOff(ActionRequest request, ActionResponse response) {
try {
SupplychainBatch supplychainBatch = request.getContext().asType(SupplychainBatch.class);
supplychainBatch = Beans.get(SupplychainBatchRepository.class).find(supplychainBatch.getId());
Batch batch = Beans.get(SupplychainBatchService.class).accountingCutOff(supplychainBatch);
response.setFlash(batch.getComments());
response.setReload(true);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
Aggregations