如何在字段 curyOrigDiscAmt 值更改时覆盖操作 Acumatica ERP

How to override action when field curyOrigDiscAmt value changes Acumatica ERP

我正在自定义 APInvoiceEntry 图表,当它在 Bills and Adjustments 屏幕 (ID=AP301000) 中修改时。

在图表的 POItem 部分添加项目时设置字段 curyOrigDiscAmt。有根据付款类型(例如现金预付款)和供应商设置的内容计算折扣的逻辑 class。

这是默认行为。然而,在那之后 运行s,我有逻辑我想 运行 调整这个数字。

我想我可以简单地将我的逻辑放在一个“字段更改”方法中。但是当更改为 curyOrigDiscAmt 时,我可以找到的 none 个操作被激活。

到目前为止,我已经尝试过:

protected virtual void _(Events.FieldVerifying<APInvoice, APInvoice.curyOrigDiscAmt> e)
protected virtual void _(Events.FieldUpdated<APInvoice, APInvoice.curyOrigDiscAmt> e)
protected void APInvoice_CuryOrigDiscAmt_FieldUpdating(PXCache cache, PXFieldUpdatingEventArgs e)
protected virtual void _(Events.RowSelecting<APInvoice> e)

None 其中在字段更改时触发。我需要在UI中反映给用户看,所以保存记录的时候再改也没什么用。我需要它在执行计算的基本代码 运行s 之后立即发生。

那是哪里?我如何找到它?

[编辑 -- 以下 Hugues Beauséjour 的回答的后续]

有没有办法只引发事件而根本不必更改 CalcDisc() 方法?我只需要调用事件。

换句话说有点像:

protected override void CalcDisc(PXCache sender, PXFieldUpdatedEventArgs e)
 {
     base.CalcDisc(sender, e);
     base.RaiseEvents(EVENTLIST_TO_RAISE);
 }

如果我可以帮助它保持对未来更改的防弹性,我宁愿根本不更改代码...

值是在 Terms 属性装饰 APInvoice.TermsID 字段中计算的:

#region TermsID
public abstract class termsID : PX.Data.BQL.BqlString.Field<termsID> { }

/// <summary>
/// The <see cref="PX.Objects.CS.Terms">credit terms</see> associated with the document (unavailable for prepayments and debit adjustments).\
/// Defaults to the <see cref="Vendor.TermsID">credit terms of the vendor</see>.
/// </summary>
[PXDBString(10, IsUnicode = true)]
[PXDefault(typeof(Search<Vendor.termsID,
    Where<Vendor.bAccountID, Equal<Current<APInvoice.vendorID>>,
        And<Current<APInvoice.docType>, NotEqual<APDocType.debitAdj>>>>),
    PersistingCheck = PXPersistingCheck.Nothing)]
[PXUIField(DisplayName = "Terms", Visibility = PXUIVisibility.Visible)]
[APTermsSelector]
[Terms(typeof(APInvoice.docDate), typeof(APInvoice.dueDate), typeof(APInvoice.discDate), 
       typeof(APInvoice.curyOrigDocAmt), typeof(APInvoice.curyOrigDiscAmt))]
public virtual string TermsID
{
    get;
    set;
}
#endregion

TermsAttributeclass构造函数的最后一个参数:CuryDiscBal

public TermsAttribute(Type DocDate, Type DueDate, Type DiscDate, Type CuryDocBal, Type CuryDiscBal)
{
    _DocDate = DocDate;
    _DueDate = DueDate;
    _DiscDate = DiscDate;
    _CuryDiscBal = CuryDiscBal;
    _CuryDocBal = CuryDocBal;
}

最终值在 Terms 属性的 CalcDisc 方法中计算。它分配有不引发事件的 SetValue 方法:

protected virtual void CalcDisc(PXCache sender, PXFieldUpdatedEventArgs e)
{
    if (_CuryDocBal != null && _CuryDiscBal != null &&
            sender.GetValue(e.Row, _FieldName) != null &&
        sender.GetValue(e.Row, _CuryDocBal.Name) != null && !sender.Graph.IsCopyPasteContext)
    {
        string TermsID = (string)sender.GetValue(e.Row, _FieldName);
        decimal CuryDocBal = (decimal)sender.GetValue(e.Row, _CuryDocBal.Name);
        decimal CuryDiscBal = 0m;

        Terms terms = SelectTerms(sender.Graph, TermsID);
        if (terms != null && terms.InstallmentType == TermsInstallmentType.Single && CuryDocBal > 0m)
        {
            CuryDiscBal = PXDBCurrencyAttribute.Round(sender, e.Row, CuryDocBal * (decimal)terms.DiscPercent / 100, CMPrecision.TRANCURY);
        }

        sender.SetValue(e.Row, _CuryDiscBal.Name, CuryDiscBal);
        PXUIFieldAttribute.SetEnabled(sender, e.Row, _CuryDiscBal.Name, (terms.InstallmentType == TermsInstallmentType.Single));
    }
}

要覆盖它,您可以将 Terms 属性替换为基于原始 TermsAttribute class 的自定义属性。然后覆盖字段 APInvoice.TermsID 并使用自定义属性对其进行修饰以替换原始条款。将 SetValue 分配更改为使用 SetValueExt 应该引发字段 updating/updated 事件。