fix invoice line creation
This commit is contained in:
@@ -93,7 +93,7 @@ public class StockMoveInvoiceServiceImpl implements StockMoveInvoiceService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackOn = {Exception.class})
|
@Transactional(rollbackOn = { Exception.class })
|
||||||
public Invoice createInvoice(
|
public Invoice createInvoice(
|
||||||
StockMove stockMove,
|
StockMove stockMove,
|
||||||
Integer operationSelect,
|
Integer operationSelect,
|
||||||
@@ -130,9 +130,8 @@ public class StockMoveInvoiceServiceImpl implements StockMoveInvoiceService {
|
|||||||
if (StockMoveRepository.ORIGIN_SALE_ORDER.equals(stockMove.getOriginTypeSelect())) {
|
if (StockMoveRepository.ORIGIN_SALE_ORDER.equals(stockMove.getOriginTypeSelect())) {
|
||||||
invoice = createInvoiceFromSaleOrder(stockMove, saleOrderRepo.find(origin), qtyToInvoiceMap);
|
invoice = createInvoiceFromSaleOrder(stockMove, saleOrderRepo.find(origin), qtyToInvoiceMap);
|
||||||
} else if (StockMoveRepository.ORIGIN_PURCHASE_ORDER.equals(stockMove.getOriginTypeSelect())) {
|
} else if (StockMoveRepository.ORIGIN_PURCHASE_ORDER.equals(stockMove.getOriginTypeSelect())) {
|
||||||
invoice =
|
invoice = createInvoiceFromPurchaseOrder(
|
||||||
createInvoiceFromPurchaseOrder(
|
stockMove, purchaseOrderRepo.find(origin), qtyToInvoiceMap);
|
||||||
stockMove, purchaseOrderRepo.find(origin), qtyToInvoiceMap);
|
|
||||||
} else {
|
} else {
|
||||||
invoice = createInvoiceFromOrderlessStockMove(stockMove, qtyToInvoiceMap);
|
invoice = createInvoiceFromOrderlessStockMove(stockMove, qtyToInvoiceMap);
|
||||||
}
|
}
|
||||||
@@ -147,10 +146,9 @@ public class StockMoveInvoiceServiceImpl implements StockMoveInvoiceService {
|
|||||||
for (StockMoveLine subLine : stockMoveLine.getSubLineList()) {
|
for (StockMoveLine subLine : stockMoveLine.getSubLineList()) {
|
||||||
BigDecimal qty = BigDecimal.ZERO;
|
BigDecimal qty = BigDecimal.ZERO;
|
||||||
if (stockMoveLine.getQty().compareTo(BigDecimal.ZERO) != 0) {
|
if (stockMoveLine.getQty().compareTo(BigDecimal.ZERO) != 0) {
|
||||||
qty =
|
qty = qtyToInvoiceItem
|
||||||
qtyToInvoiceItem
|
.multiply(subLine.getQty())
|
||||||
.multiply(subLine.getQty())
|
.divide(stockMoveLine.getQty(), 2, RoundingMode.HALF_EVEN);
|
||||||
.divide(stockMoveLine.getQty(), 2, RoundingMode.HALF_EVEN);
|
|
||||||
}
|
}
|
||||||
qty = qty.setScale(2, RoundingMode.HALF_EVEN);
|
qty = qty.setScale(2, RoundingMode.HALF_EVEN);
|
||||||
qtyToInvoiceMap.put(subLine.getId(), qty);
|
qtyToInvoiceMap.put(subLine.getId(), qty);
|
||||||
@@ -159,13 +157,13 @@ public class StockMoveInvoiceServiceImpl implements StockMoveInvoiceService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackOn = {Exception.class})
|
@Transactional(rollbackOn = { Exception.class })
|
||||||
public Invoice createInvoiceFromSaleOrder(
|
public Invoice createInvoiceFromSaleOrder(
|
||||||
StockMove stockMove, SaleOrder saleOrder, Map<Long, BigDecimal> qtyToInvoiceMap)
|
StockMove stockMove, SaleOrder saleOrder, Map<Long, BigDecimal> qtyToInvoiceMap)
|
||||||
throws AxelorException {
|
throws AxelorException {
|
||||||
|
|
||||||
InvoiceGenerator invoiceGenerator =
|
InvoiceGenerator invoiceGenerator = saleOrderInvoiceService.createInvoiceGenerator(saleOrder,
|
||||||
saleOrderInvoiceService.createInvoiceGenerator(saleOrder, stockMove.getIsReversion());
|
stockMove.getIsReversion());
|
||||||
|
|
||||||
Invoice invoice = invoiceGenerator.generate();
|
Invoice invoice = invoiceGenerator.generate();
|
||||||
|
|
||||||
@@ -210,14 +208,13 @@ public class StockMoveInvoiceServiceImpl implements StockMoveInvoiceService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackOn = {Exception.class})
|
@Transactional(rollbackOn = { Exception.class })
|
||||||
public Invoice createInvoiceFromPurchaseOrder(
|
public Invoice createInvoiceFromPurchaseOrder(
|
||||||
StockMove stockMove, PurchaseOrder purchaseOrder, Map<Long, BigDecimal> qtyToInvoiceMap)
|
StockMove stockMove, PurchaseOrder purchaseOrder, Map<Long, BigDecimal> qtyToInvoiceMap)
|
||||||
throws AxelorException {
|
throws AxelorException {
|
||||||
|
|
||||||
InvoiceGenerator invoiceGenerator =
|
InvoiceGenerator invoiceGenerator = purchaseOrderInvoiceService.createInvoiceGenerator(
|
||||||
purchaseOrderInvoiceService.createInvoiceGenerator(
|
purchaseOrder, stockMove.getIsReversion());
|
||||||
purchaseOrder, stockMove.getIsReversion());
|
|
||||||
|
|
||||||
Invoice invoice = invoiceGenerator.generate();
|
Invoice invoice = invoiceGenerator.generate();
|
||||||
|
|
||||||
@@ -249,7 +246,7 @@ public class StockMoveInvoiceServiceImpl implements StockMoveInvoiceService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackOn = {Exception.class})
|
@Transactional(rollbackOn = { Exception.class })
|
||||||
public Invoice createInvoiceFromOrderlessStockMove(
|
public Invoice createInvoiceFromOrderlessStockMove(
|
||||||
StockMove stockMove, Map<Long, BigDecimal> qtyToInvoiceMap) throws AxelorException {
|
StockMove stockMove, Map<Long, BigDecimal> qtyToInvoiceMap) throws AxelorException {
|
||||||
|
|
||||||
@@ -274,15 +271,14 @@ public class StockMoveInvoiceServiceImpl implements StockMoveInvoiceService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
InvoiceGenerator invoiceGenerator =
|
InvoiceGenerator invoiceGenerator = new InvoiceGeneratorSupplyChain(stockMove, invoiceOperationType) {
|
||||||
new InvoiceGeneratorSupplyChain(stockMove, invoiceOperationType) {
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Invoice generate() throws AxelorException {
|
public Invoice generate() throws AxelorException {
|
||||||
|
|
||||||
return super.createInvoiceHeader();
|
return super.createInvoiceHeader();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Invoice invoice = invoiceGenerator.generate();
|
Invoice invoice = invoiceGenerator.generate();
|
||||||
|
|
||||||
@@ -340,15 +336,13 @@ public class StockMoveInvoiceServiceImpl implements StockMoveInvoiceService {
|
|||||||
Long id = stockMoveLine.getId();
|
Long id = stockMoveLine.getId();
|
||||||
if (qtyToInvoiceMap != null) {
|
if (qtyToInvoiceMap != null) {
|
||||||
if (qtyToInvoiceMap.containsKey(id)) {
|
if (qtyToInvoiceMap.containsKey(id)) {
|
||||||
invoiceLineListCreated =
|
invoiceLineListCreated = this.createInvoiceLine(invoice, stockMoveLine, qtyToInvoiceMap.get(id));
|
||||||
this.createInvoiceLine(invoice, stockMoveLine, qtyToInvoiceMap.get(id));
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
invoiceLineListCreated =
|
invoiceLineListCreated = this.createInvoiceLine(
|
||||||
this.createInvoiceLine(
|
invoice,
|
||||||
invoice,
|
stockMoveLine,
|
||||||
stockMoveLine,
|
stockMoveLine.getRealQty().subtract(stockMoveLine.getQtyInvoiced()));
|
||||||
stockMoveLine.getRealQty().subtract(stockMoveLine.getQtyInvoiced()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (invoiceLineListCreated != null) {
|
if (invoiceLineListCreated != null) {
|
||||||
@@ -424,32 +418,31 @@ public class StockMoveInvoiceServiceImpl implements StockMoveInvoiceService {
|
|||||||
stockMoveLine.getStockMove().getStockMoveSeq());
|
stockMoveLine.getStockMove().getStockMoveSeq());
|
||||||
}
|
}
|
||||||
|
|
||||||
InvoiceLineGenerator invoiceLineGenerator =
|
InvoiceLineGenerator invoiceLineGenerator = new InvoiceLineGeneratorSupplyChain(
|
||||||
new InvoiceLineGeneratorSupplyChain(
|
invoice,
|
||||||
invoice,
|
product,
|
||||||
product,
|
stockMoveLine.getProductName(),
|
||||||
stockMoveLine.getProductName(),
|
stockMoveLine.getDescription(),
|
||||||
stockMoveLine.getDescription(),
|
qty,
|
||||||
qty,
|
stockMoveLine.getUnit(),
|
||||||
stockMoveLine.getUnit(),
|
sequence,
|
||||||
sequence,
|
false,
|
||||||
false,
|
stockMoveLine.getSaleOrderLine(),
|
||||||
stockMoveLine.getSaleOrderLine(),
|
stockMoveLine.getPurchaseOrderLine(),
|
||||||
stockMoveLine.getPurchaseOrderLine(),
|
stockMoveLine,
|
||||||
stockMoveLine,
|
stockMoveLine.getIsSubLine(),
|
||||||
stockMoveLine.getIsSubLine(),
|
stockMoveLine.getPackPriceSelect()) {
|
||||||
stockMoveLine.getPackPriceSelect()) {
|
@Override
|
||||||
@Override
|
public List<InvoiceLine> creates() throws AxelorException {
|
||||||
public List<InvoiceLine> creates() throws AxelorException {
|
|
||||||
|
|
||||||
InvoiceLine invoiceLine = this.createInvoiceLine();
|
InvoiceLine invoiceLine = this.createInvoiceLine();
|
||||||
|
|
||||||
List<InvoiceLine> invoiceLines = new ArrayList<InvoiceLine>();
|
List<InvoiceLine> invoiceLines = new ArrayList<InvoiceLine>();
|
||||||
invoiceLines.add(invoiceLine);
|
invoiceLines.add(invoiceLine);
|
||||||
|
|
||||||
return invoiceLines;
|
return invoiceLines;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
List<InvoiceLine> invoiceLines = invoiceLineGenerator.creates();
|
List<InvoiceLine> invoiceLines = invoiceLineGenerator.creates();
|
||||||
for (InvoiceLine invoiceLine : invoiceLines) {
|
for (InvoiceLine invoiceLine : invoiceLines) {
|
||||||
@@ -465,7 +458,8 @@ public class StockMoveInvoiceServiceImpl implements StockMoveInvoiceService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a list of stock move lines consolidated by parent line (sale or purchase order).
|
* Get a list of stock move lines consolidated by parent line (sale or purchase
|
||||||
|
* order).
|
||||||
*
|
*
|
||||||
* @param stockMoveLineList
|
* @param stockMoveLineList
|
||||||
* @return
|
* @return
|
||||||
@@ -484,8 +478,8 @@ public class StockMoveInvoiceServiceImpl implements StockMoveInvoiceService {
|
|||||||
if (stockMoveLine.getSaleOrderLine() != null) {
|
if (stockMoveLine.getSaleOrderLine() != null) {
|
||||||
list = stockMoveLineSaleMap.get(stockMoveLine.getSaleOrderLine());
|
list = stockMoveLineSaleMap.get(stockMoveLine.getSaleOrderLine());
|
||||||
// if (list == null) {
|
// if (list == null) {
|
||||||
// list = new ArrayList<>();
|
// list = new ArrayList<>();
|
||||||
// stockMoveLineSaleMap.put(stockMoveLine.getSaleOrderLine(), list);
|
// stockMoveLineSaleMap.put(stockMoveLine.getSaleOrderLine(), list);
|
||||||
// }
|
// }
|
||||||
// list.add(stockMoveLine);
|
// list.add(stockMoveLine);
|
||||||
resultList.add(stockMoveLine);
|
resultList.add(stockMoveLine);
|
||||||
@@ -496,7 +490,9 @@ public class StockMoveInvoiceServiceImpl implements StockMoveInvoiceService {
|
|||||||
stockMoveLinePurchaseMap.put(stockMoveLine.getPurchaseOrderLine(), list);
|
stockMoveLinePurchaseMap.put(stockMoveLine.getPurchaseOrderLine(), list);
|
||||||
}
|
}
|
||||||
list.add(stockMoveLine);
|
list.add(stockMoveLine);
|
||||||
} else { // if the stock move line does not have a parent line (sale or purchase order line)
|
resultList.add(stockMoveLine);
|
||||||
|
} else { // if the stock move line does not have a parent line (sale or purchase order
|
||||||
|
// line)
|
||||||
resultList.add(stockMoveLine);
|
resultList.add(stockMoveLine);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -544,18 +540,16 @@ public class StockMoveInvoiceServiceImpl implements StockMoveInvoiceService {
|
|||||||
stockMove = Beans.get(StockMoveRepository.class).find(stockMove.getId());
|
stockMove = Beans.get(StockMoveRepository.class).find(stockMove.getId());
|
||||||
|
|
||||||
if (stockMove.getInvoiceSet() != null && !stockMove.getInvoiceSet().isEmpty()) {
|
if (stockMove.getInvoiceSet() != null && !stockMove.getInvoiceSet().isEmpty()) {
|
||||||
Double totalInvoicedQty =
|
Double totalInvoicedQty = stockMove
|
||||||
stockMove
|
.getStockMoveLineList()
|
||||||
.getStockMoveLineList()
|
.stream()
|
||||||
.stream()
|
.mapToDouble(sml -> Double.parseDouble(sml.getQtyInvoiced().toString()))
|
||||||
.mapToDouble(sml -> Double.parseDouble(sml.getQtyInvoiced().toString()))
|
.sum();
|
||||||
.sum();
|
Double totalRealQty = stockMove
|
||||||
Double totalRealQty =
|
.getStockMoveLineList()
|
||||||
stockMove
|
.stream()
|
||||||
.getStockMoveLineList()
|
.mapToDouble(sml -> Double.parseDouble(sml.getRealQty().toString()))
|
||||||
.stream()
|
.sum();
|
||||||
.mapToDouble(sml -> Double.parseDouble(sml.getRealQty().toString()))
|
|
||||||
.sum();
|
|
||||||
if (totalRealQty.compareTo(totalInvoicedQty) == 1) {
|
if (totalRealQty.compareTo(totalInvoicedQty) == 1) {
|
||||||
invoiceStatus = 1;
|
invoiceStatus = 1;
|
||||||
} else if (totalRealQty.compareTo(totalInvoicedQty) == 0) {
|
} else if (totalRealQty.compareTo(totalInvoicedQty) == 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user