【问题标题】:How to disable the sales order screen discount calculation如何禁用销售订单屏幕折扣计算
【发布时间】:2018-12-05 20:57:07
【问题描述】:

我在销售订单中有修改需要用派生值更新销售订单行单价。这运行良好,并且在选择项目并且我在 SOLine_RowUpdating 事件中的代码已执行后显示新的单价。然而,在选择数量后 SOLine_RowUpdating 再次执行,之后系统会像往常一样计算折扣。由于我有自己的不应该打折的价格,我想覆盖或取消这个标准折扣计算,并保持我的价格不变。这是 SOLine_RowUpdating 代码,它运行良好。

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

  Customer customer = Base.customer.Current;
  if (customer == null) return;

  SOLine soLine = (SOLine)e.NewRow;
  int BAAccountID = Convert.ToInt32(customer.BAccountID);
  int lCompanyID = PX.Data.Update.PXInstanceHelper.CurrentCompany;
  int lInventoryID = Convert.ToInt32(soLine.InventoryID);

  LookupPriceAndDiscountDetails(BAAccountID, lCompanyID, lInventoryID);  // My own code
  sender.SetValueExt<SOLine.curyUnitPrice>(soLine, gdNewUnitPrice);      //New price is in gdNewUnitPrice

  Base.Transactions.Cache.RaiseRowUpdated(soLine, soLine);
  Base.Transactions.View.RequestRefresh();
}

经过大量调查,我发现各种帖子建议的这种方法应该清除/取消折扣,实际上我可以在标准 PX.Objects.SO.SOOrderEntry Row_Updated 事件中找到它,但是当我在我的图形扩展它不会更新或清除,因为 soline(缓存)值仍然显示折扣数字。我一定错过了一些简单的东西。

在这一点上赞赏的任何想法......

protected void SOLine_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e)
{
  SOLine row = e.Row as SOLine;
  DiscountEngine<SOLine>.ClearDiscount(sender,row);
  // RecalculateDiscounts(sender, row);  // ? (Maybe this) 
}

【问题讨论】:

    标签: acumatica


    【解决方案1】:

    你在正确的轨道上。再多几个cmets。 1. Acumatica 将始终执行基本 SOLine_RowUpdated 事件,然后执行您的 SOLine_RowUpdated 2. 如果你想控制 SOLine_RowUpdated 事件的执行流程,你可以这样做:

    protected void SOLine_RowUpdated(PXCache cache, PXRowUpdatedEventArgs e, PXRowUpdated del)
    {
        //some code
        //del or pointer to basic method can be called like this:
       del(cache, e);
    }
    
    1. del 将是指向 SOLine_RowUpdated 方法的指针

    您将有以下选择:

    一个。根本不要调用del(我不推荐你这种方法,因为基本方法有很多工作人员,而不仅仅是折扣计算)

    b.调用 del 然后删除折扣信息

    c。如果你的方法ClearDiscount不会清除折扣信息,那可能是因为它试图通过简单的assign来实现,也许你可以试试SetValueExt方法。

    还有一点要记住。默认情况下,Acumatica 将调用基本的 RowUpdated 方法,然后它会调用您的方法,因此您不需要使用委托。我建议您从 RowUpdated 图形扩展中的 SetValueExt 开始,而不是简单的分配。

    【讨论】:

    • 感谢您的建议。我肯定会尝试,但我从您的回复中收到的最有趣的信息是界面更改时事件触发的顺序。我看到 del 是基础 SOLine_RowUpdated 类,并且“del(cache, e)”行确实告诉基类执行和处理缓存的内容。
    【解决方案2】:

    为方便起见,您可以使用以下图形扩展关闭对 RecalculateDiscounts 的调用:

    public class SOOrderEntryExtension : PXGraphExtension<SOOrderEntry>
    {
        [PXOverride]
        public virtual void RecalculateDiscounts(PXCache sender, SOLine line, Action<PXCache, SOLine> del)
        {
            // if no discounts wanted, just return
    
            // else call the base/standard Acumatica calc discounts on sales order...
            if (del != null)
            {
                del(sender, line);
            }
        }
    }
    

    您还可以使用 ARSalesPriceMaint 上的图形扩展来编写自己的定价逻辑:

    public class ARSalesPriceMaintExtension : PXGraphExtension<ARSalesPriceMaint>
    {
        [PXOverride]
        public virtual decimal? CalculateSalesPriceInt(PXCache sender, string custPriceClass, int? customerID, int? inventoryID, int? siteID, CurrencyInfo currencyinfo, decimal? quantity, string UOM, DateTime date, bool alwaysFromBaseCurrency,
            Func<PXCache, string, int?, int?, int?, CurrencyInfo, decimal?, string, DateTime, bool, decimal?> del)
        {
            //run your custom price logic here and return
    
            // or return the base/standard Acumatica price logic...
            return del?.Invoke(sender, custPriceClass, customerID, inventoryID, siteID, currencyinfo, quantity, UOM, date, alwaysFromBaseCurrency);
        }
    }
    

    这样,您无需对抗事件,而是覆盖事件用于设置销售订单上的折扣和价格的调用。我还相信 ARSalesPRiceMaint 扩展将使用定价逻辑覆盖其他屏幕,这有助于减少不同订单输入屏幕上的重复代码。

    【讨论】:

    • 非常感谢。给出的第一个示例中,SOOrderEntryExtension 代码中的 RecalculateDiscounts 覆盖对我来说非常有效。
    • 完美。不要忘记标记答案以关闭问题
    猜你喜欢
    • 1970-01-01
    • 2022-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多