use of com.axelor.apps.stock.db.StockMove 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.stock.db.StockMove in project axelor-open-suite by axelor.
the class LogisticalFormSupplychainServiceImpl method createLogisticalFormLine.
@Override
protected LogisticalFormLine createLogisticalFormLine(LogisticalForm logisticalForm, StockMoveLine stockMoveLine, BigDecimal qty) {
LogisticalFormLine logisticalFormLine = super.createLogisticalFormLine(logisticalForm, stockMoveLine, qty);
if (!Beans.get(AppSupplychainService.class).isApp("supplychain")) {
return logisticalFormLine;
}
StockMove stockMove = logisticalFormLine.getStockMoveLine() != null ? logisticalFormLine.getStockMoveLine().getStockMove() : null;
if (stockMove != null && stockMove.getOriginId() != null && stockMove.getOriginId() != 0 && stockMove.getOriginTypeSelect().equals(StockMoveRepository.ORIGIN_SALE_ORDER)) {
logisticalFormLine.setSaleOrder(Beans.get(SaleOrderRepository.class).find(stockMove.getOriginId()));
}
return logisticalFormLine;
}
use of com.axelor.apps.stock.db.StockMove in project axelor-open-suite by axelor.
the class ReservedQtyServiceImpl method consolidateReservedQtyInStockMoveLineByProduct.
@Override
public void consolidateReservedQtyInStockMoveLineByProduct(StockMove stockMove) {
if (stockMove.getStockMoveLineList() == null) {
return;
}
List<Product> productList = stockMove.getStockMoveLineList().stream().map(StockMoveLine::getProduct).filter(Objects::nonNull).filter(Product::getStockManaged).distinct().collect(Collectors.toList());
for (Product product : productList) {
if (product != null) {
List<StockMoveLine> stockMoveLineListToConsolidate = stockMove.getStockMoveLineList().stream().filter(stockMoveLine1 -> product.equals(stockMoveLine1.getProduct())).collect(Collectors.toList());
if (stockMoveLineListToConsolidate.size() > 1) {
stockMoveLineListToConsolidate.sort(Comparator.comparing(StockMoveLine::getId));
BigDecimal reservedQtySum = stockMoveLineListToConsolidate.stream().map(StockMoveLine::getReservedQty).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
stockMoveLineListToConsolidate.forEach(toConsolidateStockMoveLine -> toConsolidateStockMoveLine.setReservedQty(BigDecimal.ZERO));
stockMoveLineListToConsolidate.get(0).setReservedQty(reservedQtySum);
}
}
}
}
use of com.axelor.apps.stock.db.StockMove in project axelor-open-suite by axelor.
the class AccountingCutOffServiceImpl method generateCutOffMove.
public Move generateCutOffMove(StockMove stockMove, List<StockMoveLine> sortedStockMoveLine, LocalDate moveDate, LocalDate originDate, boolean isPurchase, boolean recoveredTax, boolean ati, String moveDescription, boolean includeNotStockManagedProduct, boolean isReverse) throws AxelorException {
if (moveDate == null || stockMove.getOriginTypeSelect() == null || stockMove.getOriginId() == null) {
return null;
}
Company company = stockMove.getCompany();
AccountConfig accountConfig = accountConfigSupplychainService.getAccountConfig(company);
Partner partner = stockMove.getPartner();
Account partnerAccount = null;
Currency currency = null;
if (StockMoveRepository.ORIGIN_SALE_ORDER.equals(stockMove.getOriginTypeSelect()) && stockMove.getOriginId() != null) {
SaleOrder saleOrder = saleOrderRepository.find(stockMove.getOriginId());
currency = saleOrder.getCurrency();
if (partner == null) {
partner = saleOrder.getClientPartner();
}
partnerAccount = accountConfigSupplychainService.getForecastedInvCustAccount(accountConfig);
}
if (StockMoveRepository.ORIGIN_PURCHASE_ORDER.equals(stockMove.getOriginTypeSelect()) && stockMove.getOriginId() != null) {
PurchaseOrder purchaseOrder = purchaseOrderRepository.find(stockMove.getOriginId());
currency = purchaseOrder.getCurrency();
if (partner == null) {
partner = purchaseOrder.getSupplierPartner();
}
partnerAccount = accountConfigSupplychainService.getForecastedInvSuppAccount(accountConfig);
}
String origin = stockMove.getStockMoveSeq();
Move move = moveCreateService.createMove(accountConfigSupplychainService.getAutoMiscOpeJournal(accountConfig), company, currency, partner, moveDate, null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, MoveRepository.FUNCTIONAL_ORIGIN_CUT_OFF);
counter = 0;
this.generateMoveLines(move, stockMove.getStockMoveLineList(), origin, isPurchase, recoveredTax, ati, moveDescription, isReverse, originDate, includeNotStockManagedProduct);
this.generatePartnerMoveLine(move, origin, partnerAccount, moveDescription, originDate);
if (move.getMoveLineList() != null && !move.getMoveLineList().isEmpty()) {
move.setStockMove(stockMove);
moveValidateService.validate(move);
} else {
moveRepository.remove(move);
return null;
}
return move;
}
use of com.axelor.apps.stock.db.StockMove in project axelor-open-suite by axelor.
the class AccountingCutOffServiceImpl method generateCutOffMoves.
@Transactional(rollbackOn = { Exception.class })
public List<Move> generateCutOffMoves(StockMove stockMove, LocalDate moveDate, LocalDate reverseMoveDate, int accountingCutOffTypeSelect, boolean recoveredTax, boolean ati, String moveDescription, boolean includeNotStockManagedProduct) throws AxelorException {
List<Move> moveList = new ArrayList<>();
List<StockMoveLine> stockMoveLineSortedList = stockMove.getStockMoveLineList();
Collections.sort(stockMoveLineSortedList, Comparator.comparing(StockMoveLine::getSequence));
Move move = generateCutOffMove(stockMove, stockMoveLineSortedList, moveDate, moveDate, accountingCutOffTypeSelect == SupplychainBatchRepository.ACCOUNTING_CUT_OFF_TYPE_SUPPLIER_INVOICES, recoveredTax, ati, moveDescription, includeNotStockManagedProduct, false);
if (move == null) {
return null;
}
moveList.add(move);
Move reverseMove = generateCutOffMove(stockMove, stockMoveLineSortedList, reverseMoveDate, moveDate, accountingCutOffTypeSelect == SupplychainBatchRepository.ACCOUNTING_CUT_OFF_TYPE_SUPPLIER_INVOICES, recoveredTax, ati, moveDescription, includeNotStockManagedProduct, true);
if (reverseMove == null) {
return null;
}
moveList.add(reverseMove);
reconcile(move, reverseMove);
return moveList;
}
Aggregations