diff --git a/org.adempiere.base/src/org/compiere/model/MInvoice.java b/org.adempiere.base/src/org/compiere/model/MInvoice.java index 86b65aa3e9..8fe61c279f 100644 --- a/org.adempiere.base/src/org/compiere/model/MInvoice.java +++ b/org.adempiere.base/src/org/compiere/model/MInvoice.java @@ -679,7 +679,7 @@ public class MInvoice extends X_C_Invoice implements DocAction whereClauseFinal += whereClause; List list = new Query(getCtx(), I_C_InvoiceLine.Table_Name, whereClauseFinal, get_TrxName()) .setParameters(getC_Invoice_ID()) - .setOrderBy(I_C_InvoiceLine.COLUMNNAME_Line) + .setOrderBy("Line, C_InvoiceLine_ID") .list(); return list.toArray(new MInvoiceLine[list.size()]); } // getLines @@ -2450,17 +2450,23 @@ public class MInvoice extends X_C_Invoice implements DocAction reversal.setReversal(true); // Reverse Line Qty + MInvoiceLine[] oLines = getLines(false); MInvoiceLine[] rLines = reversal.getLines(true); for (int i = 0; i < rLines.length; i++) { MInvoiceLine rLine = rLines[i]; - rLine.setQtyEntered(rLine.getQtyEntered().negate()); - rLine.setQtyInvoiced(rLine.getQtyInvoiced().negate()); - rLine.setLineNetAmt(rLine.getLineNetAmt().negate()); - if (rLine.getTaxAmt() != null && rLine.getTaxAmt().compareTo(Env.ZERO) != 0) - rLine.setTaxAmt(rLine.getTaxAmt().negate()); - if (rLine.getLineTotalAmt() != null && rLine.getLineTotalAmt().compareTo(Env.ZERO) != 0) - rLine.setLineTotalAmt(rLine.getLineTotalAmt().negate()); + rLine.getParent().setReversal(true); + MInvoiceLine oLine = oLines[i]; + rLine.setQtyEntered(oLine.getQtyEntered().negate()); + rLine.setQtyInvoiced(oLine.getQtyInvoiced().negate()); + rLine.setLineNetAmt(oLine.getLineNetAmt().negate()); + rLine.setTaxAmt(oLine.getTaxAmt().negate()); + rLine.setLineTotalAmt(oLine.getLineTotalAmt().negate()); + rLine.setPriceActual(oLine.getPriceActual()); + rLine.setPriceList(oLine.getPriceList()); + rLine.setPriceLimit(oLine.getPriceLimit()); + rLine.setPriceEntered(oLine.getPriceEntered()); + rLine.setC_UOM_ID(oLine.getC_UOM_ID()); if (!rLine.save(get_TrxName())) { m_processMsg = "Could not correct Invoice Reversal Line"; diff --git a/org.adempiere.base/src/org/compiere/model/MInvoiceLine.java b/org.adempiere.base/src/org/compiere/model/MInvoiceLine.java index 272995eb03..3582e9d1e5 100644 --- a/org.adempiere.base/src/org/compiere/model/MInvoiceLine.java +++ b/org.adempiere.base/src/org/compiere/model/MInvoiceLine.java @@ -842,12 +842,16 @@ public class MInvoiceLine extends X_C_InvoiceLine protected boolean beforeSave (boolean newRecord) { if (log.isLoggable(Level.FINE)) log.fine("New=" + newRecord); - if (newRecord && getParent().isComplete()) { + boolean parentComplete = getParent().isComplete(); + boolean isReversal = getParent().isReversal(); + if (newRecord && parentComplete) { log.saveError("ParentComplete", Msg.translate(getCtx(), "C_InvoiceLine")); return false; } // Re-set invoice header (need to update m_IsSOTrx flag) - phib [ 1686773 ] setInvoice(getParent()); + + if (!parentComplete && !isReversal) { // do not change things when parent is complete // Charge if (getC_Charge_ID() != 0) { @@ -916,6 +920,7 @@ public class MInvoiceLine extends X_C_InvoiceLine return false; } } + } return true; } // beforeSave