Skip to main content
Answer

Having trouble increasing the Applied To Order. AR Error: Entry must be less or equal to

  • September 13, 2023
  • 3 replies
  • 117 views

Forum|alt.badge.img+7

I have a sales order with a pre-payment on it. The pre-payment has a balance meaning that the Applied to Order value is less than the value of the pre-payment and less than the value of the order.

In my case I have a detail line on the sales order that is increasing in value and I would like to bump up the Applied to Order value accordingly.

However, when I try to do this via code, I get an error: Entry must be less or equal to $X.  $X is always the value of the Applied to Order amount.

Is there something that I’m missing that I need to do to the order so that I can change the SOAdjust record?

public PXAction<SOOrder> TestPreAuthEdit;
[PXButton(CommitChanges = true, IsLockedOnToolbar = true, Category = "")]
[PXUIField(DisplayName = "Test Pre Auth Edit", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select, Enabled = true)]

public virtual IEnumerable testPreAuthEdit(PXAdapter adapter)
{
SOOrder order = Base.Document.Current;

foreach (SOLine line in Base.Transactions.Select())
{
InventoryItem item = InventoryItem.PK.Find(Base, line.InventoryID);
if (item == null) continue;
if (item.InventoryCD.Trim() == "ITEMCODE") //This is just to locate a line on the SO
{
Base.Caches[typeof(SOLine)].SetValueExt<SOLine.curyUnitPrice>(line, line.CuryUnitPrice + 10);
Base.Caches[typeof(SOLine)].Update(line);
Base.Caches[typeof(SOOrder)].Update(order);
}

}

Base.Save.PressButton(); //I've tried with and without this line

foreach (SOAdjust payment in Base.Adjustments.Select()) //I only have one prepayment so I'm not worried about the loop
{
Base.Caches[typeof(SOAdjust)].SetValueExt<SOAdjust.curyAdjdAmt>(payment, payment.CuryAdjdAmt + 10);
Base.Caches[typeof(SOAdjust)].Update(payment);
}
return adapter.Get();

}

 

Best answer by Django

I added those trying to get the order to update in some fashion, hoping that would update the balance value on the SOAdjust record. I was able to remove the .Update(order) line with no change.

I have a work around at the moment by overriding SOAdjust_CuryAdjdAmt_FieldVerifying and changing the following test from:

if (adj.AdjgCuryInfoID == null || adj.CuryDocBal == null)

to

if (adj.AdjgCuryInfoID == null || adj.CuryDocBal == 0)

Which forces the system to calculate the CuryDocBal value when updating the CuryAdjdAmt field value because the value is coming into the method with zero instead of the actual balance.

I don’t know how to force my PXGraph to run the calculation on the Adjustments view records.

I feel like I’ve over engineered this solution but sometimes there’s a mystery in the the logic that’s waiting to be revealed.

3 replies

Forum|alt.badge.img+7
  • Author
  • Captain II
  • September 13, 2023

Further exploration.

In SOAdjust_CuryAdjdAmt_FieldVerifying this line of code does the field validation logic

decimal newBalance = (decimal)adj.CuryDocBal + (decimal)adj.CuryAdjdAmt - (decimal)e.NewValue;

And the issue is that the adj.CuryDocBal is zero when I run the code above. When I test the value in the UI, adj.CuryDocBal has the value that I see on the screen.

I see that this is a calculated/unbound field.

What I find puzzling is that in my second foreach loop, the payment.CuryDocBal value will be, say, $110, but when the record arrives in SOAdjust_CuryAdjdAmt_FieldVerifying, and this line runs:

SOAdjust adj = (SOAdjust)e.Row;

adj.CuryDocBal is zero.

I feel like there’s something simple that I’m missing.

 

 


Zoltan Febert
Jr Varsity I
Forum|alt.badge.img+3
  • Jr Varsity I
  • September 14, 2023

Why do you need these Base.Caches[typeof(SOOrder)].Update(order); updates? SetValueExt updates the lines in the cache without them, and also raises the proper events.

Isn’t it possible it causes your issue?


Forum|alt.badge.img+7
  • Author
  • Captain II
  • Answer
  • September 14, 2023

I added those trying to get the order to update in some fashion, hoping that would update the balance value on the SOAdjust record. I was able to remove the .Update(order) line with no change.

I have a work around at the moment by overriding SOAdjust_CuryAdjdAmt_FieldVerifying and changing the following test from:

if (adj.AdjgCuryInfoID == null || adj.CuryDocBal == null)

to

if (adj.AdjgCuryInfoID == null || adj.CuryDocBal == 0)

Which forces the system to calculate the CuryDocBal value when updating the CuryAdjdAmt field value because the value is coming into the method with zero instead of the actual balance.

I don’t know how to force my PXGraph to run the calculation on the Adjustments view records.

I feel like I’ve over engineered this solution but sometimes there’s a mystery in the the logic that’s waiting to be revealed.