From 5fcb693d2ba2c9ea970479a45aed2603d476f74c Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Tue, 20 Jan 2009 04:25:21 +0000 Subject: [PATCH] Fix [2520529] - Error Generating Invoice from Shipment with different UoM https://sourceforge.net/tracker2/?func=detail&atid=879332&aid=2520529&group_id=176962 --- .../src/org/compiere/model/MInOutConfirm.java | 5 +++ base/src/org/compiere/model/MInOutLine.java | 14 +++++++ base/src/org/compiere/model/MInvoiceLine.java | 11 ++++- base/src/org/compiere/model/MOrder.java | 5 ++- .../compiere/process/InOutCreateInvoice.java | 5 ++- .../org/compiere/process/InvoiceGenerate.java | 5 ++- .../org/compiere/grid/VCreateFromInvoice.java | 40 +++++++++---------- .../webui/apps/form/WCreateFromInvoice.java | 40 +++++++++---------- 8 files changed, 80 insertions(+), 45 deletions(-) diff --git a/base/src/org/compiere/model/MInOutConfirm.java b/base/src/org/compiere/model/MInOutConfirm.java index 51412a57de..86bb06df2a 100644 --- a/base/src/org/compiere/model/MInOutConfirm.java +++ b/base/src/org/compiere/model/MInOutConfirm.java @@ -605,6 +605,11 @@ public class MInOutConfirm extends X_M_InOutConfirm implements DocAction } MInvoiceLine line = new MInvoiceLine (m_creditMemo); line.setShipLine(confirm.getLine()); + if (confirm.getLine().getProduct() != null) { + // use product UOM in case the shipment hasn't the same uom than the order + line.setC_UOM_ID(confirm.getLine().getProduct().getC_UOM_ID()); + } + // Note: confirmation is always in the qty according to the product UOM line.setQty(confirm.getDifferenceQty()); // Entered/Invoiced if (!line.save(get_TrxName())) { diff --git a/base/src/org/compiere/model/MInOutLine.java b/base/src/org/compiere/model/MInOutLine.java index 4e19a79f09..0853b5c441 100644 --- a/base/src/org/compiere/model/MInOutLine.java +++ b/base/src/org/compiere/model/MInOutLine.java @@ -617,4 +617,18 @@ public class MInOutLine extends X_M_InOutLine return Env.ZERO; } // getBase + public boolean sameOrderLineUOM() + { + if (getC_OrderLine_ID() <= 0) + return false; + + MOrderLine oLine = new MOrderLine(getCtx(), getC_OrderLine_ID(), get_TrxName()); + + if (oLine.getC_UOM_ID() != getC_UOM_ID()) + return false; + + // inout has orderline and both has the same UOM + return true; + } + } // MInOutLine diff --git a/base/src/org/compiere/model/MInvoiceLine.java b/base/src/org/compiere/model/MInvoiceLine.java index 7b6d36b7bc..405b89c065 100644 --- a/base/src/org/compiere/model/MInvoiceLine.java +++ b/base/src/org/compiere/model/MInvoiceLine.java @@ -242,7 +242,11 @@ public class MInvoiceLine extends X_C_InvoiceLine setDescription(sLine.getDescription()); // setM_Product_ID(sLine.getM_Product_ID()); - setC_UOM_ID(sLine.getC_UOM_ID()); + if (sLine.sameOrderLineUOM()) + setC_UOM_ID(sLine.getC_UOM_ID()); + else + // use product UOM if the shipment hasn't the same uom than the order + setC_UOM_ID(getProduct().getC_UOM_ID()); setM_AttributeSetInstance_ID(sLine.getM_AttributeSetInstance_ID()); // setS_ResourceAssignment_ID(sLine.getS_ResourceAssignment_ID()); if(getM_Product_ID() == 0) @@ -254,7 +258,10 @@ public class MInvoiceLine extends X_C_InvoiceLine MOrderLine oLine = new MOrderLine (getCtx(), C_OrderLine_ID, get_TrxName()); setS_ResourceAssignment_ID(oLine.getS_ResourceAssignment_ID()); // - setPriceEntered(oLine.getPriceEntered()); + if (sLine.sameOrderLineUOM()) + setPriceEntered(oLine.getPriceEntered()); + else + setPriceEntered(oLine.getPriceActual()); setPriceActual(oLine.getPriceActual()); setPriceLimit(oLine.getPriceLimit()); setPriceList(oLine.getPriceList()); diff --git a/base/src/org/compiere/model/MOrder.java b/base/src/org/compiere/model/MOrder.java index 19ad07d027..4684b64486 100644 --- a/base/src/org/compiere/model/MOrder.java +++ b/base/src/org/compiere/model/MOrder.java @@ -1792,7 +1792,10 @@ public class MOrder extends X_C_Order implements DocAction MInvoiceLine iLine = new MInvoiceLine(invoice); iLine.setShipLine(sLine); // Qty = Delivered - iLine.setQtyEntered(sLine.getQtyEntered()); + if (sLine.sameOrderLineUOM()) + iLine.setQtyEntered(sLine.getQtyEntered()); + else + iLine.setQtyEntered(sLine.getMovementQty()); iLine.setQtyInvoiced(sLine.getMovementQty()); if (!iLine.save(get_TrxName())) { diff --git a/base/src/org/compiere/process/InOutCreateInvoice.java b/base/src/org/compiere/process/InOutCreateInvoice.java index 2e280ed497..053c12ff32 100644 --- a/base/src/org/compiere/process/InOutCreateInvoice.java +++ b/base/src/org/compiere/process/InOutCreateInvoice.java @@ -92,7 +92,10 @@ public class InOutCreateInvoice extends SvrProcess MInOutLine sLine = shipLines[i]; MInvoiceLine line = new MInvoiceLine(invoice); line.setShipLine(sLine); - line.setQtyEntered(sLine.getQtyEntered()); + if (sLine.sameOrderLineUOM()) + line.setQtyEntered(sLine.getQtyEntered()); + else + line.setQtyEntered(sLine.getMovementQty()); line.setQtyInvoiced(sLine.getMovementQty()); if (!line.save()) throw new IllegalArgumentException("Cannot save Invoice Line"); diff --git a/base/src/org/compiere/process/InvoiceGenerate.java b/base/src/org/compiere/process/InvoiceGenerate.java index fdff5cd202..64a93bcce7 100644 --- a/base/src/org/compiere/process/InvoiceGenerate.java +++ b/base/src/org/compiere/process/InvoiceGenerate.java @@ -415,7 +415,10 @@ public class InvoiceGenerate extends SvrProcess // MInvoiceLine line = new MInvoiceLine (m_invoice); line.setShipLine(sLine); - line.setQtyEntered(sLine.getQtyEntered()); + if (sLine.sameOrderLineUOM()) + line.setQtyEntered(sLine.getQtyEntered()); + else + line.setQtyEntered(sLine.getMovementQty()); line.setQtyInvoiced(sLine.getMovementQty()); line.setLine(m_line + sLine.getLine()); if (!line.save()) diff --git a/client/src/org/compiere/grid/VCreateFromInvoice.java b/client/src/org/compiere/grid/VCreateFromInvoice.java index eb84be718d..778d9d2265 100644 --- a/client/src/org/compiere/grid/VCreateFromInvoice.java +++ b/client/src/org/compiere/grid/VCreateFromInvoice.java @@ -590,28 +590,28 @@ public class VCreateFromInvoice extends VCreateFrom implements VetoableChangeLis if (inoutLine != null) { invoiceLine.setShipLine(inoutLine); // overwrites - if (inoutLine.getQtyEntered().compareTo(inoutLine.getMovementQty()) != 0) - invoiceLine.setQtyInvoiced(QtyEntered - .multiply(inoutLine.getMovementQty()) - .divide(inoutLine.getQtyEntered(), 12, BigDecimal.ROUND_HALF_UP)); + if (inoutLine.sameOrderLineUOM()) + invoiceLine.setQtyInvoiced(QtyEntered); + else + invoiceLine.setQtyInvoiced(inoutLine.getMovementQty()); } - else + else { log.fine("No Receipt Line"); - - // Order Info - if (orderLine != null) - { - invoiceLine.setOrderLine(orderLine); // overwrites - if (orderLine.getQtyEntered().compareTo(orderLine.getQtyOrdered()) != 0) - invoiceLine.setQtyInvoiced(QtyEntered - .multiply(orderLine.getQtyOrdered()) - .divide(orderLine.getQtyEntered(), 12, BigDecimal.ROUND_HALF_UP)); - } - else - { - log.fine("No Order Line"); - invoiceLine.setPrice(); - invoiceLine.setTax(); + // Order Info + if (orderLine != null) + { + invoiceLine.setOrderLine(orderLine); // overwrites + if (orderLine.getQtyEntered().compareTo(orderLine.getQtyOrdered()) != 0) + invoiceLine.setQtyInvoiced(QtyEntered + .multiply(orderLine.getQtyOrdered()) + .divide(orderLine.getQtyEntered(), 12, BigDecimal.ROUND_HALF_UP)); + } + else + { + log.fine("No Order Line"); + invoiceLine.setPrice(); + invoiceLine.setTax(); + } } if (!invoiceLine.save()) log.log(Level.SEVERE, "Line NOT created #" + i); diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromInvoice.java b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromInvoice.java index 508e2c36a3..8c3b143d18 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromInvoice.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromInvoice.java @@ -581,28 +581,28 @@ public class WCreateFromInvoice extends WCreateFrom implements ValueChangeListen if (inoutLine != null) { invoiceLine.setShipLine(inoutLine); // overwrites - if (inoutLine.getQtyEntered().compareTo(inoutLine.getMovementQty()) != 0) - invoiceLine.setQtyInvoiced(QtyEntered - .multiply(inoutLine.getMovementQty()) - .divide(inoutLine.getQtyEntered(), 12, BigDecimal.ROUND_HALF_UP)); + if (inoutLine.sameOrderLineUOM()) + invoiceLine.setQtyInvoiced(QtyEntered); + else + invoiceLine.setQtyInvoiced(inoutLine.getMovementQty()); } - else + else { log.fine("No Receipt Line"); - - // Order Info - if (orderLine != null) - { - invoiceLine.setOrderLine(orderLine); // overwrites - if (orderLine.getQtyEntered().compareTo(orderLine.getQtyOrdered()) != 0) - invoiceLine.setQtyInvoiced(QtyEntered - .multiply(orderLine.getQtyOrdered()) - .divide(orderLine.getQtyEntered(), 12, BigDecimal.ROUND_HALF_UP)); - } - else - { - log.fine("No Order Line"); - invoiceLine.setPrice(); - invoiceLine.setTax(); + // Order Info + if (orderLine != null) + { + invoiceLine.setOrderLine(orderLine); // overwrites + if (orderLine.getQtyEntered().compareTo(orderLine.getQtyOrdered()) != 0) + invoiceLine.setQtyInvoiced(QtyEntered + .multiply(orderLine.getQtyOrdered()) + .divide(orderLine.getQtyEntered(), 12, BigDecimal.ROUND_HALF_UP)); + } + else + { + log.fine("No Order Line"); + invoiceLine.setPrice(); + invoiceLine.setTax(); + } } if (!invoiceLine.save()) log.log(Level.SEVERE, "Line NOT created #" + i);