I created some new fields on the Price/Cost tab of the Stock Item screen:
UsrWhlPrice
UsrWhlPriceChangeDate
UsrPrevWhlPrice
UsrPrevWhlPriceChangeDate
The intention is that the first will store the wholesale price for an item and the second records any time the wholesale price is changed.
The UsrPrev… fields will be updated when the wholesale price changes.
I added them and all appeared to be fine. I tested and they recorded the information I needed and I used them in an import scenario to import the wholesale prices.
I am using the code below to monitor for a change to the price and update the fields.
protected void InventoryItemCurySettings_UsrWHLPrice_FieldVerifying(PXCache cache, PXFieldVerifyingEventArgs e, PXFieldVerifying InvokeBaseHandler)
{
if(InvokeBaseHandler != null)
InvokeBaseHandler(cache, e);
var row = (InventoryItemCurySettings)e.Row;
if (row== null) return;
try {
InventoryItemCurySettingsExt inventoryItemCurySettingsExt =
PXCache<InventoryItemCurySettings>.GetExtension<InventoryItemCurySettingsExt >(row);
if (inventoryItemCurySettingsExt.UsrWHLPrice != null) {
inventoryItemCurySettingsExt.UsrPrevWHLPrice = inventoryItemCurySettingsExt.UsrWHLPrice;
}
}
catch (Exception error) {
PXTrace.WriteInformation("Error: " + error);
}
}
// Adds WHL Price and Timestamp fields
protected void InventoryItemCurySettings_UsrWHLPrice_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e, PXFieldUpdated InvokeBaseHandler)
{
if(InvokeBaseHandler != null)
InvokeBaseHandler(cache, e);
var row = (InventoryItemCurySettings)e.Row;
if (row== null) return;
try {
InventoryItemCurySettingsExt inventoryItemCurySettingsExt =
PXCache<InventoryItemCurySettings>.GetExtension<InventoryItemCurySettingsExt >(row);
if (inventoryItemCurySettingsExt.UsrWhlPriceChangeDate != null) {
inventoryItemCurySettingsExt.UsrPrevWhlPriceChangeDate = inventoryItemCurySettingsExt.UsrWhlPriceChangeDate;
}
inventoryItemCurySettingsExt.UsrWhlPriceChangeDate = PX.Common.PXTimeZoneInfo.Now;
}
catch (Exception error) {
PXTrace.WriteInformation("Error: " + error);
}
}
The problem is that when I change other details on the Stock Items screen and save it is losing the value that was already saved in the field. Changing the default Vendor did this and also changing the non-wholesale price (Default Price) and clicking save. The value in UsrWhlPrice is reset to 0.00.
What am I dong wrong?
I think I am doing something wrong in this but I don’t know what.
Any help would be very much appreciated,
Phil