销售价格每隔一次更新 [英] Sales Price Updating Every Other Time

查看:61
本文介绍了销售价格每隔一次更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我扩展了SOOrderEntry图并添加了以下代码,以便更新与当前要更新的当前行相关的同一销售订单上的另一行:

I have extended the SOOrderEntry graph and added the following code in order to update another line on the same sales order that is related to the current line that is being updated:

protected virtual void SOLine_RowUpdating(PXCache cache, PXRowUpdatingEventArgs e)
{
    if (e.NewRow == null)
    {
        return;
    }

    SOLine soLine = (SOLine)e.NewRow;

    SOLine relatedLine = Base.Transactions.Search<SOLine.inventoryID> 
    (456);

    if (relatedLine != null)
    {
           relatedLine.Qty = soLine.Qty;
           relatedLine.CuryUnitPrice = 24.20;

           Base.Transactions.Update(relatedLine);
           Base.Transactions.View.RequestRefresh();
    }
}

当我尝试通过更新数量来进行测试时在当前行中,相关行中的单价仅在我更新数量时每隔一次更新一次。相关项目是非库存项目,当前项目是库存项目。

When I try to test this by updating the Qty on the current line, the Unit Price on the related line only updates every other time that I update the Qty. The related item is a Non-stock item where the current item is a Stock Item.

我正在18.102.0048的Sales Demo环境中进行此操作

I'm doing this in a Sales Demo environment on 18.102.0048

我尝试过此操作,但现在扩展价格始终为0.00:

I tried this but, now the Extended Price is always 0.00:

protected virtual void SOLine_RowUpdating(PXCache cache, PXRowUpdatingEventArgs e)
{
    if (e.NewRow == null)
    {
        return;
    }

    SOLine soLine = (SOLine)e.NewRow;

    SOLine relatedLine = Base.Transactions.Search<SOLine.inventoryID> 
(456);

    if (relatedLine != null)
    {
       SOLine oldRelatedLine = PXCache<SOLine>.CreateCopy(relatedLine);
       relatedLine.Qty = soLine.Qty;
       relatedLine.CuryUnitPrice = 24.20;

       Base.Transactions.Cache.RaiseRowUpdated(relatedLine, oldRelatedLine);

       Base.Transactions.Update(relatedLine);
       Base.Transactions.View.RequestRefresh();
    }
}


推荐答案

何时一个字段计算出的值取决于另一个字段值,有时它需要触发事件以重新计算该值。

When a field calculated value depends on another field value it's sometimes required to trigger events for the value to be recalculated.

在某些情况下,只需要触发该字段的事件即可您修改了。使用C#赋值运算符(=)或SetValue方法分配值不会触发事件处理程序,SetValueExt方法将:

In some cases it only requires firing the event for the field that you modified. Assigning values using the C# assignment operator (=) or the SetValue method will not trigger the events handler, SetValueExt method will:

// Doesn't trigger events
relatedLine.Qty = soLine.Qty;
cache.SetValue<SOLine.qty>(relatedLine, soLine.Qty);

// This will trigger events
cache.SetValueExt<SOLine.qty>(relatedLine, soLine.Qty);

在某些情况下,您也需要为整个行触发事件。您可以使用RaiseXxxYyy方法执行此操作。我在示例中使用了Current,但是如果Current不是要修改的行,则可能需要对其进行修改:

There are some cases where you need to fire events for the whole row too. You can use the RaiseXxxYyy methods to do that. I used Current in the example but you might have to adapt it if Current is not the row being modified:

SOLine oldRowCopy = PXCache<SOLine>.CreateCopy(Base.Transactions.Current);
Base.Transactions.Current.Qty = soLine.Qty;
Base.Transactions.Cache.RaiseRowUpdated(Base.Transactions.Current, oldRowCopy);

编辑

看着更新的问题,可能不会有太大的区别,但是我建议您切换这两行的顺序:

Looking at updated question, it might not make much of a difference but I suggest you switch the order of these 2 lines:

   Base.Transactions.Cache.RaiseRowUpdated(relatedLine, oldRelatedLine);
   Base.Transactions.Update(relatedLine);

就像这样:

// You want the value in Cache to be updated
Base.Transactions.Update(relatedLine);

// After Cache value is set you want to raise the events
Base.Transactions.Cache.RaiseRowUpdated(relatedLine, oldRelatedLine);

这篇关于销售价格每隔一次更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆