use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.
the class StockMoveLineServiceSupplychainImpl method computeFromOrder.
protected StockMoveLine computeFromOrder(StockMoveLine stockMoveLine, StockMove stockMove) throws AxelorException {
BigDecimal unitPriceUntaxed = stockMoveLine.getUnitPriceUntaxed();
BigDecimal unitPriceTaxed = stockMoveLine.getUnitPriceTaxed();
Unit orderUnit = null;
if (StockMoveRepository.ORIGIN_SALE_ORDER.equals(stockMove.getOriginTypeSelect())) {
SaleOrderLine saleOrderLine = stockMoveLine.getSaleOrderLine();
if (saleOrderLine == null) {
// log the exception
TraceBackService.trace(new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, IExceptionMessage.STOCK_MOVE_MISSING_SALE_ORDER, stockMove.getOriginId(), stockMove.getName()));
} else {
unitPriceUntaxed = saleOrderLine.getPriceDiscounted();
unitPriceTaxed = saleOrderLine.getInTaxPrice();
orderUnit = saleOrderLine.getUnit();
}
} else if (StockMoveRepository.ORIGIN_PURCHASE_ORDER.equals(stockMove.getOriginTypeSelect())) {
PurchaseOrderLine purchaseOrderLine = stockMoveLine.getPurchaseOrderLine();
if (purchaseOrderLine == null) {
// log the exception
TraceBackService.trace(new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, IExceptionMessage.STOCK_MOVE_MISSING_PURCHASE_ORDER, stockMove.getOriginId(), stockMove.getName()));
} else {
unitPriceUntaxed = purchaseOrderLine.getPrice();
unitPriceTaxed = purchaseOrderLine.getInTaxPrice();
orderUnit = purchaseOrderLine.getUnit();
}
}
stockMoveLine.setUnitPriceUntaxed(unitPriceUntaxed);
stockMoveLine.setUnitPriceTaxed(unitPriceTaxed);
Unit stockUnit = getStockUnit(stockMoveLine);
return convertUnitPrice(stockMoveLine, orderUnit, stockUnit);
}
use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.
the class StockMoveLineServiceSupplychainImpl method getMergedStockMoveLine.
@Override
public StockMoveLine getMergedStockMoveLine(List<StockMoveLine> stockMoveLineList) throws AxelorException {
if (stockMoveLineList == null || stockMoveLineList.isEmpty()) {
return null;
}
if (stockMoveLineList.size() == 1) {
return stockMoveLineList.get(0);
}
StockMove stockMove = stockMoveLineList.get(0).getStockMove();
SaleOrderLine saleOrderLine = stockMoveLineList.get(0).getSaleOrderLine();
PurchaseOrderLine purchaseOrderLine = stockMoveLineList.get(0).getPurchaseOrderLine();
Product product;
String productName;
String description;
BigDecimal quantity = BigDecimal.ZERO;
Unit unit;
if (saleOrderLine != null) {
product = saleOrderLine.getProduct();
productName = saleOrderLine.getProductName();
description = saleOrderLine.getDescription();
unit = saleOrderLine.getUnit();
} else if (purchaseOrderLine != null) {
product = purchaseOrderLine.getProduct();
productName = purchaseOrderLine.getProductName();
description = purchaseOrderLine.getDescription();
unit = purchaseOrderLine.getUnit();
} else {
// shouldn't ever happen or you misused this function
return null;
}
for (StockMoveLine stockMoveLine : stockMoveLineList) {
quantity = quantity.add(stockMoveLine.getRealQty());
}
StockMoveLine generatedStockMoveLine = createStockMoveLine(product, productName, description, quantity, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, unit, stockMove, null);
generatedStockMoveLine.setSaleOrderLine(saleOrderLine);
generatedStockMoveLine.setPurchaseOrderLine(purchaseOrderLine);
generatedStockMoveLine.setIsMergedStockMoveLine(true);
return generatedStockMoveLine;
}
use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.
the class StockMoveLineServiceSupplychainImpl method setProductInfo.
/**
* This implementation copy fields from sale order line and purchase order line if the link
* exists.
*
* @param stockMove
* @param stockMoveLine
* @param company
*/
@Override
public void setProductInfo(StockMove stockMove, StockMoveLine stockMoveLine, Company company) throws AxelorException {
if (!Beans.get(AppBaseService.class).isApp("supplychain")) {
super.setProductInfo(stockMove, stockMoveLine, company);
return;
}
Preconditions.checkNotNull(stockMoveLine);
Preconditions.checkNotNull(company);
Product product = stockMoveLine.getProduct();
if (product == null) {
return;
}
super.setProductInfo(stockMove, stockMoveLine, company);
SaleOrderLine saleOrderLine = stockMoveLine.getSaleOrderLine();
PurchaseOrderLine purchaseOrderLine = stockMoveLine.getPurchaseOrderLine();
if (saleOrderLine != null) {
setProductInfoFromSaleOrder(stockMoveLine, saleOrderLine);
}
if (purchaseOrderLine != null) {
setProductInfoFromPurchaseOrder(stockMoveLine, purchaseOrderLine);
}
}
use of com.axelor.apps.purchase.db.PurchaseOrderLine 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.purchase.db.PurchaseOrderLine 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;
}
Aggregations