Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
9 changed files
with
200 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...n/sql/postgresql/system/10-de.metas.adempiere/5560200_sys_gh6718_fix_uomConvertDirect.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
|
||
create or replace function uomConvertDirect | ||
( | ||
p_M_Product_ID numeric | ||
, p_C_UOM_From_ID numeric | ||
, p_C_UOM_To_ID numeric | ||
, p_Qty numeric | ||
) | ||
returns numeric | ||
as | ||
$BODY$ | ||
declare | ||
v_MultiplyRate numeric; | ||
v_QtyConv numeric; | ||
begin | ||
-- If quantity is null or zero, there is no point to convert | ||
if (p_Qty is null or p_Qty = 0) | ||
then | ||
return p_Qty; | ||
end if; | ||
|
||
-- If same UOM, there is no point to convert | ||
if (p_C_UOM_From_ID = p_C_UOM_To_ID) | ||
then | ||
return p_Qty; | ||
end if; | ||
|
||
-- | ||
-- Direct: p_C_UOM_From_ID -> p_C_UOM_To_ID | ||
select MultiplyRate | ||
into v_MultiplyRate | ||
from C_UOM_Conversion c | ||
-- there might be product-independent conversion rates; we allow them, but prefer ones with a product | ||
where (c.M_Product_ID IS NULL OR c.M_Product_ID=p_M_Product_ID) | ||
and c.C_UOM_ID = p_C_UOM_From_ID and c.C_UOM_To_ID = p_C_UOM_To_ID | ||
and c.IsActive='Y' | ||
order by c.M_Product_ID NULLS LAST | ||
; | ||
|
||
-- | ||
-- Direct (reversed): p_C_UOM_To_ID -> p_C_UOM_From_ID | ||
if (v_MultiplyRate is null) | ||
then | ||
select DivideRate | ||
into v_MultiplyRate | ||
from C_UOM_Conversion c | ||
-- there might be product-independent conversion rates; we allow them, but prefer ones with a product | ||
where (c.M_Product_ID IS NULL OR c.M_Product_ID=p_M_Product_ID) | ||
and c.C_UOM_ID = p_C_UOM_To_ID and c.C_UOM_To_ID = p_C_UOM_From_ID | ||
and c.IsActive='Y' | ||
order by c.M_Product_ID NULLS LAST | ||
; | ||
end if; | ||
|
||
if (v_MultiplyRate is null) | ||
then | ||
return null; | ||
end if; | ||
|
||
v_QtyConv := p_Qty * v_MultiplyRate; | ||
|
||
return v_QtyConv; | ||
end; | ||
$BODY$ | ||
LANGUAGE plpgsql STABLE | ||
COST 100; | ||
|
||
COMMENT ON FUNCTION public.uomconvertdirect(numeric, numeric, numeric, numeric) | ||
IS 'Attempts to convert between two UOMs by using the C_UOM_Conversion table. If there is no conversion table record it can use, the function returns null. | ||
Note that the function tries both "directions" so we need just one C_UOM_Conversion record to convert both from "A" to "B" and from "B" to "A".'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 55 additions & 46 deletions
101
backend/de.metas.material/cockpit/src/main/sql/postgresql/ddl/views/MD_Stock_From_HUs_V.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,59 @@ | ||
|
||
DROP VIEW IF EXISTS MD_Stock_From_HUs_V; | ||
CREATE VIEW MD_Stock_From_HUs_V AS | ||
SELECT | ||
COALESCE(hu_agg.AD_Client_ID, s.AD_Client_ID) AS AD_Client_ID, | ||
COALESCE(hu_agg.AD_Org_ID, s.AD_Org_ID) AS AD_Org_ID, | ||
COALESCE(hu_agg.M_Warehouse_ID, s.M_Warehouse_ID) AS M_Warehouse_ID, | ||
COALESCE(hu_agg.M_Product_ID, s.M_Product_ID) AS M_Product_ID, | ||
COALESCE(hu_agg.C_UOM_ID, p.C_UOM_ID) AS C_UOM_ID, | ||
COALESCE(hu_agg.AttributesKey, s.AttributesKey) AS AttributesKey, | ||
COALESCE(hu_agg.QtyOnHand, 0) AS QtyOnHand, | ||
COALESCE(hu_agg.QtyOnHand, 0) - COALESCE(s.QtyOnHand, 0) AS QtyOnHandChange | ||
FROM | ||
MD_Stock s | ||
LEFT JOIN M_Product p ON p.M_Product_ID = s.M_Product_ID /*needed for its C_UOM_ID*/ | ||
FULL OUTER JOIN | ||
( | ||
SELECT | ||
hu.AD_Client_ID, | ||
hu.AD_Org_ID, | ||
l.M_Warehouse_ID, | ||
hus.M_Product_ID, | ||
hus.C_UOM_ID, | ||
GenerateHUAttributesKey(hu.m_hu_id) as AttributesKey, | ||
SUM(hus.Qty) as QtyOnHand | ||
FROM m_hu hu | ||
JOIN M_HU_Storage hus ON hus.M_HU_ID = hu.M_HU_ID | ||
JOIN M_Locator l ON l.M_Locator_ID=hu.M_Locator_ID | ||
WHERE hu.isactive='Y' | ||
and M_HU_Item_Parent_ID IS NULL | ||
SELECT | ||
/*the COALESCEs are for the case of missing hu_agg (i.e. nothing on stock)*/ | ||
COALESCE(hu_agg.AD_Client_ID, s.AD_Client_ID) AS AD_Client_ID, | ||
COALESCE(hu_agg.AD_Org_ID, s.AD_Org_ID) AS AD_Org_ID, | ||
COALESCE(hu_agg.M_Warehouse_ID, s.M_Warehouse_ID) AS M_Warehouse_ID, | ||
COALESCE(hu_agg.M_Product_ID, s.M_Product_ID) AS M_Product_ID, | ||
COALESCE(hu_agg.C_UOM_ID, p.C_UOM_ID) AS C_UOM_ID, | ||
COALESCE(hu_agg.AttributesKey, s.AttributesKey) AS AttributesKey, | ||
COALESCE(hu_agg.QtyOnHand, 0) AS QtyOnHand, | ||
|
||
-- QtyOnHandChange is the quantity - in the view's UOM - to add to the *current* MD_Stock.QtyOnHand to get the *correct* qtyOnHand | ||
COALESCE(hu_agg.QtyOnHand, 0) - | ||
uomconvert( | ||
COALESCE(hu_agg.M_Product_ID, s.M_Product_ID), | ||
p.C_UOM_ID, | ||
COALESCE(hu_agg.C_UOM_ID, p.C_UOM_ID), | ||
COALESCE(s.QtyOnHand, 0)) AS QtyOnHandChange | ||
FROM | ||
MD_Stock s | ||
LEFT JOIN M_Product p ON p.M_Product_ID = s.M_Product_ID /*needed for its C_UOM_ID*/ | ||
FULL OUTER JOIN | ||
( | ||
SELECT | ||
hu.AD_Client_ID, | ||
hu.AD_Org_ID, | ||
l.M_Warehouse_ID, | ||
hus.M_Product_ID, | ||
hus.C_UOM_ID, | ||
GenerateHUAttributesKey(hu.m_hu_id) as AttributesKey, | ||
SUM(hus.Qty) as QtyOnHand | ||
FROM m_hu hu | ||
JOIN M_HU_Storage hus ON hus.M_HU_ID = hu.M_HU_ID | ||
JOIN M_Locator l ON l.M_Locator_ID=hu.M_Locator_ID | ||
WHERE hu.isactive='Y' | ||
and M_HU_Item_Parent_ID IS NULL | ||
|
||
/*please keep in sync with de.metas.handlingunits.IHUStatusBL.isPhysicalHU(I_M_HU)*/ | ||
and hu.HuStatus NOT IN ('P'/*Planning*/,'D'/*Destroyed*/,'E'/*Shipped*/) | ||
GROUP BY | ||
hu.AD_Client_ID, | ||
hu.AD_Org_ID, | ||
l.M_Warehouse_ID, | ||
hus.M_Product_ID, | ||
hus.C_UOM_ID, | ||
GenerateHUAttributesKey(hu.m_hu_id) | ||
) hu_agg ON true | ||
AND hu_agg.AD_Client_ID = s.AD_Client_ID | ||
AND hu_agg.AD_Org_ID=s.AD_Org_ID | ||
AND hu_agg.M_Warehouse_ID = s.M_Warehouse_ID | ||
AND hu_agg.M_Product_ID = s.M_Product_ID | ||
AND hu_agg.AttributesKey = s.AttributesKey | ||
/*please keep in sync with de.metas.handlingunits.IHUStatusBL.isPhysicalHU(I_M_HU)*/ | ||
and hu.HuStatus NOT IN ('P'/*Planning*/,'D'/*Destroyed*/,'E'/*Shipped*/) | ||
GROUP BY | ||
hu.AD_Client_ID, | ||
hu.AD_Org_ID, | ||
l.M_Warehouse_ID, | ||
hus.M_Product_ID, | ||
hus.C_UOM_ID, | ||
GenerateHUAttributesKey(hu.m_hu_id) | ||
) hu_agg ON true | ||
AND hu_agg.AD_Client_ID = s.AD_Client_ID | ||
AND hu_agg.AD_Org_ID=s.AD_Org_ID | ||
AND hu_agg.M_Warehouse_ID = s.M_Warehouse_ID | ||
AND hu_agg.M_Product_ID = s.M_Product_ID | ||
AND hu_agg.AttributesKey = s.AttributesKey | ||
; | ||
COMMENT ON VIEW MD_Stock_From_HUs_V IS | ||
'This view is used by the process MD_Stock_Reset_From_M_HUs to intitialize or reset the MD_stock table. | ||
Note that due to the outer join, existing MD_Stock records that currently don''t have any HU-storage are also represented (with qty=0) | ||
Belongs to issue "Show onhand quantity in new WebUI MRP Product Info Window" https://github.com/metasfresh/metasfresh-webui-api/issues/762'; | ||
COMMENT ON VIEW MD_Stock_From_HUs_V IS | ||
'This view is used by the process MD_Stock_Reset_From_M_HUs to initialize or reset the MD_stock table. | ||
Note that due to the outer join, existing MD_Stock records that currently don''t have any HU-storage are also represented (with qty=0) | ||
Belongs to issue "Show onhand quantity in new WebUI MRP Product Info Window" https://github.com/metasfresh/metasfresh-webui-api/issues/762'; |
59 changes: 59 additions & 0 deletions
59
...in/sql/postgresql/system/75-material-cockpit/5560210_sys_6718_fix_MD_Stock_From_HUs_V.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
|
||
DROP VIEW IF EXISTS MD_Stock_From_HUs_V; | ||
CREATE VIEW MD_Stock_From_HUs_V AS | ||
SELECT | ||
/*the COALESCEs are for the case of missing hu_agg (i.e. nothing on stock)*/ | ||
COALESCE(hu_agg.AD_Client_ID, s.AD_Client_ID) AS AD_Client_ID, | ||
COALESCE(hu_agg.AD_Org_ID, s.AD_Org_ID) AS AD_Org_ID, | ||
COALESCE(hu_agg.M_Warehouse_ID, s.M_Warehouse_ID) AS M_Warehouse_ID, | ||
COALESCE(hu_agg.M_Product_ID, s.M_Product_ID) AS M_Product_ID, | ||
COALESCE(hu_agg.C_UOM_ID, p.C_UOM_ID) AS C_UOM_ID, | ||
COALESCE(hu_agg.AttributesKey, s.AttributesKey) AS AttributesKey, | ||
COALESCE(hu_agg.QtyOnHand, 0) AS QtyOnHand, | ||
|
||
-- QtyOnHandChange is the quantity - in the view's UOM - to add to the *current* MD_Stock.QtyOnHand to get the *correct* qtyOnHand | ||
COALESCE(hu_agg.QtyOnHand, 0) - | ||
uomconvert( | ||
COALESCE(hu_agg.M_Product_ID, s.M_Product_ID), | ||
p.C_UOM_ID, | ||
COALESCE(hu_agg.C_UOM_ID, p.C_UOM_ID), | ||
COALESCE(s.QtyOnHand, 0)) AS QtyOnHandChange | ||
FROM | ||
MD_Stock s | ||
LEFT JOIN M_Product p ON p.M_Product_ID = s.M_Product_ID /*needed for its C_UOM_ID*/ | ||
FULL OUTER JOIN | ||
( | ||
SELECT | ||
hu.AD_Client_ID, | ||
hu.AD_Org_ID, | ||
l.M_Warehouse_ID, | ||
hus.M_Product_ID, | ||
hus.C_UOM_ID, | ||
GenerateHUAttributesKey(hu.m_hu_id) as AttributesKey, | ||
SUM(hus.Qty) as QtyOnHand | ||
FROM m_hu hu | ||
JOIN M_HU_Storage hus ON hus.M_HU_ID = hu.M_HU_ID | ||
JOIN M_Locator l ON l.M_Locator_ID=hu.M_Locator_ID | ||
WHERE hu.isactive='Y' | ||
and M_HU_Item_Parent_ID IS NULL | ||
|
||
/*please keep in sync with de.metas.handlingunits.IHUStatusBL.isPhysicalHU(I_M_HU)*/ | ||
and hu.HuStatus NOT IN ('P'/*Planning*/,'D'/*Destroyed*/,'E'/*Shipped*/) | ||
GROUP BY | ||
hu.AD_Client_ID, | ||
hu.AD_Org_ID, | ||
l.M_Warehouse_ID, | ||
hus.M_Product_ID, | ||
hus.C_UOM_ID, | ||
GenerateHUAttributesKey(hu.m_hu_id) | ||
) hu_agg ON true | ||
AND hu_agg.AD_Client_ID = s.AD_Client_ID | ||
AND hu_agg.AD_Org_ID=s.AD_Org_ID | ||
AND hu_agg.M_Warehouse_ID = s.M_Warehouse_ID | ||
AND hu_agg.M_Product_ID = s.M_Product_ID | ||
AND hu_agg.AttributesKey = s.AttributesKey | ||
; | ||
COMMENT ON VIEW MD_Stock_From_HUs_V IS | ||
'This view is used by the process MD_Stock_Reset_From_M_HUs to initialize or reset the MD_stock table. | ||
Note that due to the outer join, existing MD_Stock records that currently don''t have any HU-storage are also represented (with qty=0) | ||
Belongs to issue "Show onhand quantity in new WebUI MRP Product Info Window" https://github.com/metasfresh/metasfresh-webui-api/issues/762'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters