Skip to content

Commit

Permalink
#6938 Do not round in view and exttract price pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
cristinamghita committed Jul 1, 2020
1 parent 33606eb commit 2551891
Show file tree
Hide file tree
Showing 2 changed files with 586 additions and 26 deletions.
Expand Up @@ -14,35 +14,43 @@ SELECT pp.AD_Org_ID,
pp.IsActive,

-- Displayed pricelist data
pc.Name AS ProductCategory,
pc.value AS ProductCategoryValue,
pc.Name AS ProductCategory,
pc.value AS ProductCategoryValue,
p.M_Product_ID,
p.Value,
p.Name AS ProductName,
p.Name AS ProductName,
pp.IsSeasonFixedPrice,
hupip.Name AS ItemProductName,
pm.Name AS PackingMaterialName,
ROUND(COALESCE(ppa.PriceStd, pp.PriceStd), coalesce(pl.priceprecision, 2)) AS PriceStd,
ROUND(pp2.PriceStd, coalesce(pl2.priceprecision, 2)) AS AltPriceStd,
CASE WHEN pp2.PriceStd IS NULL THEN 0 ELSE 1 END AS hasaltprice,
hupip.Name AS ItemProductName,
pm.Name AS PackingMaterialName,
COALESCE(ppa.PriceStd, pp.PriceStd) AS PriceStd,
CASE
WHEN pl.priceprecision = 0
THEN '#,##0'
ELSE Substring('#,##0.000' FROM 0 FOR 7 + pl.priceprecision :: integer) END AS PricePattern1,
pp2.PriceStd AS AltPriceStd,
CASE
WHEN pl.priceprecision = 0
THEN '#,##0'
ELSE Substring('#,##0.000' FROM 0 FOR 7 + pl2.priceprecision :: integer) END AS PricePattern2,
CASE WHEN pp2.PriceStd IS NULL THEN 0 ELSE 1 END AS hasaltprice,
uom.UOMSymbol,
COALESCE(ppa.Attributes, '') as attributes,
COALESCE(ppa.Attributes, '') as attributes,
pp.seqNo,

-- Filter Columns
bp.C_BPartner_ID,
plv.M_Pricelist_Version_ID,
plv2.M_Pricelist_Version_ID AS Alt_PriceList_Version_ID,
plv2.M_Pricelist_Version_ID AS Alt_PriceList_Version_ID,

-- Additional internal infos to be used
pp.M_ProductPrice_ID,
ppa.m_attributesetinstance_ID,
bp_ip.M_HU_PI_Item_Product_ID as M_HU_PI_Item_Product_ID,
uom.X12DE355 as UOM_X12DE355,
hupip.Qty as QtyCUsPerTU,
it.m_hu_pi_version_id AS m_hu_pi_version_id,
c.iso_code as currency,
c2.iso_code as currency2
bp_ip.M_HU_PI_Item_Product_ID as M_HU_PI_Item_Product_ID,
uom.X12DE355 as UOM_X12DE355,
hupip.Qty as QtyCUsPerTU,
it.m_hu_pi_version_id AS m_hu_pi_version_id,
c.iso_code as currency,
c2.iso_code as currency2

FROM M_ProductPrice pp

Expand All @@ -69,14 +77,24 @@ FROM M_ProductPrice pp

AND CASE
WHEN
EXISTS(select 0 from Report.Valid_PI_Item_Product_V v where p.M_Product_ID = v.M_Product_ID AND v.hasPartner is true and bp.C_BPartner_ID = v.C_BPartner_ID)
EXISTS(select 0
from Report.Valid_PI_Item_Product_V v
where p.M_Product_ID = v.M_Product_ID
AND v.hasPartner is true
and bp.C_BPartner_ID = v.C_BPartner_ID)
THEN vip.C_BPartner_ID = bp.C_BPartner_ID
else vip.C_BPartner_ID IS NULL END
) bp_ip ON TRUE

LEFT OUTER JOIN LATERAL
(
SELECT M_ProductPrice_ID, M_Attributesetinstance_ID, PriceStd, IsActive, M_HU_PI_Item_Product_ID, Attributes, Signature
SELECT M_ProductPrice_ID,
M_Attributesetinstance_ID,
PriceStd,
IsActive,
M_HU_PI_Item_Product_ID,
Attributes,
Signature
FROM report.fresh_AttributePrice ppa
WHERE ppa.isActive = 'Y'
AND ppa.M_ProductPrice_ID = pp.M_ProductPrice_ID
Expand All @@ -87,16 +105,20 @@ FROM M_ProductPrice pp
LEFT OUTER JOIN m_hu_pi_item_product hupip ON
case
when pp.m_hu_pi_item_product_id is null then
bp_ip.m_hu_pi_item_product_ID = hupip.m_hu_pi_item_product_id and hupip.isActive = 'Y'
bp_ip.m_hu_pi_item_product_ID = hupip.m_hu_pi_item_product_id and hupip.isActive = 'Y'
else
bp_ip.m_product_id = hupip.m_product_id and hupip.isActive = 'Y'
end
LEFT OUTER JOIN m_hu_pi_item it ON hupip.M_HU_PI_Item_ID = it.M_HU_PI_Item_ID AND it.isActive = 'Y'
LEFT OUTER JOIN m_hu_pi_item pmit ON it.m_hu_pi_version_id = pmit.m_hu_pi_version_id AND pmit.itemtype::TEXT = 'PM'::TEXT AND pmit.isActive = 'Y'
LEFT OUTER JOIN m_hu_packingmaterial pm ON pmit.m_hu_packingmaterial_id = pm.m_hu_packingmaterial_id AND pm.isActive = 'Y'
LEFT OUTER JOIN m_hu_pi_item pmit
ON it.m_hu_pi_version_id = pmit.m_hu_pi_version_id AND pmit.itemtype::TEXT = 'PM'::TEXT AND
pmit.isActive = 'Y'
LEFT OUTER JOIN m_hu_packingmaterial pm
ON pmit.m_hu_packingmaterial_id = pm.m_hu_packingmaterial_id AND pm.isActive = 'Y'


INNER JOIN M_PriceList_Version plv ON pp.M_PriceList_Version_ID = plv.M_PriceList_Version_ID AND plv.IsActive = 'Y'
INNER JOIN M_PriceList_Version plv
ON pp.M_PriceList_Version_ID = plv.M_PriceList_Version_ID AND plv.IsActive = 'Y'
/*
Get Comparison Prices
*/
Expand All @@ -108,15 +130,20 @@ FROM M_ProductPrice pp
SELECT COALESCE(ppa2.PriceStd, pp2.PriceStd) AS PriceStd, ppa2.signature
FROM M_ProductPrice pp2
/* Joining attribute prices */
INNER JOIN report.fresh_AttributePrice ppa2 ON pp2.M_ProductPrice_ID = ppa2.M_ProductPrice_ID AND ppa2.m_pricelist_version_id = pp2.m_pricelist_version_id
INNER JOIN report.fresh_AttributePrice ppa2 ON pp2.M_ProductPrice_ID = ppa2.M_ProductPrice_ID AND
ppa2.m_pricelist_version_id = pp2.m_pricelist_version_id

WHERE p.M_Product_ID = pp2.M_Product_ID
AND pp2.M_Pricelist_Version_ID = plv2.M_Pricelist_Version_ID
AND pp2.IsActive = 'Y'
AND (pp2.m_hu_pi_item_product_ID = pp.m_hu_pi_item_product_ID OR (pp2.m_hu_pi_item_product_ID is null and pp.m_hu_pi_item_product_ID is null))
AND (pp2.m_hu_pi_item_product_ID = pp.m_hu_pi_item_product_ID OR
(pp2.m_hu_pi_item_product_ID is null and pp.m_hu_pi_item_product_ID is null))
AND pp2.isAttributeDependant = pp.isAttributeDependant
--avoid comparing different prices in same pricelist
AND (CASE WHEN pp2.M_PriceList_Version_ID = pp.M_PriceList_Version_ID THEN pp2.M_ProductPrice_ID = pp.M_ProductPrice_ID ELSE TRUE END)
AND (CASE
WHEN pp2.M_PriceList_Version_ID = pp.M_PriceList_Version_ID
THEN pp2.M_ProductPrice_ID = pp.M_ProductPrice_ID
ELSE TRUE END)
/* we have to make sure that only prices with the same attributes and packing instructions are compared. Note:
* - If there is an Existing Attribute Price but no signature related columns are filled the signature will be ''
* - If there are no Attribute Prices the signature will be null
Expand All @@ -136,7 +163,9 @@ WHERE pp.isActive = 'Y'
AND (pp.M_Attributesetinstance_ID = ppa.M_Attributesetinstance_ID OR pp.M_Attributesetinstance_ID is null)
AND (pp.M_HU_PI_Item_Product_ID = bp_ip.M_HU_PI_Item_Product_ID OR pp.M_HU_PI_Item_Product_ID is null)

AND (case when plv2.M_PriceList_Version_ID = plv.M_PriceList_Version_ID THEN ppa.signature = pp2.signature ELSE true end)
AND (case
when plv2.M_PriceList_Version_ID = plv.M_PriceList_Version_ID THEN ppa.signature = pp2.signature
ELSE true end)
;

COMMENT ON VIEW RV_fresh_PriceList_Comparison
Expand Down

0 comments on commit 2551891

Please sign in to comment.