IDEMPIERE-6025 Purchase Credit Memo > Create Lines From not displaying open/deferred matched PO invoice quantities (#2248)

* IDEMPIERE-6025 Purchase Credit Memo > Create Lines From not displaying open/deferred matched PO invoice quantities
This commit is contained in:
Elaine Tan 2024-03-08 12:01:12 +08:00 committed by Carlos Ruiz
parent 7b5d9e578f
commit 2e76fbce5b
5 changed files with 1350 additions and 0 deletions

View File

@ -0,0 +1,79 @@
-- IDEMPIERE-6025 Purchase Credit Memo > Create Lines From not displaying open/deferred matched PO invoice quantities
SELECT register_migration_script('202402291804_IDEMPIERE-6025.sql') FROM dual;
SET SQLBLANKLINES ON
SET DEFINE OFF
-- Feb 29, 2024, 6:04:33 PM MYT
UPDATE AD_ViewComponent SET OtherClause='GROUP BY l.QtyOrdered,CASE WHEN l.QtyOrdered=0 THEN 0 ELSE l.QtyEntered/l.QtyOrdered END,
l.C_UOM_ID, po.VendorProductNo, l.M_Product_ID, l.C_Charge_ID, l.Line, l.C_OrderLine_ID, o.IsSOTrx,
l.AD_Client_ID, l.AD_Org_ID, l.IsActive,l.c_bpartner_id,l.C_Order_ID, m2.Qty, l.QtyInvoiced
HAVING (l.QtyOrdered-(CASE WHEN SUM(m.Qty) IS NULL THEN l.QtyInvoiced ELSE SUM(COALESCE(m.Qty,0))+COALESCE(m2.Qty,0) END) <> 0)
OR (COALESCE(m2.Qty,SUM(COALESCE(m.Qty,0))) <> 0)', FromClause='FROM C_OrderLine l
JOIN C_Order o ON o.C_Order_ID = l.C_Order_ID
LEFT JOIN M_Product_PO po ON l.M_Product_ID = po.M_Product_ID AND l.C_BPartner_ID = po.C_BPartner_ID
LEFT JOIN M_MatchPO m ON l.c_orderline_id = m.C_OrderLine_ID AND m.C_InvoiceLine_ID IS NOT NULL AND COALESCE(m.Reversal_ID,0)=0 AND m.Posted<>''d''
LEFT JOIN (
SELECT m2.C_OrderLine_ID, SUM(COALESCE(m2.Qty,0)) AS Qty
FROM M_MatchPO m2
WHERE m2.C_InvoiceLine_ID IS NOT NULL
AND COALESCE(m2.Reversal_ID,0)=0
AND m2.Posted=''d''
GROUP BY m2.C_OrderLine_ID
) m2 ON l.c_orderline_id = m2.C_OrderLine_ID
LEFT JOIN M_Product p ON l.M_Product_ID = p.M_Product_ID',Updated=TO_TIMESTAMP('2024-02-29 18:04:33','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_ViewComponent_ID=200227
;
-- Feb 29, 2024, 6:05:09 PM MYT
UPDATE AD_ViewColumn SET ColumnSQL='l.QtyOrdered-(CASE WHEN SUM(m.Qty) IS NULL THEN l.QtyInvoiced ELSE SUM(COALESCE(m.Qty,0))+COALESCE(m2.Qty,0) END)',Updated=TO_TIMESTAMP('2024-02-29 18:05:09','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_ViewColumn_ID=217539
;
-- Feb 29, 2024, 6:06:19 PM MYT
UPDATE AD_ViewColumn SET ColumnSQL='COALESCE(m2.Qty,SUM(COALESCE(m.Qty,0)))',Updated=TO_TIMESTAMP('2024-02-29 18:06:19','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_ViewColumn_ID=217538
;
-- Feb 29, 2024, 6:07:01 PM MYT
CREATE OR REPLACE VIEW C_Invoice_CreateFrom_v(CreditQty, Qty, Multiplier, C_UOM_ID, M_Product_ID, C_Charge_ID, VendorProductNo, Line, C_OrderLine_ID, M_InOutLine_ID, M_RMALine_ID, C_BPartner_ID, C_Order_ID, M_InOut_ID, M_RMA_ID, C_Invoice_CreateFrom_v_ID, AD_Client_ID, AD_Org_ID, IsActive, IsSOTrx, AD_Table_ID) AS SELECT COALESCE(m2.Qty,SUM(COALESCE(m.Qty,0))) AS CreditQty, l.QtyOrdered-(CASE WHEN SUM(m.Qty) IS NULL THEN l.QtyInvoiced ELSE SUM(COALESCE(m.Qty,0))+COALESCE(m2.Qty,0) END) AS Qty, CASE WHEN l.QtyOrdered=0 THEN 0 ELSE l.QtyEntered/l.QtyOrdered END AS Multiplier, l.C_UOM_ID AS C_UOM_ID, COALESCE(l.M_Product_ID, 0) AS M_Product_ID, COALESCE(l.C_Charge_ID, 0) AS C_Charge_ID, po.VendorProductNo AS VendorProductNo, l.Line AS Line, l.C_OrderLine_ID AS C_OrderLine_ID, 0 AS M_InOutLine_ID, 0 AS M_RMALine_ID, l.C_BPartner_ID AS C_BPartner_ID, l.C_Order_ID AS C_Order_ID, 0 AS M_InOut_ID, 0 AS M_RMA_ID, l.C_OrderLine_ID AS C_Invoice_CreateFrom_v_ID, l.AD_Client_ID AS AD_Client_ID, l.AD_Org_ID AS AD_Org_ID, l.IsActive AS IsActive, o.IsSOTrx AS IsSOTrx, 260 AS AD_Table_ID FROM C_OrderLine l
JOIN C_Order o ON o.C_Order_ID = l.C_Order_ID
LEFT JOIN M_Product_PO po ON l.M_Product_ID = po.M_Product_ID AND l.C_BPartner_ID = po.C_BPartner_ID
LEFT JOIN M_MatchPO m ON l.c_orderline_id = m.C_OrderLine_ID AND m.C_InvoiceLine_ID IS NOT NULL AND COALESCE(m.Reversal_ID,0)=0 AND m.Posted<>'d'
LEFT JOIN (
SELECT m2.C_OrderLine_ID, SUM(COALESCE(m2.Qty,0)) AS Qty
FROM M_MatchPO m2
WHERE m2.C_InvoiceLine_ID IS NOT NULL
AND COALESCE(m2.Reversal_ID,0)=0
AND m2.Posted='d'
GROUP BY m2.C_OrderLine_ID
) m2 ON l.c_orderline_id = m2.C_OrderLine_ID
LEFT JOIN M_Product p ON l.M_Product_ID = p.M_Product_ID GROUP BY l.QtyOrdered,CASE WHEN l.QtyOrdered=0 THEN 0 ELSE l.QtyEntered/l.QtyOrdered END,
l.C_UOM_ID, po.VendorProductNo, l.M_Product_ID, l.C_Charge_ID, l.Line, l.C_OrderLine_ID, o.IsSOTrx,
l.AD_Client_ID, l.AD_Org_ID, l.IsActive,l.c_bpartner_id,l.C_Order_ID, m2.Qty, l.QtyInvoiced
HAVING (l.QtyOrdered-(CASE WHEN SUM(m.Qty) IS NULL THEN l.QtyInvoiced ELSE SUM(COALESCE(m.Qty,0))+COALESCE(m2.Qty,0) END) <> 0)
OR (COALESCE(m2.Qty,SUM(COALESCE(m.Qty,0))) <> 0) UNION ALL SELECT CASE WHEN io.IsSOTrx='N' THEN (l.Movementqty-SUM(COALESCE(mi.Qty, 0))*CASE WHEN io.MovementType = 'V-' THEN -1 ELSE 1 END) ELSE (l.Movementqty-SUM(COALESCE(mi.Qty, 0))*CASE WHEN io.MovementType = 'V-' THEN -1 ELSE 1 END) END AS CreditQty, l.Movementqty-SUM(COALESCE(mi.Qty, 0))*CASE WHEN io.MovementType = 'V-' THEN -1 ELSE 1 END AS Qty, l.QtyEntered/l.MovementQty AS Multiplier, l.C_UOM_ID AS C_UOM_ID, l.M_Product_ID AS M_Product_ID, l.C_Charge_ID AS C_Charge_ID, po.VendorProductNo AS VendorProductNo, l.Line AS Line, l.C_OrderLine_ID AS C_OrderLine_ID, l.M_InOutLine_ID AS M_InOutLine_ID, 0 AS M_RMALine_ID, io.C_BPartner_ID AS C_BPartner_ID, 0 AS C_Order_ID, l.M_InOut_ID AS M_InOut_ID, 0 AS M_RMA_ID, l.M_InOutLine_ID AS C_Invoice_CreateFrom_v_ID, l.AD_Client_ID AS AD_Client_ID, l.AD_Org_ID AS AD_Org_ID, l.IsActive AS IsActive, io.IsSOTrx AS IsSOTrx, 320 AS AD_Table_ID FROM M_InOutLine l
LEFT JOIN M_Product p ON l.M_Product_ID = p.M_Product_ID
JOIN M_InOut io ON l.m_inout_id= io.M_InOut_ID
LEFT JOIN M_Product_PO po ON l.M_Product_ID = po.M_Product_ID AND io.C_BPartner_ID = po.C_BPartner_ID
LEFT JOIN M_MatchInv mi ON l.M_InOutLine_ID = mi.M_InOutLine_ID WHERE l.MovementQty <> 0 AND io.IsSOTrx='N' GROUP BY io.MovementType, l.MovementQty, l.QtyEntered/l.MovementQty, l.C_UOM_ID, po.VendorProductNo, l.M_Product_ID, l.C_Charge_ID,
l.Line, l.C_OrderLine_ID, l.M_InOutLine_ID, io.C_BPartner_ID, l.M_InOut_ID, io.IsSOTrx, l.AD_Client_ID, l.AD_Org_ID, l.IsActive
HAVING l.MovementQty-SUM(COALESCE(mi.Qty, 0)) <> 0 UNION ALL SELECT l.MovementQty-SUM(COALESCE(il.QtyInvoiced,0)) AS CreditQty, l.MovementQty-SUM(COALESCE(il.QtyInvoiced,0)) AS Qty, l.QtyEntered/l.MovementQty AS Multiplier, l.C_UOM_ID AS C_UOM_ID, l.M_Product_ID AS M_Product_ID, l.C_Charge_ID AS C_Charge_ID, po.VendorProductNo AS VendorProductNo, l.Line AS Line, l.C_OrderLine_ID AS C_OrderLine_ID, l.M_InOutLine_ID AS M_InOutLine_ID, 0 AS M_RMALine_ID, io.C_BPartner_ID AS C_BPartner_ID, 0 AS C_Order_ID, l.M_InOut_ID AS M_InOut_ID, 0 AS M_RMA_ID, l.M_InOutLine_ID AS C_Invoice_CreateFrom_v_ID, l.AD_Client_ID AS AD_Client_ID, l.AD_Org_ID AS AD_Org_ID, l.IsActive AS IsActive, io.IsSOTrx AS IsSOTrx, 320 AS AD_Table_ID FROM M_InOutLine l
LEFT JOIN M_Product p ON l.M_Product_ID = p.M_Product_ID
JOIN M_InOut io ON l.m_inout_id= io.M_InOut_ID
LEFT JOIN M_Product_PO po ON l.M_Product_ID = po.M_Product_ID AND io.C_BPartner_ID = po.C_BPartner_ID
LEFT JOIN C_InvoiceLine il ON l.M_InOutLine_ID = il.M_InOutLine_ID WHERE l.MovementQty <> 0 AND io.IsSOTrx='Y' GROUP BY io.MovementType, l.MovementQty, l.QtyEntered/l.MovementQty, l.C_UOM_ID, po.VendorProductNo, l.M_Product_ID, l.C_Charge_ID,
l.Line, l.C_OrderLine_ID, l.M_InOutLine_ID, io.C_BPartner_ID, l.M_InOut_ID, io.IsSOTrx, l.AD_Client_ID, l.AD_Org_ID, l.IsActive
HAVING l.MovementQty-SUM(COALESCE(il.QtyInvoiced,0)) <> 0 UNION ALL SELECT rl.Qty - COALESCE(rl.QtyInvoiced, 0) AS CreditQty, rl.Qty - COALESCE(rl.QtyInvoiced, 0) AS Qty, 1 AS Multiplier, uom.C_UOM_ID AS C_UOM_ID, p.M_Product_ID AS M_Product_ID, c.C_Charge_ID AS C_Charge_ID, po.VendorProductNo AS VendorProductNo, rl.Line AS Line, 0 AS C_OrderLine_ID, 0 AS M_InOutLine_ID, rl.M_RMALine_ID AS M_RMALine_ID, r.C_BPartner_ID AS C_BPartner_ID, 0 AS C_Order_ID, 0 AS M_InOut_ID, r.m_rma_id AS M_RMA_ID, rl.M_RMALine_ID AS C_Invoice_CreateFrom_v_ID, rl.AD_Client_ID AS AD_Client_ID, rl.AD_Org_ID AS AD_Org_ID, rl.IsActive AS IsActive, r.IsSOTrx AS IsSOTrx, 660 AS AD_Table_ID FROM m_rmaline rl
JOIN m_rma r ON r.m_rma_id = rl.m_rma_id
JOIN m_inoutline iol ON rl.m_inoutline_id = iol.m_inoutline_id
LEFT JOIN m_product p ON p.m_product_id = iol.m_product_id
LEFT JOIN c_uom uom ON uom.c_uom_id = COALESCE(p.c_uom_id, iol.c_uom_id)
LEFT JOIN c_charge c ON c.c_charge_id = iol.c_charge_id
LEFT JOIN m_product_po po ON rl.m_product_id = po.m_product_id AND r.c_bpartner_id = po.c_bpartner_id WHERE rl.m_inoutline_id IS NOT NULL UNION ALL SELECT rl.Qty - COALESCE(rl.QtyInvoiced, 0) AS CreditQty, rl.Qty - COALESCE(rl.QtyInvoiced, 0) AS Qty, 1 AS Multiplier, uom.C_UOM_ID AS C_UOM_ID, p.M_Product_ID AS M_Product_ID, 0 AS C_Charge_ID, po.VendorProductNo AS VendorProductNo, rl.Line AS Line, 0 AS C_OrderLine_ID, 0 AS M_InOutLine_ID, rl.M_RMALine_ID AS M_RMALine_ID, r.C_BPartner_ID AS C_BPartner_ID, 0 AS C_Order_ID, 0 AS M_InOut_ID, r.M_RMA_ID AS M_RMA_ID, rl.M_RMALine_ID AS C_Invoice_CreateFrom_v_ID, rl.AD_Client_ID AS AD_Client_ID, rl.AD_Org_ID AS AD_Org_ID, rl.IsActive AS IsActive, r.IsSOTrx AS IsSOTrx, 660 AS AD_Table_ID FROM m_rmaline rl
JOIN m_rma r ON r.m_rma_id = rl.m_rma_id
JOIN m_product p ON p.m_product_id = rl.m_product_id
LEFT JOIN c_uom uom ON uom.c_uom_id = p.c_uom_id
LEFT JOIN m_product_po po ON rl.m_product_id = po.m_product_id AND r.c_bpartner_id = po.c_bpartner_id WHERE rl.m_product_id IS NOT NULL AND rl.m_inoutline_id IS NULL UNION ALL SELECT rl.Qty - COALESCE(rl.QtyInvoiced, 0) AS CreditQty, rl.Qty - COALESCE(rl.QtyInvoiced, 0) AS Qty, 1 AS Multiplier, uom.C_UOM_ID AS C_UOM_ID, 0 AS M_Product_ID, c.C_Charge_ID AS C_Charge_ID, NULL AS VendorProductNo, rl.Line AS Line, 0 AS C_OrderLine_ID, 0 AS M_InOutLine_ID, rl.M_RMALine_ID AS M_RMALine_ID, r.C_BPartner_ID AS C_BPartner_ID, 0 AS C_Order_ID, 0 AS M_InOut_ID, r.m_rma_id AS M_RMA_ID, rl.M_RMALine_ID AS C_Invoice_CreateFrom_v_ID, rl.AD_Client_ID AS AD_Client_ID, rl.AD_Org_ID AS AD_Org_ID, rl.IsActive AS IsActive, r.IsSOTrx AS IsSOTrx, 660 AS AD_Table_ID FROM m_rmaline rl
JOIN m_rma r ON r.m_rma_id = rl.m_rma_id
JOIN c_charge c ON c.c_charge_id = rl.c_charge_id
LEFT JOIN c_uom uom ON uom.c_uom_id = 100 WHERE rl.c_charge_id IS NOT NULL AND rl.m_inoutline_id IS NULL
;

View File

@ -0,0 +1,59 @@
-- IDEMPIERE-6025 Purchase Credit Memo > Create Lines From not displaying open/deferred matched PO invoice quantities
SELECT register_migration_script('202403051827_IDEMPIERE-6025.sql') FROM dual;
SET SQLBLANKLINES ON
SET DEFINE OFF
-- Mar 5, 2024, 6:27:42 PM MYT
UPDATE AD_ViewComponent SET OtherClause='GROUP BY l.QtyOrdered,CASE WHEN l.QtyOrdered=0 THEN 0 ELSE l.QtyEntered/l.QtyOrdered END,
l.C_UOM_ID, po.VendorProductNo, l.M_Product_ID, l.C_Charge_ID, l.Line, l.C_OrderLine_ID, o.IsSOTrx,
l.AD_Client_ID, l.AD_Org_ID, l.IsActive,l.c_bpartner_id,l.C_Order_ID, m2.Qty, l.QtyInvoiced
HAVING (l.QtyOrdered-(CASE WHEN SUM(m.Qty) IS NULL THEN l.QtyInvoiced ELSE SUM(COALESCE(m.Qty,0))+COALESCE(m2.Qty,0) END) <> 0)
OR (COALESCE(m2.Qty,0) <> 0)',Updated=TO_TIMESTAMP('2024-03-05 18:27:42','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_ViewComponent_ID=200227
;
-- Mar 5, 2024, 6:27:54 PM MYT
CREATE OR REPLACE VIEW C_Invoice_CreateFrom_v(CreditQty, Qty, Multiplier, C_UOM_ID, M_Product_ID, C_Charge_ID, VendorProductNo, Line, C_OrderLine_ID, M_InOutLine_ID, M_RMALine_ID, C_BPartner_ID, C_Order_ID, M_InOut_ID, M_RMA_ID, C_Invoice_CreateFrom_v_ID, AD_Client_ID, AD_Org_ID, IsActive, IsSOTrx, AD_Table_ID) AS SELECT COALESCE(m2.Qty,SUM(COALESCE(m.Qty,0))) AS CreditQty, l.QtyOrdered-(CASE WHEN SUM(m.Qty) IS NULL THEN l.QtyInvoiced ELSE SUM(COALESCE(m.Qty,0))+COALESCE(m2.Qty,0) END) AS Qty, CASE WHEN l.QtyOrdered=0 THEN 0 ELSE l.QtyEntered/l.QtyOrdered END AS Multiplier, l.C_UOM_ID AS C_UOM_ID, COALESCE(l.M_Product_ID, 0) AS M_Product_ID, COALESCE(l.C_Charge_ID, 0) AS C_Charge_ID, po.VendorProductNo AS VendorProductNo, l.Line AS Line, l.C_OrderLine_ID AS C_OrderLine_ID, 0 AS M_InOutLine_ID, 0 AS M_RMALine_ID, l.C_BPartner_ID AS C_BPartner_ID, l.C_Order_ID AS C_Order_ID, 0 AS M_InOut_ID, 0 AS M_RMA_ID, l.C_OrderLine_ID AS C_Invoice_CreateFrom_v_ID, l.AD_Client_ID AS AD_Client_ID, l.AD_Org_ID AS AD_Org_ID, l.IsActive AS IsActive, o.IsSOTrx AS IsSOTrx, 260 AS AD_Table_ID FROM C_OrderLine l
JOIN C_Order o ON o.C_Order_ID = l.C_Order_ID
LEFT JOIN M_Product_PO po ON l.M_Product_ID = po.M_Product_ID AND l.C_BPartner_ID = po.C_BPartner_ID
LEFT JOIN M_MatchPO m ON l.c_orderline_id = m.C_OrderLine_ID AND m.C_InvoiceLine_ID IS NOT NULL AND COALESCE(m.Reversal_ID,0)=0 AND m.Posted<>'d'
LEFT JOIN (
SELECT m2.C_OrderLine_ID, SUM(COALESCE(m2.Qty,0)) AS Qty
FROM M_MatchPO m2
WHERE m2.C_InvoiceLine_ID IS NOT NULL
AND COALESCE(m2.Reversal_ID,0)=0
AND m2.Posted='d'
GROUP BY m2.C_OrderLine_ID
) m2 ON l.c_orderline_id = m2.C_OrderLine_ID
LEFT JOIN M_Product p ON l.M_Product_ID = p.M_Product_ID GROUP BY l.QtyOrdered,CASE WHEN l.QtyOrdered=0 THEN 0 ELSE l.QtyEntered/l.QtyOrdered END,
l.C_UOM_ID, po.VendorProductNo, l.M_Product_ID, l.C_Charge_ID, l.Line, l.C_OrderLine_ID, o.IsSOTrx,
l.AD_Client_ID, l.AD_Org_ID, l.IsActive,l.c_bpartner_id,l.C_Order_ID, m2.Qty, l.QtyInvoiced
HAVING (l.QtyOrdered-(CASE WHEN SUM(m.Qty) IS NULL THEN l.QtyInvoiced ELSE SUM(COALESCE(m.Qty,0))+COALESCE(m2.Qty,0) END) <> 0)
OR (COALESCE(m2.Qty,0) <> 0) UNION ALL SELECT CASE WHEN io.IsSOTrx='N' THEN (l.Movementqty-SUM(COALESCE(mi.Qty, 0))*CASE WHEN io.MovementType = 'V-' THEN -1 ELSE 1 END) ELSE (l.Movementqty-SUM(COALESCE(mi.Qty, 0))*CASE WHEN io.MovementType = 'V-' THEN -1 ELSE 1 END) END AS CreditQty, l.Movementqty-SUM(COALESCE(mi.Qty, 0))*CASE WHEN io.MovementType = 'V-' THEN -1 ELSE 1 END AS Qty, l.QtyEntered/l.MovementQty AS Multiplier, l.C_UOM_ID AS C_UOM_ID, l.M_Product_ID AS M_Product_ID, l.C_Charge_ID AS C_Charge_ID, po.VendorProductNo AS VendorProductNo, l.Line AS Line, l.C_OrderLine_ID AS C_OrderLine_ID, l.M_InOutLine_ID AS M_InOutLine_ID, 0 AS M_RMALine_ID, io.C_BPartner_ID AS C_BPartner_ID, 0 AS C_Order_ID, l.M_InOut_ID AS M_InOut_ID, 0 AS M_RMA_ID, l.M_InOutLine_ID AS C_Invoice_CreateFrom_v_ID, l.AD_Client_ID AS AD_Client_ID, l.AD_Org_ID AS AD_Org_ID, l.IsActive AS IsActive, io.IsSOTrx AS IsSOTrx, 320 AS AD_Table_ID FROM M_InOutLine l
LEFT JOIN M_Product p ON l.M_Product_ID = p.M_Product_ID
JOIN M_InOut io ON l.m_inout_id= io.M_InOut_ID
LEFT JOIN M_Product_PO po ON l.M_Product_ID = po.M_Product_ID AND io.C_BPartner_ID = po.C_BPartner_ID
LEFT JOIN M_MatchInv mi ON l.M_InOutLine_ID = mi.M_InOutLine_ID WHERE l.MovementQty <> 0 AND io.IsSOTrx='N' GROUP BY io.MovementType, l.MovementQty, l.QtyEntered/l.MovementQty, l.C_UOM_ID, po.VendorProductNo, l.M_Product_ID, l.C_Charge_ID,
l.Line, l.C_OrderLine_ID, l.M_InOutLine_ID, io.C_BPartner_ID, l.M_InOut_ID, io.IsSOTrx, l.AD_Client_ID, l.AD_Org_ID, l.IsActive
HAVING l.MovementQty-SUM(COALESCE(mi.Qty, 0)) <> 0 UNION ALL SELECT l.MovementQty-SUM(COALESCE(il.QtyInvoiced,0)) AS CreditQty, l.MovementQty-SUM(COALESCE(il.QtyInvoiced,0)) AS Qty, l.QtyEntered/l.MovementQty AS Multiplier, l.C_UOM_ID AS C_UOM_ID, l.M_Product_ID AS M_Product_ID, l.C_Charge_ID AS C_Charge_ID, po.VendorProductNo AS VendorProductNo, l.Line AS Line, l.C_OrderLine_ID AS C_OrderLine_ID, l.M_InOutLine_ID AS M_InOutLine_ID, 0 AS M_RMALine_ID, io.C_BPartner_ID AS C_BPartner_ID, 0 AS C_Order_ID, l.M_InOut_ID AS M_InOut_ID, 0 AS M_RMA_ID, l.M_InOutLine_ID AS C_Invoice_CreateFrom_v_ID, l.AD_Client_ID AS AD_Client_ID, l.AD_Org_ID AS AD_Org_ID, l.IsActive AS IsActive, io.IsSOTrx AS IsSOTrx, 320 AS AD_Table_ID FROM M_InOutLine l
LEFT JOIN M_Product p ON l.M_Product_ID = p.M_Product_ID
JOIN M_InOut io ON l.m_inout_id= io.M_InOut_ID
LEFT JOIN M_Product_PO po ON l.M_Product_ID = po.M_Product_ID AND io.C_BPartner_ID = po.C_BPartner_ID
LEFT JOIN C_InvoiceLine il ON l.M_InOutLine_ID = il.M_InOutLine_ID WHERE l.MovementQty <> 0 AND io.IsSOTrx='Y' GROUP BY io.MovementType, l.MovementQty, l.QtyEntered/l.MovementQty, l.C_UOM_ID, po.VendorProductNo, l.M_Product_ID, l.C_Charge_ID,
l.Line, l.C_OrderLine_ID, l.M_InOutLine_ID, io.C_BPartner_ID, l.M_InOut_ID, io.IsSOTrx, l.AD_Client_ID, l.AD_Org_ID, l.IsActive
HAVING l.MovementQty-SUM(COALESCE(il.QtyInvoiced,0)) <> 0 UNION ALL SELECT rl.Qty - COALESCE(rl.QtyInvoiced, 0) AS CreditQty, rl.Qty - COALESCE(rl.QtyInvoiced, 0) AS Qty, 1 AS Multiplier, uom.C_UOM_ID AS C_UOM_ID, p.M_Product_ID AS M_Product_ID, c.C_Charge_ID AS C_Charge_ID, po.VendorProductNo AS VendorProductNo, rl.Line AS Line, 0 AS C_OrderLine_ID, 0 AS M_InOutLine_ID, rl.M_RMALine_ID AS M_RMALine_ID, r.C_BPartner_ID AS C_BPartner_ID, 0 AS C_Order_ID, 0 AS M_InOut_ID, r.m_rma_id AS M_RMA_ID, rl.M_RMALine_ID AS C_Invoice_CreateFrom_v_ID, rl.AD_Client_ID AS AD_Client_ID, rl.AD_Org_ID AS AD_Org_ID, rl.IsActive AS IsActive, r.IsSOTrx AS IsSOTrx, 660 AS AD_Table_ID FROM m_rmaline rl
JOIN m_rma r ON r.m_rma_id = rl.m_rma_id
JOIN m_inoutline iol ON rl.m_inoutline_id = iol.m_inoutline_id
LEFT JOIN m_product p ON p.m_product_id = iol.m_product_id
LEFT JOIN c_uom uom ON uom.c_uom_id = COALESCE(p.c_uom_id, iol.c_uom_id)
LEFT JOIN c_charge c ON c.c_charge_id = iol.c_charge_id
LEFT JOIN m_product_po po ON rl.m_product_id = po.m_product_id AND r.c_bpartner_id = po.c_bpartner_id WHERE rl.m_inoutline_id IS NOT NULL UNION ALL SELECT rl.Qty - COALESCE(rl.QtyInvoiced, 0) AS CreditQty, rl.Qty - COALESCE(rl.QtyInvoiced, 0) AS Qty, 1 AS Multiplier, uom.C_UOM_ID AS C_UOM_ID, p.M_Product_ID AS M_Product_ID, 0 AS C_Charge_ID, po.VendorProductNo AS VendorProductNo, rl.Line AS Line, 0 AS C_OrderLine_ID, 0 AS M_InOutLine_ID, rl.M_RMALine_ID AS M_RMALine_ID, r.C_BPartner_ID AS C_BPartner_ID, 0 AS C_Order_ID, 0 AS M_InOut_ID, r.M_RMA_ID AS M_RMA_ID, rl.M_RMALine_ID AS C_Invoice_CreateFrom_v_ID, rl.AD_Client_ID AS AD_Client_ID, rl.AD_Org_ID AS AD_Org_ID, rl.IsActive AS IsActive, r.IsSOTrx AS IsSOTrx, 660 AS AD_Table_ID FROM m_rmaline rl
JOIN m_rma r ON r.m_rma_id = rl.m_rma_id
JOIN m_product p ON p.m_product_id = rl.m_product_id
LEFT JOIN c_uom uom ON uom.c_uom_id = p.c_uom_id
LEFT JOIN m_product_po po ON rl.m_product_id = po.m_product_id AND r.c_bpartner_id = po.c_bpartner_id WHERE rl.m_product_id IS NOT NULL AND rl.m_inoutline_id IS NULL UNION ALL SELECT rl.Qty - COALESCE(rl.QtyInvoiced, 0) AS CreditQty, rl.Qty - COALESCE(rl.QtyInvoiced, 0) AS Qty, 1 AS Multiplier, uom.C_UOM_ID AS C_UOM_ID, 0 AS M_Product_ID, c.C_Charge_ID AS C_Charge_ID, NULL AS VendorProductNo, rl.Line AS Line, 0 AS C_OrderLine_ID, 0 AS M_InOutLine_ID, rl.M_RMALine_ID AS M_RMALine_ID, r.C_BPartner_ID AS C_BPartner_ID, 0 AS C_Order_ID, 0 AS M_InOut_ID, r.m_rma_id AS M_RMA_ID, rl.M_RMALine_ID AS C_Invoice_CreateFrom_v_ID, rl.AD_Client_ID AS AD_Client_ID, rl.AD_Org_ID AS AD_Org_ID, rl.IsActive AS IsActive, r.IsSOTrx AS IsSOTrx, 660 AS AD_Table_ID FROM m_rmaline rl
JOIN m_rma r ON r.m_rma_id = rl.m_rma_id
JOIN c_charge c ON c.c_charge_id = rl.c_charge_id
LEFT JOIN c_uom uom ON uom.c_uom_id = 100 WHERE rl.c_charge_id IS NOT NULL AND rl.m_inoutline_id IS NULL
;

View File

@ -0,0 +1,358 @@
-- IDEMPIERE-6025 Purchase Credit Memo > Create Lines From not displaying open/deferred matched PO invoice quantities
SELECT register_migration_script('202402291804_IDEMPIERE-6025.sql') FROM dual;
-- Feb 29, 2024, 6:04:33 PM MYT
UPDATE AD_ViewComponent SET OtherClause='GROUP BY l.QtyOrdered,CASE WHEN l.QtyOrdered=0 THEN 0 ELSE l.QtyEntered/l.QtyOrdered END,
l.C_UOM_ID, po.VendorProductNo, l.M_Product_ID, l.C_Charge_ID, l.Line, l.C_OrderLine_ID, o.IsSOTrx,
l.AD_Client_ID, l.AD_Org_ID, l.IsActive,l.c_bpartner_id,l.C_Order_ID, m2.Qty, l.QtyInvoiced
HAVING (l.QtyOrdered-(CASE WHEN SUM(m.Qty) IS NULL THEN l.QtyInvoiced ELSE SUM(COALESCE(m.Qty,0))+COALESCE(m2.Qty,0) END) <> 0)
OR (COALESCE(m2.Qty,SUM(COALESCE(m.Qty,0))) <> 0)', FromClause='FROM C_OrderLine l
JOIN C_Order o ON o.C_Order_ID = l.C_Order_ID
LEFT JOIN M_Product_PO po ON l.M_Product_ID = po.M_Product_ID AND l.C_BPartner_ID = po.C_BPartner_ID
LEFT JOIN M_MatchPO m ON l.c_orderline_id = m.C_OrderLine_ID AND m.C_InvoiceLine_ID IS NOT NULL AND COALESCE(m.Reversal_ID,0)=0 AND m.Posted<>''d''
LEFT JOIN (
SELECT m2.C_OrderLine_ID, SUM(COALESCE(m2.Qty,0)) AS Qty
FROM M_MatchPO m2
WHERE m2.C_InvoiceLine_ID IS NOT NULL
AND COALESCE(m2.Reversal_ID,0)=0
AND m2.Posted=''d''
GROUP BY m2.C_OrderLine_ID
) m2 ON l.c_orderline_id = m2.C_OrderLine_ID
LEFT JOIN M_Product p ON l.M_Product_ID = p.M_Product_ID',Updated=TO_TIMESTAMP('2024-02-29 18:04:33','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_ViewComponent_ID=200227
;
-- Feb 29, 2024, 6:05:09 PM MYT
UPDATE AD_ViewColumn SET ColumnSQL='l.QtyOrdered-(CASE WHEN SUM(m.Qty) IS NULL THEN l.QtyInvoiced ELSE SUM(COALESCE(m.Qty,0))+COALESCE(m2.Qty,0) END)',Updated=TO_TIMESTAMP('2024-02-29 18:05:09','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_ViewColumn_ID=217539
;
-- Feb 29, 2024, 6:06:19 PM MYT
UPDATE AD_ViewColumn SET ColumnSQL='COALESCE(m2.Qty,SUM(COALESCE(m.Qty,0)))',Updated=TO_TIMESTAMP('2024-02-29 18:06:19','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_ViewColumn_ID=217538
;
-- Feb 29, 2024, 6:07:01 PM MYT
CREATE OR REPLACE VIEW C_INVOICE_CREATEFROM_V (
CREDITQTY,
QTY,
MULTIPLIER,
C_UOM_ID,
M_PRODUCT_ID,
C_CHARGE_ID,
VENDORPRODUCTNO,
LINE,
C_ORDERLINE_ID,
M_INOUTLINE_ID,
M_RMALINE_ID,
C_BPARTNER_ID,
C_ORDER_ID,
M_INOUT_ID,
M_RMA_ID,
C_INVOICE_CREATEFROM_V_ID,
AD_CLIENT_ID,
AD_ORG_ID,
ISACTIVE,
ISSOTRX,
AD_TABLE_ID
) AS
SELECT
COALESCE(M2.QTY, SUM(COALESCE(M.QTY, 0))) AS CREDITQTY,
L.QTYORDERED - (
CASE
WHEN SUM(M.QTY) IS NULL THEN L.QTYINVOICED
ELSE SUM(COALESCE(M.QTY, 0)) + COALESCE(M2.QTY, 0)
END
) AS QTY,
CASE
WHEN L.QTYORDERED = 0 THEN 0
ELSE L.QTYENTERED / L.QTYORDERED
END AS MULTIPLIER,
L.C_UOM_ID AS C_UOM_ID,
COALESCE(L.M_PRODUCT_ID, 0) AS M_PRODUCT_ID,
COALESCE(L.C_CHARGE_ID, 0) AS C_CHARGE_ID,
PO.VENDORPRODUCTNO AS VENDORPRODUCTNO,
L.LINE AS LINE,
L.C_ORDERLINE_ID AS C_ORDERLINE_ID,
0 AS M_INOUTLINE_ID,
0 AS M_RMALINE_ID,
L.C_BPARTNER_ID AS C_BPARTNER_ID,
L.C_ORDER_ID AS C_ORDER_ID,
0 AS M_INOUT_ID,
0 AS M_RMA_ID,
L.C_ORDERLINE_ID AS C_INVOICE_CREATEFROM_V_ID,
L.AD_CLIENT_ID AS AD_CLIENT_ID,
L.AD_ORG_ID AS AD_ORG_ID,
L.ISACTIVE AS ISACTIVE,
O.ISSOTRX AS ISSOTRX,
260 AS AD_TABLE_ID
FROM
C_ORDERLINE L
JOIN C_ORDER O ON O.C_ORDER_ID = L.C_ORDER_ID
LEFT JOIN M_PRODUCT_PO PO ON L.M_PRODUCT_ID = PO.M_PRODUCT_ID
AND L.C_BPARTNER_ID = PO.C_BPARTNER_ID
LEFT JOIN M_MATCHPO M ON L.C_ORDERLINE_ID = M.C_ORDERLINE_ID
AND M.C_INVOICELINE_ID IS NOT NULL
AND COALESCE(M.REVERSAL_ID, 0) = 0
AND M.POSTED <> 'd'
LEFT JOIN (
SELECT
M2.C_ORDERLINE_ID,
SUM(COALESCE(M2.QTY, 0)) AS QTY
FROM
M_MATCHPO M2
WHERE
M2.C_INVOICELINE_ID IS NOT NULL
AND COALESCE(M2.REVERSAL_ID, 0) = 0
AND M2.POSTED = 'd'
GROUP BY
M2.C_ORDERLINE_ID
) M2 ON L.C_ORDERLINE_ID = M2.C_ORDERLINE_ID
LEFT JOIN M_PRODUCT P ON L.M_PRODUCT_ID = P.M_PRODUCT_ID
GROUP BY
L.QTYORDERED,
CASE
WHEN L.QTYORDERED = 0 THEN 0
ELSE L.QTYENTERED / L.QTYORDERED
END,
L.C_UOM_ID,
PO.VENDORPRODUCTNO,
L.M_PRODUCT_ID,
L.C_CHARGE_ID,
L.LINE,
L.C_ORDERLINE_ID,
O.ISSOTRX,
L.AD_CLIENT_ID,
L.AD_ORG_ID,
L.ISACTIVE,
L.C_BPARTNER_ID,
L.C_ORDER_ID,
M2.QTY,
L.QTYINVOICED
HAVING
(
L.QTYORDERED - (
CASE
WHEN SUM(M.QTY) IS NULL THEN L.QTYINVOICED
ELSE SUM(COALESCE(M.QTY, 0)) + COALESCE(M2.QTY, 0)
END
) <> 0
)
OR (COALESCE(M2.QTY, SUM(COALESCE(M.QTY, 0))) <> 0)
UNION ALL
SELECT
CASE
WHEN IO.ISSOTRX = 'N' THEN (
L.MOVEMENTQTY - SUM(COALESCE(MI.QTY, 0)) * CASE
WHEN IO.MOVEMENTTYPE = 'V-' THEN -1
ELSE 1
END
)
ELSE (
L.MOVEMENTQTY - SUM(COALESCE(MI.QTY, 0)) * CASE
WHEN IO.MOVEMENTTYPE = 'V-' THEN -1
ELSE 1
END
)
END AS CREDITQTY,
L.MOVEMENTQTY - SUM(COALESCE(MI.QTY, 0)) * CASE
WHEN IO.MOVEMENTTYPE = 'V-' THEN -1
ELSE 1
END AS QTY,
L.QTYENTERED / L.MOVEMENTQTY AS MULTIPLIER,
L.C_UOM_ID AS C_UOM_ID,
L.M_PRODUCT_ID AS M_PRODUCT_ID,
L.C_CHARGE_ID AS C_CHARGE_ID,
PO.VENDORPRODUCTNO AS VENDORPRODUCTNO,
L.LINE AS LINE,
L.C_ORDERLINE_ID AS C_ORDERLINE_ID,
L.M_INOUTLINE_ID AS M_INOUTLINE_ID,
0 AS M_RMALINE_ID,
IO.C_BPARTNER_ID AS C_BPARTNER_ID,
0 AS C_ORDER_ID,
L.M_INOUT_ID AS M_INOUT_ID,
0 AS M_RMA_ID,
L.M_INOUTLINE_ID AS C_INVOICE_CREATEFROM_V_ID,
L.AD_CLIENT_ID AS AD_CLIENT_ID,
L.AD_ORG_ID AS AD_ORG_ID,
L.ISACTIVE AS ISACTIVE,
IO.ISSOTRX AS ISSOTRX,
320 AS AD_TABLE_ID
FROM
M_INOUTLINE L
LEFT JOIN M_PRODUCT P ON L.M_PRODUCT_ID = P.M_PRODUCT_ID
JOIN M_INOUT IO ON L.M_INOUT_ID = IO.M_INOUT_ID
LEFT JOIN M_PRODUCT_PO PO ON L.M_PRODUCT_ID = PO.M_PRODUCT_ID
AND IO.C_BPARTNER_ID = PO.C_BPARTNER_ID
LEFT JOIN M_MATCHINV MI ON L.M_INOUTLINE_ID = MI.M_INOUTLINE_ID
WHERE
L.MOVEMENTQTY <> 0
AND IO.ISSOTRX = 'N'
GROUP BY
IO.MOVEMENTTYPE,
L.MOVEMENTQTY,
L.QTYENTERED / L.MOVEMENTQTY,
L.C_UOM_ID,
PO.VENDORPRODUCTNO,
L.M_PRODUCT_ID,
L.C_CHARGE_ID,
L.LINE,
L.C_ORDERLINE_ID,
L.M_INOUTLINE_ID,
IO.C_BPARTNER_ID,
L.M_INOUT_ID,
IO.ISSOTRX,
L.AD_CLIENT_ID,
L.AD_ORG_ID,
L.ISACTIVE
HAVING
L.MOVEMENTQTY - SUM(COALESCE(MI.QTY, 0)) <> 0
UNION ALL
SELECT
L.MOVEMENTQTY - SUM(COALESCE(IL.QTYINVOICED, 0)) AS CREDITQTY,
L.MOVEMENTQTY - SUM(COALESCE(IL.QTYINVOICED, 0)) AS QTY,
L.QTYENTERED / L.MOVEMENTQTY AS MULTIPLIER,
L.C_UOM_ID AS C_UOM_ID,
L.M_PRODUCT_ID AS M_PRODUCT_ID,
L.C_CHARGE_ID AS C_CHARGE_ID,
PO.VENDORPRODUCTNO AS VENDORPRODUCTNO,
L.LINE AS LINE,
L.C_ORDERLINE_ID AS C_ORDERLINE_ID,
L.M_INOUTLINE_ID AS M_INOUTLINE_ID,
0 AS M_RMALINE_ID,
IO.C_BPARTNER_ID AS C_BPARTNER_ID,
0 AS C_ORDER_ID,
L.M_INOUT_ID AS M_INOUT_ID,
0 AS M_RMA_ID,
L.M_INOUTLINE_ID AS C_INVOICE_CREATEFROM_V_ID,
L.AD_CLIENT_ID AS AD_CLIENT_ID,
L.AD_ORG_ID AS AD_ORG_ID,
L.ISACTIVE AS ISACTIVE,
IO.ISSOTRX AS ISSOTRX,
320 AS AD_TABLE_ID
FROM
M_INOUTLINE L
LEFT JOIN M_PRODUCT P ON L.M_PRODUCT_ID = P.M_PRODUCT_ID
JOIN M_INOUT IO ON L.M_INOUT_ID = IO.M_INOUT_ID
LEFT JOIN M_PRODUCT_PO PO ON L.M_PRODUCT_ID = PO.M_PRODUCT_ID
AND IO.C_BPARTNER_ID = PO.C_BPARTNER_ID
LEFT JOIN C_INVOICELINE IL ON L.M_INOUTLINE_ID = IL.M_INOUTLINE_ID
WHERE
L.MOVEMENTQTY <> 0
AND IO.ISSOTRX = 'Y'
GROUP BY
IO.MOVEMENTTYPE,
L.MOVEMENTQTY,
L.QTYENTERED / L.MOVEMENTQTY,
L.C_UOM_ID,
PO.VENDORPRODUCTNO,
L.M_PRODUCT_ID,
L.C_CHARGE_ID,
L.LINE,
L.C_ORDERLINE_ID,
L.M_INOUTLINE_ID,
IO.C_BPARTNER_ID,
L.M_INOUT_ID,
IO.ISSOTRX,
L.AD_CLIENT_ID,
L.AD_ORG_ID,
L.ISACTIVE
HAVING
L.MOVEMENTQTY - SUM(COALESCE(IL.QTYINVOICED, 0)) <> 0
UNION ALL
SELECT
RL.QTY - COALESCE(RL.QTYINVOICED, 0) AS CREDITQTY,
RL.QTY - COALESCE(RL.QTYINVOICED, 0) AS QTY,
1 AS MULTIPLIER,
UOM.C_UOM_ID AS C_UOM_ID,
P.M_PRODUCT_ID AS M_PRODUCT_ID,
C.C_CHARGE_ID AS C_CHARGE_ID,
PO.VENDORPRODUCTNO AS VENDORPRODUCTNO,
RL.LINE AS LINE,
0 AS C_ORDERLINE_ID,
0 AS M_INOUTLINE_ID,
RL.M_RMALINE_ID AS M_RMALINE_ID,
R.C_BPARTNER_ID AS C_BPARTNER_ID,
0 AS C_ORDER_ID,
0 AS M_INOUT_ID,
R.M_RMA_ID AS M_RMA_ID,
RL.M_RMALINE_ID AS C_INVOICE_CREATEFROM_V_ID,
RL.AD_CLIENT_ID AS AD_CLIENT_ID,
RL.AD_ORG_ID AS AD_ORG_ID,
RL.ISACTIVE AS ISACTIVE,
R.ISSOTRX AS ISSOTRX,
660 AS AD_TABLE_ID
FROM
M_RMALINE RL
JOIN M_RMA R ON R.M_RMA_ID = RL.M_RMA_ID
JOIN M_INOUTLINE IOL ON RL.M_INOUTLINE_ID = IOL.M_INOUTLINE_ID
LEFT JOIN M_PRODUCT P ON P.M_PRODUCT_ID = IOL.M_PRODUCT_ID
LEFT JOIN C_UOM UOM ON UOM.C_UOM_ID = COALESCE(P.C_UOM_ID, IOL.C_UOM_ID)
LEFT JOIN C_CHARGE C ON C.C_CHARGE_ID = IOL.C_CHARGE_ID
LEFT JOIN M_PRODUCT_PO PO ON RL.M_PRODUCT_ID = PO.M_PRODUCT_ID
AND R.C_BPARTNER_ID = PO.C_BPARTNER_ID
WHERE
RL.M_INOUTLINE_ID IS NOT NULL
UNION ALL
SELECT
RL.QTY - COALESCE(RL.QTYINVOICED, 0) AS CREDITQTY,
RL.QTY - COALESCE(RL.QTYINVOICED, 0) AS QTY,
1 AS MULTIPLIER,
UOM.C_UOM_ID AS C_UOM_ID,
P.M_PRODUCT_ID AS M_PRODUCT_ID,
0 AS C_CHARGE_ID,
PO.VENDORPRODUCTNO AS VENDORPRODUCTNO,
RL.LINE AS LINE,
0 AS C_ORDERLINE_ID,
0 AS M_INOUTLINE_ID,
RL.M_RMALINE_ID AS M_RMALINE_ID,
R.C_BPARTNER_ID AS C_BPARTNER_ID,
0 AS C_ORDER_ID,
0 AS M_INOUT_ID,
R.M_RMA_ID AS M_RMA_ID,
RL.M_RMALINE_ID AS C_INVOICE_CREATEFROM_V_ID,
RL.AD_CLIENT_ID AS AD_CLIENT_ID,
RL.AD_ORG_ID AS AD_ORG_ID,
RL.ISACTIVE AS ISACTIVE,
R.ISSOTRX AS ISSOTRX,
660 AS AD_TABLE_ID
FROM
M_RMALINE RL
JOIN M_RMA R ON R.M_RMA_ID = RL.M_RMA_ID
JOIN M_PRODUCT P ON P.M_PRODUCT_ID = RL.M_PRODUCT_ID
LEFT JOIN C_UOM UOM ON UOM.C_UOM_ID = P.C_UOM_ID
LEFT JOIN M_PRODUCT_PO PO ON RL.M_PRODUCT_ID = PO.M_PRODUCT_ID
AND R.C_BPARTNER_ID = PO.C_BPARTNER_ID
WHERE
RL.M_PRODUCT_ID IS NOT NULL
AND RL.M_INOUTLINE_ID IS NULL
UNION ALL
SELECT
RL.QTY - COALESCE(RL.QTYINVOICED, 0) AS CREDITQTY,
RL.QTY - COALESCE(RL.QTYINVOICED, 0) AS QTY,
1 AS MULTIPLIER,
UOM.C_UOM_ID AS C_UOM_ID,
0 AS M_PRODUCT_ID,
C.C_CHARGE_ID AS C_CHARGE_ID,
NULL AS VENDORPRODUCTNO,
RL.LINE AS LINE,
0 AS C_ORDERLINE_ID,
0 AS M_INOUTLINE_ID,
RL.M_RMALINE_ID AS M_RMALINE_ID,
R.C_BPARTNER_ID AS C_BPARTNER_ID,
0 AS C_ORDER_ID,
0 AS M_INOUT_ID,
R.M_RMA_ID AS M_RMA_ID,
RL.M_RMALINE_ID AS C_INVOICE_CREATEFROM_V_ID,
RL.AD_CLIENT_ID AS AD_CLIENT_ID,
RL.AD_ORG_ID AS AD_ORG_ID,
RL.ISACTIVE AS ISACTIVE,
R.ISSOTRX AS ISSOTRX,
660 AS AD_TABLE_ID
FROM
M_RMALINE RL
JOIN M_RMA R ON R.M_RMA_ID = RL.M_RMA_ID
JOIN C_CHARGE C ON C.C_CHARGE_ID = RL.C_CHARGE_ID
LEFT JOIN C_UOM UOM ON UOM.C_UOM_ID = 100
WHERE
RL.C_CHARGE_ID IS NOT NULL
AND RL.M_INOUTLINE_ID IS NULL
;

View File

@ -0,0 +1,338 @@
-- IDEMPIERE-6025 Purchase Credit Memo > Create Lines From not displaying open/deferred matched PO invoice quantities
SELECT register_migration_script('202403051827_IDEMPIERE-6025.sql') FROM dual;
-- Mar 5, 2024, 6:27:42 PM MYT
UPDATE AD_ViewComponent SET OtherClause='GROUP BY l.QtyOrdered,CASE WHEN l.QtyOrdered=0 THEN 0 ELSE l.QtyEntered/l.QtyOrdered END,
l.C_UOM_ID, po.VendorProductNo, l.M_Product_ID, l.C_Charge_ID, l.Line, l.C_OrderLine_ID, o.IsSOTrx,
l.AD_Client_ID, l.AD_Org_ID, l.IsActive,l.c_bpartner_id,l.C_Order_ID, m2.Qty, l.QtyInvoiced
HAVING (l.QtyOrdered-(CASE WHEN SUM(m.Qty) IS NULL THEN l.QtyInvoiced ELSE SUM(COALESCE(m.Qty,0))+COALESCE(m2.Qty,0) END) <> 0)
OR (COALESCE(m2.Qty,0) <> 0)',Updated=TO_TIMESTAMP('2024-03-05 18:27:42','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_ViewComponent_ID=200227
;
-- Mar 5, 2024, 6:27:54 PM MYT
CREATE OR REPLACE VIEW C_INVOICE_CREATEFROM_V (
CREDITQTY,
QTY,
MULTIPLIER,
C_UOM_ID,
M_PRODUCT_ID,
C_CHARGE_ID,
VENDORPRODUCTNO,
LINE,
C_ORDERLINE_ID,
M_INOUTLINE_ID,
M_RMALINE_ID,
C_BPARTNER_ID,
C_ORDER_ID,
M_INOUT_ID,
M_RMA_ID,
C_INVOICE_CREATEFROM_V_ID,
AD_CLIENT_ID,
AD_ORG_ID,
ISACTIVE,
ISSOTRX,
AD_TABLE_ID
) AS
SELECT
COALESCE(M2.QTY, SUM(COALESCE(M.QTY, 0))) AS CREDITQTY,
L.QTYORDERED - (
CASE
WHEN SUM(M.QTY) IS NULL THEN L.QTYINVOICED
ELSE SUM(COALESCE(M.QTY, 0)) + COALESCE(M2.QTY, 0)
END
) AS QTY,
CASE
WHEN L.QTYORDERED = 0 THEN 0
ELSE L.QTYENTERED / L.QTYORDERED
END AS MULTIPLIER,
L.C_UOM_ID AS C_UOM_ID,
COALESCE(L.M_PRODUCT_ID, 0) AS M_PRODUCT_ID,
COALESCE(L.C_CHARGE_ID, 0) AS C_CHARGE_ID,
PO.VENDORPRODUCTNO AS VENDORPRODUCTNO,
L.LINE AS LINE,
L.C_ORDERLINE_ID AS C_ORDERLINE_ID,
0 AS M_INOUTLINE_ID,
0 AS M_RMALINE_ID,
L.C_BPARTNER_ID AS C_BPARTNER_ID,
L.C_ORDER_ID AS C_ORDER_ID,
0 AS M_INOUT_ID,
0 AS M_RMA_ID,
L.C_ORDERLINE_ID AS C_INVOICE_CREATEFROM_V_ID,
L.AD_CLIENT_ID AS AD_CLIENT_ID,
L.AD_ORG_ID AS AD_ORG_ID,
L.ISACTIVE AS ISACTIVE,
O.ISSOTRX AS ISSOTRX,
260 AS AD_TABLE_ID
FROM
C_ORDERLINE L
JOIN C_ORDER O ON O.C_ORDER_ID = L.C_ORDER_ID
LEFT JOIN M_PRODUCT_PO PO ON L.M_PRODUCT_ID = PO.M_PRODUCT_ID
AND L.C_BPARTNER_ID = PO.C_BPARTNER_ID
LEFT JOIN M_MATCHPO M ON L.C_ORDERLINE_ID = M.C_ORDERLINE_ID
AND M.C_INVOICELINE_ID IS NOT NULL
AND COALESCE(M.REVERSAL_ID, 0) = 0
AND M.POSTED <> 'd'
LEFT JOIN (
SELECT
M2.C_ORDERLINE_ID,
SUM(COALESCE(M2.QTY, 0)) AS QTY
FROM
M_MATCHPO M2
WHERE
M2.C_INVOICELINE_ID IS NOT NULL
AND COALESCE(M2.REVERSAL_ID, 0) = 0
AND M2.POSTED = 'd'
GROUP BY
M2.C_ORDERLINE_ID
) M2 ON L.C_ORDERLINE_ID = M2.C_ORDERLINE_ID
LEFT JOIN M_PRODUCT P ON L.M_PRODUCT_ID = P.M_PRODUCT_ID
GROUP BY
L.QTYORDERED,
CASE
WHEN L.QTYORDERED = 0 THEN 0
ELSE L.QTYENTERED / L.QTYORDERED
END,
L.C_UOM_ID,
PO.VENDORPRODUCTNO,
L.M_PRODUCT_ID,
L.C_CHARGE_ID,
L.LINE,
L.C_ORDERLINE_ID,
O.ISSOTRX,
L.AD_CLIENT_ID,
L.AD_ORG_ID,
L.ISACTIVE,
L.C_BPARTNER_ID,
L.C_ORDER_ID,
M2.QTY,
L.QTYINVOICED
HAVING
(
L.QTYORDERED - (
CASE
WHEN SUM(M.QTY) IS NULL THEN L.QTYINVOICED
ELSE SUM(COALESCE(M.QTY, 0)) + COALESCE(M2.QTY, 0)
END
) <> 0
)
OR (COALESCE(M2.QTY, 0) <> 0)
UNION ALL
SELECT
CASE
WHEN IO.ISSOTRX = 'N' THEN (
L.MOVEMENTQTY - SUM(COALESCE(MI.QTY, 0)) * CASE
WHEN IO.MOVEMENTTYPE = 'V-' THEN -1
ELSE 1
END
)
ELSE (
L.MOVEMENTQTY - SUM(COALESCE(MI.QTY, 0)) * CASE
WHEN IO.MOVEMENTTYPE = 'V-' THEN -1
ELSE 1
END
)
END AS CREDITQTY,
L.MOVEMENTQTY - SUM(COALESCE(MI.QTY, 0)) * CASE
WHEN IO.MOVEMENTTYPE = 'V-' THEN -1
ELSE 1
END AS QTY,
L.QTYENTERED / L.MOVEMENTQTY AS MULTIPLIER,
L.C_UOM_ID AS C_UOM_ID,
L.M_PRODUCT_ID AS M_PRODUCT_ID,
L.C_CHARGE_ID AS C_CHARGE_ID,
PO.VENDORPRODUCTNO AS VENDORPRODUCTNO,
L.LINE AS LINE,
L.C_ORDERLINE_ID AS C_ORDERLINE_ID,
L.M_INOUTLINE_ID AS M_INOUTLINE_ID,
0 AS M_RMALINE_ID,
IO.C_BPARTNER_ID AS C_BPARTNER_ID,
0 AS C_ORDER_ID,
L.M_INOUT_ID AS M_INOUT_ID,
0 AS M_RMA_ID,
L.M_INOUTLINE_ID AS C_INVOICE_CREATEFROM_V_ID,
L.AD_CLIENT_ID AS AD_CLIENT_ID,
L.AD_ORG_ID AS AD_ORG_ID,
L.ISACTIVE AS ISACTIVE,
IO.ISSOTRX AS ISSOTRX,
320 AS AD_TABLE_ID
FROM
M_INOUTLINE L
LEFT JOIN M_PRODUCT P ON L.M_PRODUCT_ID = P.M_PRODUCT_ID
JOIN M_INOUT IO ON L.M_INOUT_ID = IO.M_INOUT_ID
LEFT JOIN M_PRODUCT_PO PO ON L.M_PRODUCT_ID = PO.M_PRODUCT_ID
AND IO.C_BPARTNER_ID = PO.C_BPARTNER_ID
LEFT JOIN M_MATCHINV MI ON L.M_INOUTLINE_ID = MI.M_INOUTLINE_ID
WHERE
L.MOVEMENTQTY <> 0
AND IO.ISSOTRX = 'N'
GROUP BY
IO.MOVEMENTTYPE,
L.MOVEMENTQTY,
L.QTYENTERED / L.MOVEMENTQTY,
L.C_UOM_ID,
PO.VENDORPRODUCTNO,
L.M_PRODUCT_ID,
L.C_CHARGE_ID,
L.LINE,
L.C_ORDERLINE_ID,
L.M_INOUTLINE_ID,
IO.C_BPARTNER_ID,
L.M_INOUT_ID,
IO.ISSOTRX,
L.AD_CLIENT_ID,
L.AD_ORG_ID,
L.ISACTIVE
HAVING
L.MOVEMENTQTY - SUM(COALESCE(MI.QTY, 0)) <> 0
UNION ALL
SELECT
L.MOVEMENTQTY - SUM(COALESCE(IL.QTYINVOICED, 0)) AS CREDITQTY,
L.MOVEMENTQTY - SUM(COALESCE(IL.QTYINVOICED, 0)) AS QTY,
L.QTYENTERED / L.MOVEMENTQTY AS MULTIPLIER,
L.C_UOM_ID AS C_UOM_ID,
L.M_PRODUCT_ID AS M_PRODUCT_ID,
L.C_CHARGE_ID AS C_CHARGE_ID,
PO.VENDORPRODUCTNO AS VENDORPRODUCTNO,
L.LINE AS LINE,
L.C_ORDERLINE_ID AS C_ORDERLINE_ID,
L.M_INOUTLINE_ID AS M_INOUTLINE_ID,
0 AS M_RMALINE_ID,
IO.C_BPARTNER_ID AS C_BPARTNER_ID,
0 AS C_ORDER_ID,
L.M_INOUT_ID AS M_INOUT_ID,
0 AS M_RMA_ID,
L.M_INOUTLINE_ID AS C_INVOICE_CREATEFROM_V_ID,
L.AD_CLIENT_ID AS AD_CLIENT_ID,
L.AD_ORG_ID AS AD_ORG_ID,
L.ISACTIVE AS ISACTIVE,
IO.ISSOTRX AS ISSOTRX,
320 AS AD_TABLE_ID
FROM
M_INOUTLINE L
LEFT JOIN M_PRODUCT P ON L.M_PRODUCT_ID = P.M_PRODUCT_ID
JOIN M_INOUT IO ON L.M_INOUT_ID = IO.M_INOUT_ID
LEFT JOIN M_PRODUCT_PO PO ON L.M_PRODUCT_ID = PO.M_PRODUCT_ID
AND IO.C_BPARTNER_ID = PO.C_BPARTNER_ID
LEFT JOIN C_INVOICELINE IL ON L.M_INOUTLINE_ID = IL.M_INOUTLINE_ID
WHERE
L.MOVEMENTQTY <> 0
AND IO.ISSOTRX = 'Y'
GROUP BY
IO.MOVEMENTTYPE,
L.MOVEMENTQTY,
L.QTYENTERED / L.MOVEMENTQTY,
L.C_UOM_ID,
PO.VENDORPRODUCTNO,
L.M_PRODUCT_ID,
L.C_CHARGE_ID,
L.LINE,
L.C_ORDERLINE_ID,
L.M_INOUTLINE_ID,
IO.C_BPARTNER_ID,
L.M_INOUT_ID,
IO.ISSOTRX,
L.AD_CLIENT_ID,
L.AD_ORG_ID,
L.ISACTIVE
HAVING
L.MOVEMENTQTY - SUM(COALESCE(IL.QTYINVOICED, 0)) <> 0
UNION ALL
SELECT
RL.QTY - COALESCE(RL.QTYINVOICED, 0) AS CREDITQTY,
RL.QTY - COALESCE(RL.QTYINVOICED, 0) AS QTY,
1 AS MULTIPLIER,
UOM.C_UOM_ID AS C_UOM_ID,
P.M_PRODUCT_ID AS M_PRODUCT_ID,
C.C_CHARGE_ID AS C_CHARGE_ID,
PO.VENDORPRODUCTNO AS VENDORPRODUCTNO,
RL.LINE AS LINE,
0 AS C_ORDERLINE_ID,
0 AS M_INOUTLINE_ID,
RL.M_RMALINE_ID AS M_RMALINE_ID,
R.C_BPARTNER_ID AS C_BPARTNER_ID,
0 AS C_ORDER_ID,
0 AS M_INOUT_ID,
R.M_RMA_ID AS M_RMA_ID,
RL.M_RMALINE_ID AS C_INVOICE_CREATEFROM_V_ID,
RL.AD_CLIENT_ID AS AD_CLIENT_ID,
RL.AD_ORG_ID AS AD_ORG_ID,
RL.ISACTIVE AS ISACTIVE,
R.ISSOTRX AS ISSOTRX,
660 AS AD_TABLE_ID
FROM
M_RMALINE RL
JOIN M_RMA R ON R.M_RMA_ID = RL.M_RMA_ID
JOIN M_INOUTLINE IOL ON RL.M_INOUTLINE_ID = IOL.M_INOUTLINE_ID
LEFT JOIN M_PRODUCT P ON P.M_PRODUCT_ID = IOL.M_PRODUCT_ID
LEFT JOIN C_UOM UOM ON UOM.C_UOM_ID = COALESCE(P.C_UOM_ID, IOL.C_UOM_ID)
LEFT JOIN C_CHARGE C ON C.C_CHARGE_ID = IOL.C_CHARGE_ID
LEFT JOIN M_PRODUCT_PO PO ON RL.M_PRODUCT_ID = PO.M_PRODUCT_ID
AND R.C_BPARTNER_ID = PO.C_BPARTNER_ID
WHERE
RL.M_INOUTLINE_ID IS NOT NULL
UNION ALL
SELECT
RL.QTY - COALESCE(RL.QTYINVOICED, 0) AS CREDITQTY,
RL.QTY - COALESCE(RL.QTYINVOICED, 0) AS QTY,
1 AS MULTIPLIER,
UOM.C_UOM_ID AS C_UOM_ID,
P.M_PRODUCT_ID AS M_PRODUCT_ID,
0 AS C_CHARGE_ID,
PO.VENDORPRODUCTNO AS VENDORPRODUCTNO,
RL.LINE AS LINE,
0 AS C_ORDERLINE_ID,
0 AS M_INOUTLINE_ID,
RL.M_RMALINE_ID AS M_RMALINE_ID,
R.C_BPARTNER_ID AS C_BPARTNER_ID,
0 AS C_ORDER_ID,
0 AS M_INOUT_ID,
R.M_RMA_ID AS M_RMA_ID,
RL.M_RMALINE_ID AS C_INVOICE_CREATEFROM_V_ID,
RL.AD_CLIENT_ID AS AD_CLIENT_ID,
RL.AD_ORG_ID AS AD_ORG_ID,
RL.ISACTIVE AS ISACTIVE,
R.ISSOTRX AS ISSOTRX,
660 AS AD_TABLE_ID
FROM
M_RMALINE RL
JOIN M_RMA R ON R.M_RMA_ID = RL.M_RMA_ID
JOIN M_PRODUCT P ON P.M_PRODUCT_ID = RL.M_PRODUCT_ID
LEFT JOIN C_UOM UOM ON UOM.C_UOM_ID = P.C_UOM_ID
LEFT JOIN M_PRODUCT_PO PO ON RL.M_PRODUCT_ID = PO.M_PRODUCT_ID
AND R.C_BPARTNER_ID = PO.C_BPARTNER_ID
WHERE
RL.M_PRODUCT_ID IS NOT NULL
AND RL.M_INOUTLINE_ID IS NULL
UNION ALL
SELECT
RL.QTY - COALESCE(RL.QTYINVOICED, 0) AS CREDITQTY,
RL.QTY - COALESCE(RL.QTYINVOICED, 0) AS QTY,
1 AS MULTIPLIER,
UOM.C_UOM_ID AS C_UOM_ID,
0 AS M_PRODUCT_ID,
C.C_CHARGE_ID AS C_CHARGE_ID,
NULL AS VENDORPRODUCTNO,
RL.LINE AS LINE,
0 AS C_ORDERLINE_ID,
0 AS M_INOUTLINE_ID,
RL.M_RMALINE_ID AS M_RMALINE_ID,
R.C_BPARTNER_ID AS C_BPARTNER_ID,
0 AS C_ORDER_ID,
0 AS M_INOUT_ID,
R.M_RMA_ID AS M_RMA_ID,
RL.M_RMALINE_ID AS C_INVOICE_CREATEFROM_V_ID,
RL.AD_CLIENT_ID AS AD_CLIENT_ID,
RL.AD_ORG_ID AS AD_ORG_ID,
RL.ISACTIVE AS ISACTIVE,
R.ISSOTRX AS ISSOTRX,
660 AS AD_TABLE_ID
FROM
M_RMALINE RL
JOIN M_RMA R ON R.M_RMA_ID = RL.M_RMA_ID
JOIN C_CHARGE C ON C.C_CHARGE_ID = RL.C_CHARGE_ID
LEFT JOIN C_UOM UOM ON UOM.C_UOM_ID = 100
WHERE
RL.C_CHARGE_ID IS NOT NULL
AND RL.M_INOUTLINE_ID IS NULL
;

View File

@ -33,6 +33,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.Calendar;
import java.util.List;
import java.util.Properties;
import org.compiere.model.MAttributeSetInstance;
@ -40,6 +41,7 @@ import org.compiere.model.MBPartner;
import org.compiere.model.MClient;
import org.compiere.model.MInOut;
import org.compiere.model.MInOutLine;
import org.compiere.model.MInfoWindow;
import org.compiere.model.MInvoice;
import org.compiere.model.MInvoiceLine;
import org.compiere.model.MOrder;
@ -53,6 +55,7 @@ import org.compiere.model.MStorageOnHand;
import org.compiere.model.MStorageReservation;
import org.compiere.model.MStorageReservationLog;
import org.compiere.model.MSysConfig;
import org.compiere.model.MTable;
import org.compiere.model.Query;
import org.compiere.process.DocAction;
import org.compiere.process.ProcessInfo;
@ -808,4 +811,517 @@ public class PurchaseOrderTest extends AbstractTestCase {
assertEquals(date2, vendorReturn.getMovementDate());
assertEquals(date2, vendorReturn.getDateAcct());
}
/**
* https://idempiere.atlassian.net/browse/IDEMPIERE-6025
* PO Qty=12
* MR Qty=10
* INV Qty=12
* CM Qty=2 (should be displayed on Purchase Credit Memo > Create Lines From info window)
*/
@Test
public void testDeferredMatchedPOCreditQty() {
Properties ctx = Env.getCtx();
String trxName = getTrxName();
MOrder order = new MOrder(ctx, 0, trxName);
order.setBPartner(MBPartner.get(ctx, DictionaryIDs.C_BPartner.PATIO.id));
order.setC_DocTypeTarget_ID(DictionaryIDs.C_DocType.PURCHASE_ORDER.id);
order.setIsSOTrx(false);
order.setSalesRep_ID(DictionaryIDs.AD_User.GARDEN_ADMIN.id);
order.setDocStatus(DocAction.STATUS_Drafted);
order.setDocAction(DocAction.ACTION_Complete);
Timestamp today = TimeUtil.getDay(System.currentTimeMillis());
order.setDateOrdered(today);
order.setDatePromised(today);
order.saveEx();
MOrderLine line = new MOrderLine(order);
line.setLine(10);
line.setProduct(MProduct.get(ctx, DictionaryIDs.M_Product.WEEDER.id));
line.setQty(new BigDecimal("12"));
line.setDatePromised(today);
line.saveEx();
ProcessInfo info = MWorkflow.runDocumentActionWorkflow(order, DocAction.ACTION_Complete);
assertFalse(info.isError(), info.getSummary());
order.load(trxName);
assertEquals(DocAction.STATUS_Completed, order.getDocStatus());
MInOut receipt = new MInOut(order, DictionaryIDs.C_DocType.MM_RECEIPT.id, order.getDateOrdered());
receipt.setDocStatus(DocAction.STATUS_Drafted);
receipt.setDocAction(DocAction.ACTION_Complete);
receipt.saveEx();
MInOutLine receiptLine = new MInOutLine(receipt);
receiptLine.setOrderLine(line, 0, new BigDecimal("10"));
receiptLine.setQty(new BigDecimal("10"));
receiptLine.saveEx();
info = MWorkflow.runDocumentActionWorkflow(receipt, DocAction.ACTION_Complete);
assertFalse(info.isError(), info.getSummary());
receipt.load(trxName);
assertEquals(DocAction.STATUS_Completed, receipt.getDocStatus());
MInvoice invoice = new MInvoice(order, DictionaryIDs.C_DocType.AP_INVOICE.id, order.getDateOrdered());
invoice.setDocStatus(DocAction.STATUS_Drafted);
invoice.setDocAction(DocAction.ACTION_Complete);
invoice.saveEx();
MInvoiceLine invoiceLine = new MInvoiceLine(invoice);
invoiceLine.setOrderLine(line);
invoiceLine.setQty(new BigDecimal("12"));
invoiceLine.saveEx();
info = MWorkflow.runDocumentActionWorkflow(invoice, DocAction.ACTION_Complete);
assertFalse(info.isError(), info.getSummary());
invoice.load(trxName);
assertEquals(DocAction.STATUS_Completed, invoice.getDocStatus());
MInvoice creditMemo = new MInvoice(order, DictionaryIDs.C_DocType.AP_CREDIT_MEMO.id, order.getDateOrdered());
creditMemo.setDocStatus(DocAction.STATUS_Drafted);
creditMemo.setDocAction(DocAction.ACTION_Complete);
creditMemo.saveEx();
MInfoWindow infoWindow = MInfoWindow.get(200024, trxName); // Create lines from Invoice
String tableName = MTable.getTableName(Env.getCtx(), infoWindow.getAD_Table_ID());
String sql = "SELECT C_OrderLine_ID, CreditQty, Qty FROM " + tableName + " WHERE C_Order_ID=? ";
List<Object> data = DB.getSQLValueObjectsEx(trxName, sql, order.getC_Order_ID());
assertEquals(data.size(), 3);
int C_OrderLine_ID = ((BigDecimal) data.get(0)).intValue();
BigDecimal CreditQty = (BigDecimal) data.get(1);
BigDecimal Qty = (BigDecimal) data.get(2);
CreditQty = CreditQty.setScale(0);
Qty = Qty.setScale(0);
assertEquals(line.getC_OrderLine_ID(), C_OrderLine_ID);
assertEquals(new BigDecimal("2"), CreditQty);
assertEquals(new BigDecimal("0"), Qty);
MInvoiceLine creditMemoLine = new MInvoiceLine(creditMemo);
creditMemoLine.setOrderLine(line);
creditMemoLine.setQty(CreditQty);
creditMemoLine.saveEx();
info = MWorkflow.runDocumentActionWorkflow(creditMemo, DocAction.ACTION_Complete);
assertFalse(info.isError(), info.getSummary());
creditMemo.load(trxName);
assertEquals(DocAction.STATUS_Completed, creditMemo.getDocStatus());
}
/**
* https://idempiere.atlassian.net/browse/IDEMPIERE-6025
* PO Qty=3
* INV Qty=3
* CM Qty=3 (should be displayed on Purchase Credit Memo > Create Lines From info window)
*/
@Test
public void testDeferredMatchedPOCreditQtyNoMR() {
Properties ctx = Env.getCtx();
String trxName = getTrxName();
MOrder order = new MOrder(ctx, 0, trxName);
order.setBPartner(MBPartner.get(ctx, DictionaryIDs.C_BPartner.PATIO.id));
order.setC_DocTypeTarget_ID(DictionaryIDs.C_DocType.PURCHASE_ORDER.id);
order.setIsSOTrx(false);
order.setSalesRep_ID(DictionaryIDs.AD_User.GARDEN_ADMIN.id);
order.setDocStatus(DocAction.STATUS_Drafted);
order.setDocAction(DocAction.ACTION_Complete);
Timestamp today = TimeUtil.getDay(System.currentTimeMillis());
order.setDateOrdered(today);
order.setDatePromised(today);
order.saveEx();
MOrderLine line = new MOrderLine(order);
line.setLine(10);
line.setProduct(MProduct.get(ctx, DictionaryIDs.M_Product.WEEDER.id));
line.setQty(new BigDecimal("3"));
line.setDatePromised(today);
line.saveEx();
ProcessInfo info = MWorkflow.runDocumentActionWorkflow(order, DocAction.ACTION_Complete);
assertFalse(info.isError(), info.getSummary());
order.load(trxName);
assertEquals(DocAction.STATUS_Completed, order.getDocStatus());
MInvoice invoice = new MInvoice(order, DictionaryIDs.C_DocType.AP_INVOICE.id, order.getDateOrdered());
invoice.setDocStatus(DocAction.STATUS_Drafted);
invoice.setDocAction(DocAction.ACTION_Complete);
invoice.saveEx();
MInvoiceLine invoiceLine = new MInvoiceLine(invoice);
invoiceLine.setOrderLine(line);
invoiceLine.setQty(new BigDecimal("3"));
invoiceLine.saveEx();
info = MWorkflow.runDocumentActionWorkflow(invoice, DocAction.ACTION_Complete);
assertFalse(info.isError(), info.getSummary());
invoice.load(trxName);
assertEquals(DocAction.STATUS_Completed, invoice.getDocStatus());
MInvoice creditMemo = new MInvoice(order, DictionaryIDs.C_DocType.AP_CREDIT_MEMO.id, order.getDateOrdered());
creditMemo.setDocStatus(DocAction.STATUS_Drafted);
creditMemo.setDocAction(DocAction.ACTION_Complete);
creditMemo.saveEx();
MInfoWindow infoWindow = MInfoWindow.get(200024, trxName); // Create lines from Invoice
String tableName = MTable.getTableName(Env.getCtx(), infoWindow.getAD_Table_ID());
String sql = "SELECT C_OrderLine_ID, CreditQty, Qty FROM " + tableName + " WHERE C_Order_ID=? ";
List<Object> data = DB.getSQLValueObjectsEx(trxName, sql, order.getC_Order_ID());
assertEquals(data.size(), 3);
int C_OrderLine_ID = ((BigDecimal) data.get(0)).intValue();
BigDecimal CreditQty = (BigDecimal) data.get(1);
BigDecimal Qty = (BigDecimal) data.get(2);
CreditQty = CreditQty.setScale(0);
Qty = Qty.setScale(0);
assertEquals(line.getC_OrderLine_ID(), C_OrderLine_ID);
assertEquals(new BigDecimal("3"), CreditQty);
assertEquals(new BigDecimal("0"), Qty);
MInvoiceLine creditMemoLine = new MInvoiceLine(creditMemo);
creditMemoLine.setOrderLine(line);
creditMemoLine.setQty(CreditQty);
creditMemoLine.saveEx();
info = MWorkflow.runDocumentActionWorkflow(creditMemo, DocAction.ACTION_Complete);
assertFalse(info.isError(), info.getSummary());
creditMemo.load(trxName);
assertEquals(DocAction.STATUS_Completed, creditMemo.getDocStatus());
}
/**
* https://idempiere.atlassian.net/browse/IDEMPIERE-6025
* PO Qty=1800
* INV Qty=1800
* MR-1 Qty=1763
* MR-2 Qty=30
* CM Qty=7 (should be displayed on Purchase Credit Memo > Create Lines From info window)
*/
@Test
public void testDeferredMatchedPOCreditQtyMultiMR_1() {
Properties ctx = Env.getCtx();
String trxName = getTrxName();
MOrder order = new MOrder(ctx, 0, trxName);
order.setBPartner(MBPartner.get(ctx, DictionaryIDs.C_BPartner.PATIO.id));
order.setC_DocTypeTarget_ID(DictionaryIDs.C_DocType.PURCHASE_ORDER.id);
order.setIsSOTrx(false);
order.setSalesRep_ID(DictionaryIDs.AD_User.GARDEN_ADMIN.id);
order.setDocStatus(DocAction.STATUS_Drafted);
order.setDocAction(DocAction.ACTION_Complete);
Timestamp today = TimeUtil.getDay(System.currentTimeMillis());
order.setDateOrdered(today);
order.setDatePromised(today);
order.saveEx();
MOrderLine line = new MOrderLine(order);
line.setLine(10);
line.setProduct(MProduct.get(ctx, DictionaryIDs.M_Product.WEEDER.id));
line.setQty(new BigDecimal("1800"));
line.setDatePromised(today);
line.saveEx();
ProcessInfo info = MWorkflow.runDocumentActionWorkflow(order, DocAction.ACTION_Complete);
assertFalse(info.isError(), info.getSummary());
order.load(trxName);
assertEquals(DocAction.STATUS_Completed, order.getDocStatus());
MInvoice invoice = new MInvoice(order, DictionaryIDs.C_DocType.AP_INVOICE.id, order.getDateOrdered());
invoice.setDocStatus(DocAction.STATUS_Drafted);
invoice.setDocAction(DocAction.ACTION_Complete);
invoice.saveEx();
MInvoiceLine invoiceLine = new MInvoiceLine(invoice);
invoiceLine.setOrderLine(line);
invoiceLine.setQty(new BigDecimal("1800"));
invoiceLine.saveEx();
info = MWorkflow.runDocumentActionWorkflow(invoice, DocAction.ACTION_Complete);
assertFalse(info.isError(), info.getSummary());
invoice.load(trxName);
assertEquals(DocAction.STATUS_Completed, invoice.getDocStatus());
MInOut receipt1 = new MInOut(order, DictionaryIDs.C_DocType.MM_RECEIPT.id, order.getDateOrdered());
receipt1.setDocStatus(DocAction.STATUS_Drafted);
receipt1.setDocAction(DocAction.ACTION_Complete);
receipt1.saveEx();
MInOutLine receiptLine1 = new MInOutLine(receipt1);
receiptLine1.setOrderLine(line, 0, new BigDecimal("1763"));
receiptLine1.setQty(new BigDecimal("1763"));
receiptLine1.saveEx();
info = MWorkflow.runDocumentActionWorkflow(receipt1, DocAction.ACTION_Complete);
assertFalse(info.isError(), info.getSummary());
receipt1.load(trxName);
assertEquals(DocAction.STATUS_Completed, receipt1.getDocStatus());
MInOut receipt2 = new MInOut(order, DictionaryIDs.C_DocType.MM_RECEIPT.id, order.getDateOrdered());
receipt2.setDocStatus(DocAction.STATUS_Drafted);
receipt2.setDocAction(DocAction.ACTION_Complete);
receipt2.saveEx();
MInOutLine receiptLine2 = new MInOutLine(receipt2);
receiptLine2.setOrderLine(line, 0, new BigDecimal("30"));
receiptLine2.setQty(new BigDecimal("30"));
receiptLine2.saveEx();
info = MWorkflow.runDocumentActionWorkflow(receipt2, DocAction.ACTION_Complete);
assertFalse(info.isError(), info.getSummary());
receipt2.load(trxName);
assertEquals(DocAction.STATUS_Completed, receipt2.getDocStatus());
MInvoice creditMemo = new MInvoice(order, DictionaryIDs.C_DocType.AP_CREDIT_MEMO.id, order.getDateOrdered());
creditMemo.setDocStatus(DocAction.STATUS_Drafted);
creditMemo.setDocAction(DocAction.ACTION_Complete);
creditMemo.saveEx();
MInfoWindow infoWindow = MInfoWindow.get(200024, trxName); // Create lines from Invoice
String tableName = MTable.getTableName(Env.getCtx(), infoWindow.getAD_Table_ID());
String sql = "SELECT C_OrderLine_ID, CreditQty, Qty FROM " + tableName + " WHERE C_Order_ID=? ";
List<Object> data = DB.getSQLValueObjectsEx(trxName, sql, order.getC_Order_ID());
assertEquals(data.size(), 3);
int C_OrderLine_ID = ((BigDecimal) data.get(0)).intValue();
BigDecimal CreditQty = (BigDecimal) data.get(1);
BigDecimal Qty = (BigDecimal) data.get(2);
CreditQty = CreditQty.setScale(0);
Qty = Qty.setScale(0);
assertEquals(line.getC_OrderLine_ID(), C_OrderLine_ID);
assertEquals(new BigDecimal("7"), CreditQty);
assertEquals(new BigDecimal("0"), Qty);
MInvoiceLine creditMemoLine = new MInvoiceLine(creditMemo);
creditMemoLine.setOrderLine(line);
creditMemoLine.setQty(CreditQty);
creditMemoLine.saveEx();
info = MWorkflow.runDocumentActionWorkflow(creditMemo, DocAction.ACTION_Complete);
assertFalse(info.isError(), info.getSummary());
creditMemo.load(trxName);
assertEquals(DocAction.STATUS_Completed, creditMemo.getDocStatus());
}
/**
* https://idempiere.atlassian.net/browse/IDEMPIERE-6025
* PO Qty=1800
* MR-1 Qty=1763
* MR-2 Qty=30
* INV Qty=1800
* CM Qty=7 (should be displayed on Purchase Credit Memo > Create Lines From info window)
*/
@Test
public void testDeferredMatchedPOCreditQtyMultiMR_2() {
Properties ctx = Env.getCtx();
String trxName = getTrxName();
MOrder order = new MOrder(ctx, 0, trxName);
order.setBPartner(MBPartner.get(ctx, DictionaryIDs.C_BPartner.PATIO.id));
order.setC_DocTypeTarget_ID(DictionaryIDs.C_DocType.PURCHASE_ORDER.id);
order.setIsSOTrx(false);
order.setSalesRep_ID(DictionaryIDs.AD_User.GARDEN_ADMIN.id);
order.setDocStatus(DocAction.STATUS_Drafted);
order.setDocAction(DocAction.ACTION_Complete);
Timestamp today = TimeUtil.getDay(System.currentTimeMillis());
order.setDateOrdered(today);
order.setDatePromised(today);
order.saveEx();
MOrderLine line = new MOrderLine(order);
line.setLine(10);
line.setProduct(MProduct.get(ctx, DictionaryIDs.M_Product.WEEDER.id));
line.setQty(new BigDecimal("1800"));
line.setDatePromised(today);
line.saveEx();
ProcessInfo info = MWorkflow.runDocumentActionWorkflow(order, DocAction.ACTION_Complete);
assertFalse(info.isError(), info.getSummary());
order.load(trxName);
assertEquals(DocAction.STATUS_Completed, order.getDocStatus());
MInOut receipt1 = new MInOut(order, DictionaryIDs.C_DocType.MM_RECEIPT.id, order.getDateOrdered());
receipt1.setDocStatus(DocAction.STATUS_Drafted);
receipt1.setDocAction(DocAction.ACTION_Complete);
receipt1.saveEx();
MInOutLine receiptLine1 = new MInOutLine(receipt1);
receiptLine1.setOrderLine(line, 0, new BigDecimal("1763"));
receiptLine1.setQty(new BigDecimal("1763"));
receiptLine1.saveEx();
info = MWorkflow.runDocumentActionWorkflow(receipt1, DocAction.ACTION_Complete);
assertFalse(info.isError(), info.getSummary());
receipt1.load(trxName);
assertEquals(DocAction.STATUS_Completed, receipt1.getDocStatus());
MInOut receipt2 = new MInOut(order, DictionaryIDs.C_DocType.MM_RECEIPT.id, order.getDateOrdered());
receipt2.setDocStatus(DocAction.STATUS_Drafted);
receipt2.setDocAction(DocAction.ACTION_Complete);
receipt2.saveEx();
MInOutLine receiptLine2 = new MInOutLine(receipt2);
receiptLine2.setOrderLine(line, 0, new BigDecimal("30"));
receiptLine2.setQty(new BigDecimal("30"));
receiptLine2.saveEx();
info = MWorkflow.runDocumentActionWorkflow(receipt2, DocAction.ACTION_Complete);
assertFalse(info.isError(), info.getSummary());
receipt2.load(trxName);
assertEquals(DocAction.STATUS_Completed, receipt2.getDocStatus());
MInvoice invoice = new MInvoice(order, DictionaryIDs.C_DocType.AP_INVOICE.id, order.getDateOrdered());
invoice.setDocStatus(DocAction.STATUS_Drafted);
invoice.setDocAction(DocAction.ACTION_Complete);
invoice.saveEx();
MInvoiceLine invoiceLine = new MInvoiceLine(invoice);
invoiceLine.setOrderLine(line);
invoiceLine.setQty(new BigDecimal("1800"));
invoiceLine.saveEx();
info = MWorkflow.runDocumentActionWorkflow(invoice, DocAction.ACTION_Complete);
assertFalse(info.isError(), info.getSummary());
invoice.load(trxName);
assertEquals(DocAction.STATUS_Completed, invoice.getDocStatus());
MInvoice creditMemo = new MInvoice(order, DictionaryIDs.C_DocType.AP_CREDIT_MEMO.id, order.getDateOrdered());
creditMemo.setDocStatus(DocAction.STATUS_Drafted);
creditMemo.setDocAction(DocAction.ACTION_Complete);
creditMemo.saveEx();
MInfoWindow infoWindow = MInfoWindow.get(200024, trxName); // Create lines from Invoice
String tableName = MTable.getTableName(Env.getCtx(), infoWindow.getAD_Table_ID());
String sql = "SELECT C_OrderLine_ID, CreditQty, Qty FROM " + tableName + " WHERE C_Order_ID=? ";
List<Object> data = DB.getSQLValueObjectsEx(trxName, sql, order.getC_Order_ID());
assertEquals(data.size(), 3);
int C_OrderLine_ID = ((BigDecimal) data.get(0)).intValue();
BigDecimal CreditQty = (BigDecimal) data.get(1);
BigDecimal Qty = (BigDecimal) data.get(2);
CreditQty = CreditQty.setScale(0);
Qty = Qty.setScale(0);
assertEquals(line.getC_OrderLine_ID(), C_OrderLine_ID);
assertEquals(new BigDecimal("7"), CreditQty);
assertEquals(new BigDecimal("0"), Qty);
MInvoiceLine creditMemoLine = new MInvoiceLine(creditMemo);
creditMemoLine.setOrderLine(line);
creditMemoLine.setQty(CreditQty);
creditMemoLine.saveEx();
info = MWorkflow.runDocumentActionWorkflow(creditMemo, DocAction.ACTION_Complete);
assertFalse(info.isError(), info.getSummary());
creditMemo.load(trxName);
assertEquals(DocAction.STATUS_Completed, creditMemo.getDocStatus());
}
/**
* https://idempiere.atlassian.net/browse/IDEMPIERE-6025
* PO Line-1 Qty=3, Line-2 Qty=3
* MR Line-1 Qty=3, Line-2 Qty=2
* INV Line-1 Qty=3, Line-2 Qty=2
* CM Line-2 Qty=1 (Line-1 should not be displayed. Line-2 should be displayed on Purchase Credit Memo > Create Lines From info window)
*/
@Test
public void testDeferredMatchedPOCreditQtyMultiLine() {
Properties ctx = Env.getCtx();
String trxName = getTrxName();
MOrder order = new MOrder(ctx, 0, trxName);
order.setBPartner(MBPartner.get(ctx, DictionaryIDs.C_BPartner.PATIO.id));
order.setC_DocTypeTarget_ID(DictionaryIDs.C_DocType.PURCHASE_ORDER.id);
order.setIsSOTrx(false);
order.setSalesRep_ID(DictionaryIDs.AD_User.GARDEN_ADMIN.id);
order.setDocStatus(DocAction.STATUS_Drafted);
order.setDocAction(DocAction.ACTION_Complete);
Timestamp today = TimeUtil.getDay(System.currentTimeMillis());
order.setDateOrdered(today);
order.setDatePromised(today);
order.saveEx();
MOrderLine line1 = new MOrderLine(order);
line1.setLine(10);
line1.setProduct(MProduct.get(ctx, DictionaryIDs.M_Product.ELM.id));
line1.setQty(new BigDecimal("3"));
line1.setDatePromised(today);
line1.saveEx();
MOrderLine line2 = new MOrderLine(order);
line2.setLine(20);
line2.setProduct(MProduct.get(ctx, DictionaryIDs.M_Product.OAK.id));
line2.setQty(new BigDecimal("3"));
line2.setDatePromised(today);
line2.saveEx();
ProcessInfo info = MWorkflow.runDocumentActionWorkflow(order, DocAction.ACTION_Complete);
assertFalse(info.isError(), info.getSummary());
order.load(trxName);
assertEquals(DocAction.STATUS_Completed, order.getDocStatus());
MInOut receipt = new MInOut(order, DictionaryIDs.C_DocType.MM_RECEIPT.id, order.getDateOrdered());
receipt.setDocStatus(DocAction.STATUS_Drafted);
receipt.setDocAction(DocAction.ACTION_Complete);
receipt.saveEx();
MInOutLine receiptLine1 = new MInOutLine(receipt);
receiptLine1.setOrderLine(line1, 0, new BigDecimal("3"));
receiptLine1.setQty(new BigDecimal("3"));
receiptLine1.saveEx();
MInOutLine receiptLine2 = new MInOutLine(receipt);
receiptLine2.setOrderLine(line2, 0, new BigDecimal("2"));
receiptLine2.setQty(new BigDecimal("2"));
receiptLine2.saveEx();
info = MWorkflow.runDocumentActionWorkflow(receipt, DocAction.ACTION_Complete);
assertFalse(info.isError(), info.getSummary());
receipt.load(trxName);
assertEquals(DocAction.STATUS_Completed, receipt.getDocStatus());
MInvoice invoice = new MInvoice(order, DictionaryIDs.C_DocType.AP_INVOICE.id, order.getDateOrdered());
invoice.setDocStatus(DocAction.STATUS_Drafted);
invoice.setDocAction(DocAction.ACTION_Complete);
invoice.saveEx();
MInvoiceLine invoiceLine1 = new MInvoiceLine(invoice);
invoiceLine1.setOrderLine(line1);
invoiceLine1.setQty(new BigDecimal("3"));
invoiceLine1.saveEx();
MInvoiceLine invoiceLine2 = new MInvoiceLine(invoice);
invoiceLine2.setOrderLine(line2);
invoiceLine2.setQty(new BigDecimal("3"));
invoiceLine2.saveEx();
info = MWorkflow.runDocumentActionWorkflow(invoice, DocAction.ACTION_Complete);
assertFalse(info.isError(), info.getSummary());
invoice.load(trxName);
assertEquals(DocAction.STATUS_Completed, invoice.getDocStatus());
MInvoice creditMemo = new MInvoice(order, DictionaryIDs.C_DocType.AP_CREDIT_MEMO.id, order.getDateOrdered());
creditMemo.setDocStatus(DocAction.STATUS_Drafted);
creditMemo.setDocAction(DocAction.ACTION_Complete);
creditMemo.saveEx();
MInfoWindow infoWindow = MInfoWindow.get(200024, trxName); // Create lines from Invoice
String tableName = MTable.getTableName(Env.getCtx(), infoWindow.getAD_Table_ID());
String sql = "SELECT CreditQty, Qty FROM " + tableName + " WHERE C_Order_ID=? AND C_OrderLine_ID=?";
List<Object> data = DB.getSQLValueObjectsEx(trxName, sql, order.getC_Order_ID(), line1.getC_OrderLine_ID());
assertTrue(data == null); // fully invoiced, should not appear in the create lines from info window
data = DB.getSQLValueObjectsEx(trxName, sql, order.getC_Order_ID(), line2.getC_OrderLine_ID());
assertEquals(data.size(), 2);
BigDecimal CreditQty = (BigDecimal) data.get(0);
BigDecimal Qty = (BigDecimal) data.get(1);
CreditQty = CreditQty.setScale(0);
Qty = Qty.setScale(0);
assertEquals(new BigDecimal("1"), CreditQty);
assertEquals(new BigDecimal("0"), Qty);
MInvoiceLine creditMemoLine = new MInvoiceLine(creditMemo);
creditMemoLine.setOrderLine(line2);
creditMemoLine.setQty(CreditQty);
creditMemoLine.saveEx();
info = MWorkflow.runDocumentActionWorkflow(creditMemo, DocAction.ACTION_Complete);
assertFalse(info.isError(), info.getSummary());
creditMemo.load(trxName);
assertEquals(DocAction.STATUS_Completed, creditMemo.getDocStatus());
}
}