添加新的 SOLine 时动态更新所有 SOLine 项目单价

Updating ALL SOLine items unit prices dynamically when a new SOLine is added

我有一个由 PXAction 调用的存储过程。我知道使用存储过程违反 Acumatica 的最佳实践,但我还没有为我的目标找到替代解决方案。存储过程根据确定单价的 breakQuantity 评估每个行项目及其关联的价格 class。如果多个商品属于同一价格 class == 或超过突破数量,则减少单价。

我开始的是一行更新

 protected virtual void SOLine_RowUpdating(PXCache sender, PXRowUpdatingEventArgs e)
    {
        SOLine row = (SOLine)e.Row;
        formalizeOrderTotal(row);
    }

然后在我的 formalizeOrderTotal 函数中,它在 SOLine in lines.Select() 上执行了一个 foreach 循环以增加订单数量。作为测试,我只是尝试将所有订单数量相加并将其应用于每个订单项。这仅在刷新后更新,这否定了将存储过程移动到 c# function/Acumatica 事件处理程序的目的。

如果有人对更新缓存中所有订单项的好方法有一些建议,如果您能提供一些意见,我们将不胜感激。

尝试使用 Base.Transactions.View.RequestRefresh();,它会要求网格自行刷新。在此示例中,我将每条线的数量设置为网格中存在的 SOLines 的数量。

using PX.Data;
namespace PX.Objects.SO
{

    public class SOOrderEntry_Extension:PXGraphExtension<SOOrderEntry>
    {
        protected virtual void SOLine_RowUpdating(PXCache sender, PXRowUpdatingEventArgs e)
        {
            SOLine row = (SOLine)e.Row;
            formalizeOrderTotal(row);
        }

        private void formalizeOrderTotal(SOLine row)
        {
            foreach (SOLine line in Base.Transactions.Select())
            {
                if(line.Qty == Base.Transactions.Select().Count)
                {
                    continue;
                }

                line.Qty = Base.Transactions.Select().Count;
                Base.Transactions.Update(line);
                Base.Transactions.View.RequestRefresh();
            }
        }
    }
}