Hello..
I need to get purch price agreement so.
first I create purch price agreement for testing and applied it in purch price
First I created it from Trade agreement journals
and this applied in PurchLine without problems..
now I need to don't allow PurchPrice to be greater than the price on journal
SO I created a class as below
class BT_PurchTable_Table_VaildatePriceAggrement { ////// /// /// [PostHandlerFor(tableStr(PurchLine), tableMethodStr(PurchLine, validateField))] public static void PurchLine_Post_validateField(XppPrePostArgs args) { PurchLine purchLine = args.getThis(); InventDim inventDim; inventDim = InventDim::find(purchLine.InventDimId); PriceDiscParameters parameters = PriceDiscParameters::construct(); parameters.parmModuleType(ModuleInventPurchSales::Purch); parameters.parmItemId(purchLine.ItemId); parameters.parmInventDim(inventDim); parameters.parmUnitID(purchLine.PurchUnit); parameters.parmPriceDiscDate(systemDateGet()); parameters.parmQty(purchLine.PurchQty); parameters.parmAccountNum(purchLine.VendAccount); parameters.parmCurrencyCode(purchLine.CurrencyCode); PriceDisc priceDisc = PriceDisc::newFromPriceDiscParameters(parameters); FieldId fieldId = args.getArg("fieldId"); boolean ret = args.getReturnValue(); switch(fieldId) { case fieldNum(purchLine, PurchPrice): if (purchLine.PurchPrice > priceDisc.priceUnit()) { ret = ret && checkFailed("Line per cent is to high!"); } break; } args.setReturnValue(ret); } }
but priceDisc.priceUnit() or priceDisc.price() always return 0
when I tested my code in Runable class
class getPrice
{
///
when debug the Runable class
parameters returns the PurchLine
PriceDisc return nothing
So how I can return the PurchPrice agreement ?
Thank you ..
Hi Ahmed,
If you check the method implementation "purchLine.salesPurchLineInterface().priceDisc_PriceCache(purchLine.InventDim(), true)"you will see that price group is set for PriceDisc from PurchTable (and before it's copied from Vendor), but PriceDiscParameters doesn't cover it in your code.
That's why I recommend using the same method if you need to be sure to have the same behavior.
if (priceDisc.findPrice(VendTable::find(purchLine.VendAccount).PriceGroup)) { retPrice = priceDisc.price(); }
this code return the right value ,but I didn't understand why I need to use PriceGroup in findPrice()
Gunjan ,thank you
my problem is that priceDisc return null
Sergei really thank you ,it's return the right value from agreement.
It could be that some search parameters in your code don't match parameters from purch line.
In my job I pointed to the PO and line that applied the agreement so i think no problem in my data , maybe there some information not inserted in the parameters ,Also I reviewed all the data manually .
Hi Ahmad,
Can you try this line and try ?
priceDisc.findItemPrice();
Hi Ahmed,
It could be that some search parameters in your code don't match parameters from purch line.
Try to use the same code as in PurchLine to get price
purchLine.salesPurchLineInterface().priceDisc_PriceCache(purchLine.InventDim(), true).price();
Hi Ahmed Osamam,
The code looks correct, Did you check if the data exists in purchase agreements for that item/invetDim/Vendor combination?
Martin Dráb
456
Most Valuable Professional
Abhilash Warrier
310
Saalim Ansari
261