From 03a72d738c0814ae53841ee0a5ad020bb5671e2d Mon Sep 17 00:00:00 2001 From: vpj-cd Date: Wed, 20 Aug 2008 19:18:01 +0000 Subject: [PATCH] bug fixed consolidate order --- .../org/compiere/process/DistributionRun.java | 80 +++++++++++++------ 1 file changed, 56 insertions(+), 24 deletions(-) diff --git a/base/src/org/compiere/process/DistributionRun.java b/base/src/org/compiere/process/DistributionRun.java index 72ed2ac561..2e14099ac9 100644 --- a/base/src/org/compiere/process/DistributionRun.java +++ b/base/src/org/compiere/process/DistributionRun.java @@ -977,32 +977,64 @@ public class DistributionRun extends SvrProcess continue; } - // Create Order Line - MDDOrderLine line = new MDDOrderLine(order); - if (counter && bp.getAD_OrgBP_ID_Int() > 0) - ; // don't overwrite counter doc - /*else // normal - optionally overwrite + if(p_ConsolidateDocument) { - line.setC_BPartner_ID(detail.getC_BPartner_ID()); - if (detail.getC_BPartner_Location_ID() != 0) - line.setC_BPartner_Location_ID(detail.getC_BPartner_Location_ID()); - }*/ - // - line.setAD_Org_ID(bp.getAD_OrgBP_ID_Int()); - line.setM_Locator_ID(m_locator.getM_Locator_ID()); - line.setM_LocatorTo_ID(m_locator_to.getM_Locator_ID()); - line.setIsInvoiced(false); - line.setProduct(product); - line.setQty(detail.getActualAllocation()); - line.setTargetQty(detail.getActualAllocation()); - line.setQtyEntered(detail.getActualAllocation()); - line.setConfirmedQty(detail.getActualAllocation()); - line.setDescription("Distribution Push"); - if (!line.save()) - { - log.log(Level.SEVERE, "OrderLine not saved"); - return false; + + String sql = "SELECT DD_OrderLine_ID FROM DD_OrderLine ol INNER JOIN DD_Order o ON (o.DD_Order_ID=ol.DD_Order_ID) WHERE o.DocStatus IN ('DR','IN') AND o.C_BPartner_ID = ? AND M_Product_ID=? AND ol.M_Locator_ID=? AND ol.DatePromised BETWEEN ? AND ? "; + int DD_OrderLine_ID = DB.getSQLValue(get_TrxName(), sql, new Object[]{detail.getC_BPartner_ID(),product.getM_Product_ID(), m_locator.getM_Locator_ID(), p_DatePromised,p_DatePromised_To}); + + if (DD_OrderLine_ID <= 0) + { + MDDOrderLine line = new MDDOrderLine(order); + line.setAD_Org_ID(bp.getAD_OrgBP_ID_Int()); + line.setM_Locator_ID(m_locator.getM_Locator_ID()); + line.setM_LocatorTo_ID(m_locator_to.getM_Locator_ID()); + line.setIsInvoiced(false); + line.setProduct(product); + line.setQty(detail.getActualAllocation()); + line.setTargetQty(detail.getActualAllocation()); + line.setQtyEntered(detail.getActualAllocation()); + line.setConfirmedQty(detail.getActualAllocation()); + line.setDescription("Distribution Push"); + line.saveEx(); + } + else + { + MDDOrderLine line = new MDDOrderLine(getCtx(), DD_OrderLine_ID, get_TrxName()); + line.setDescription(line.getDescription().concat(" "+Msg.translate(getCtx(), "Qty")+" Pull " + detail.getActualAllocation())); + line.setConfirmedQty(line.getConfirmedQty().add(detail.getActualAllocation())); + line.saveEx(); + } } + else + { + // Create Order Line + MDDOrderLine line = new MDDOrderLine(order); + if (counter && bp.getAD_OrgBP_ID_Int() > 0) + ; // don't overwrite counter doc + /*else // normal - optionally overwrite + { + line.setC_BPartner_ID(detail.getC_BPartner_ID()); + if (detail.getC_BPartner_Location_ID() != 0) + line.setC_BPartner_Location_ID(detail.getC_BPartner_Location_ID()); + }*/ + // + line.setAD_Org_ID(bp.getAD_OrgBP_ID_Int()); + line.setM_Locator_ID(m_locator.getM_Locator_ID()); + line.setM_LocatorTo_ID(m_locator_to.getM_Locator_ID()); + line.setIsInvoiced(false); + line.setProduct(product); + line.setQty(detail.getActualAllocation()); + line.setTargetQty(detail.getActualAllocation()); + line.setQtyEntered(detail.getActualAllocation()); + line.setConfirmedQty(detail.getActualAllocation()); + line.setDescription("Distribution Push"); + if (!line.save()) + { + log.log(Level.SEVERE, "OrderLine not saved"); + return false; + } + } addLog(0,null, detail.getActualAllocation(), order.getDocumentNo() + ": " + bp.getName() + " - " + product.getName()); }