use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.
the class StockMoveInvoiceServiceImpl method getConsolidatedStockMoveLineList.
/**
* Get a list of stock move lines consolidated by parent line (sale or purchase order).
*
* @param stockMoveLineList
* @return
* @throws AxelorException
*/
private List<StockMoveLine> getConsolidatedStockMoveLineList(List<StockMoveLine> stockMoveLineList) throws AxelorException {
Map<SaleOrderLine, List<StockMoveLine>> stockMoveLineSaleMap = new LinkedHashMap<>();
Map<PurchaseOrderLine, List<StockMoveLine>> stockMoveLinePurchaseMap = new LinkedHashMap<>();
List<StockMoveLine> resultList = new ArrayList<>();
List<StockMoveLine> list;
for (StockMoveLine stockMoveLine : stockMoveLineList) {
if (stockMoveLine.getSaleOrderLine() != null) {
list = stockMoveLineSaleMap.get(stockMoveLine.getSaleOrderLine());
if (list == null) {
list = new ArrayList<>();
stockMoveLineSaleMap.put(stockMoveLine.getSaleOrderLine(), list);
}
list.add(stockMoveLine);
} else if (stockMoveLine.getPurchaseOrderLine() != null) {
list = stockMoveLinePurchaseMap.get(stockMoveLine.getPurchaseOrderLine());
if (list == null) {
list = new ArrayList<>();
stockMoveLinePurchaseMap.put(stockMoveLine.getPurchaseOrderLine(), list);
}
list.add(stockMoveLine);
} else {
// if the stock move line does not have a parent line (sale or purchase order line)
resultList.add(stockMoveLine);
}
}
for (List<StockMoveLine> stockMoveLines : stockMoveLineSaleMap.values()) {
resultList.add(stockMoveLineServiceSupplychain.getMergedStockMoveLine(stockMoveLines));
}
for (List<StockMoveLine> stockMoveLines : stockMoveLinePurchaseMap.values()) {
resultList.add(stockMoveLineServiceSupplychain.getMergedStockMoveLine(stockMoveLines));
}
return resultList;
}
use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.
the class StockMoveInvoiceServiceImpl method createInvoiceLines.
@Override
public List<InvoiceLine> createInvoiceLines(Invoice invoice, StockMove stockMove, List<StockMoveLine> stockMoveLineList, Map<Long, BigDecimal> qtyToInvoiceMap) throws AxelorException {
List<InvoiceLine> invoiceLineList = new ArrayList<>();
List<StockMoveLine> stockMoveLineToInvoiceList;
if ((StockMoveRepository.ORIGIN_PURCHASE_ORDER.equals(stockMove.getOriginTypeSelect()) && supplyChainConfigService.getSupplyChainConfig(invoice.getCompany()).getActivateIncStockMovePartialInvoicing()) || (StockMoveRepository.ORIGIN_SALE_ORDER.equals(stockMove.getOriginTypeSelect()) && supplyChainConfigService.getSupplyChainConfig(invoice.getCompany()).getActivateOutStockMovePartialInvoicing())) {
// we do not consolidate because the invoicing is partial
stockMoveLineToInvoiceList = stockMoveLineList;
} else {
stockMoveLineToInvoiceList = getConsolidatedStockMoveLineList(stockMoveLineList);
}
for (StockMoveLine stockMoveLine : stockMoveLineToInvoiceList) {
InvoiceLine invoiceLineCreated;
Long id = stockMoveLine.getId();
if (qtyToInvoiceMap != null) {
invoiceLineCreated = this.createInvoiceLine(invoice, stockMoveLine, qtyToInvoiceMap.get(id));
} else {
invoiceLineCreated = this.createInvoiceLine(invoice, stockMoveLine, stockMoveLine.getRealQty().subtract(computeNonCanceledInvoiceQty(stockMoveLine)));
}
if (invoiceLineCreated != null) {
invoiceLineList.add(invoiceLineCreated);
}
}
return invoiceLineList;
}
use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.
the class StockMoveInvoiceServiceImpl method createInvoiceLine.
@Override
public InvoiceLine createInvoiceLine(Invoice invoice, StockMoveLine stockMoveLine, BigDecimal qty) throws AxelorException {
Product product = stockMoveLine.getProduct();
boolean isTitleLine = false;
int sequence = InvoiceLineGenerator.DEFAULT_SEQUENCE;
SaleOrderLine saleOrderLine = stockMoveLine.getSaleOrderLine();
PurchaseOrderLine purchaseOrderLine = stockMoveLine.getPurchaseOrderLine();
if (saleOrderLine != null) {
sequence = saleOrderLine.getSequence();
} else if (purchaseOrderLine != null) {
if (purchaseOrderLine.getIsTitleLine()) {
isTitleLine = true;
}
sequence = purchaseOrderLine.getSequence();
}
// do not create lines with no qties
if ((qty == null || qty.signum() == 0 || stockMoveLine.getRealQty().signum() == 0) && !isTitleLine) {
return null;
}
if (product == null && !isTitleLine) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.STOCK_MOVE_INVOICE_1), stockMoveLine.getStockMove().getStockMoveSeq());
}
InvoiceLineGenerator invoiceLineGenerator = new InvoiceLineGeneratorSupplyChain(invoice, product, stockMoveLine.getProductName(), stockMoveLine.getDescription(), qty, stockMoveLine.getUnit(), sequence, false, stockMoveLine.getSaleOrderLine(), stockMoveLine.getPurchaseOrderLine(), stockMoveLine) {
@Override
public List<InvoiceLine> creates() throws AxelorException {
InvoiceLine invoiceLine = this.createInvoiceLine();
List<InvoiceLine> invoiceLines = new ArrayList<>();
invoiceLines.add(invoiceLine);
return invoiceLines;
}
};
List<InvoiceLine> invoiceLines = invoiceLineGenerator.creates();
InvoiceLine invoiceLine = null;
if (invoiceLines != null && !invoiceLines.isEmpty()) {
invoiceLine = invoiceLines.get(0);
if (!stockMoveLine.getIsMergedStockMoveLine()) {
// not a consolidated line so we can set the reference.
invoiceLine.setStockMoveLine(stockMoveLine);
} else {
// set the reference to a correct stock move line by following either the sale order line or
// purchase order line. We cannot have a consolidated line without purchase order line or
// sale order line reference
StockMoveLine nonConsolidatedStockMoveLine = null;
StockMove stockMove = stockMoveLine.getStockMove();
if (saleOrderLine != null) {
nonConsolidatedStockMoveLine = stockMoveLineRepository.all().filter("self.saleOrderLine.id = :saleOrderLineId " + "AND self.stockMove.id = :stockMoveId " + "AND self.id != :stockMoveLineId").bind("saleOrderLineId", saleOrderLine.getId()).bind("stockMoveId", stockMove.getId()).bind("stockMoveLineId", stockMoveLine.getId()).order("id").fetchOne();
} else if (purchaseOrderLine != null) {
nonConsolidatedStockMoveLine = stockMoveLineRepository.all().filter("self.purchaseOrderLine.id = :purchaseOrderLineId " + "AND self.stockMove.id = :stockMoveId " + "AND self.id != :stockMoveLineId").bind("purchaseOrderLineId", purchaseOrderLine.getId()).bind("stockMoveId", stockMove.getId()).bind("stockMoveLineId", stockMoveLine.getId()).order("id").fetchOne();
}
invoiceLine.setStockMoveLine(nonConsolidatedStockMoveLine);
deleteConsolidatedStockMoveLine(stockMoveLine);
}
}
return invoiceLine;
}
use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.
the class StockMoveInvoiceServiceImpl method createInvoice.
@Override
@Transactional(rollbackOn = { Exception.class })
public Invoice createInvoice(StockMove stockMove, Integer operationSelect, List<Map<String, Object>> stockMoveLineListContext) throws AxelorException {
Invoice invoice;
Map<Long, BigDecimal> qtyToInvoiceMap = new HashMap<>();
if (operationSelect == StockMoveRepository.INVOICE_PARTIALLY) {
for (Map<String, Object> map : stockMoveLineListContext) {
if (map.get("qtyToInvoice") != null) {
BigDecimal qtyToInvoiceItem = new BigDecimal(map.get("qtyToInvoice").toString());
BigDecimal remainingQty = new BigDecimal(map.get("remainingQty").toString());
if (qtyToInvoiceItem.compareTo(BigDecimal.ZERO) != 0) {
if (qtyToInvoiceItem.compareTo(remainingQty) > 0) {
qtyToInvoiceItem = remainingQty;
}
Long stockMoveLineId = Long.parseLong(map.get("stockMoveLineId").toString());
StockMoveLine stockMoveLine = stockMoveLineRepository.find(stockMoveLineId);
qtyToInvoiceMap.put(stockMoveLine.getId(), qtyToInvoiceItem);
}
}
}
} else {
qtyToInvoiceMap = null;
}
Long origin = stockMove.getOriginId();
if (StockMoveRepository.ORIGIN_SALE_ORDER.equals(stockMove.getOriginTypeSelect())) {
invoice = createInvoiceFromSaleOrder(stockMove, saleOrderRepo.find(origin), qtyToInvoiceMap);
} else if (StockMoveRepository.ORIGIN_PURCHASE_ORDER.equals(stockMove.getOriginTypeSelect())) {
invoice = createInvoiceFromPurchaseOrder(stockMove, purchaseOrderRepo.find(origin), qtyToInvoiceMap);
} else {
invoice = createInvoiceFromOrderlessStockMove(stockMove, qtyToInvoiceMap);
}
return invoice;
}
use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.
the class ManufOrderServiceImpl method updateProducedStockMoveFromManufOrder.
@Override
@Transactional(rollbackOn = { Exception.class })
public void updateProducedStockMoveFromManufOrder(ManufOrder manufOrder) throws AxelorException {
List<StockMoveLine> producedStockMoveLineList = manufOrder.getProducedStockMoveLineList();
ManufOrderStockMoveService manufOrderStockMoveService = Beans.get(ManufOrderStockMoveService.class);
Optional<StockMove> stockMoveOpt = manufOrderStockMoveService.getPlannedStockMove(manufOrder.getOutStockMoveList());
StockMove stockMove;
if (stockMoveOpt.isPresent()) {
stockMove = stockMoveOpt.get();
} else {
stockMove = manufOrderStockMoveService._createToProduceStockMove(manufOrder, manufOrder.getCompany());
manufOrder.addOutStockMoveListItem(stockMove);
Beans.get(StockMoveService.class).plan(stockMove);
}
updateStockMoveFromManufOrder(producedStockMoveLineList, stockMove);
}
Aggregations