【发布时间】:2021-04-01 02:48:51
【问题描述】:
这是我在这里发布的问题Override action on curyOrigDiscAmt 的后续行动
按照那里的建议,我正在尝试:
-
根据原来的 TermsAttribute 创建自定义属性 类。
-
覆盖字段 APInvoice.TermsID
-
使用自定义属性装饰字段 APInvoice.TermsID 和 用它来替换原来的条款。
-
终于改变了CalcDisc()方法的逻辑
这是我所做的:
1.自定义属性:
public class CTERMSIDAttribute : PX.Objects.CS.TermsAttribute
{
public CTERMSIDAttribute(Type DocDate, Type DueDate, Type DiscDate, Type CuryDocBal, Type CuryDiscBal) : base(DocDate, DueDate, DiscDate, CuryDocBal, CuryDiscBal)
{
var cBalance = _CuryDocBal;
var cDiscount = _CuryDiscBal;
int i = 0;
}
protected override void CalcDisc(PXCache sender, PXFieldUpdatedEventArgs e)
{
base.CalcDisc(sender, e);
int i2 = 0;
}
}
注意:目前没有任何事情要做。我只是在 int i = 0 上放了一个断点,以确保我的代码在运行时被执行。
我还创建了一个用新创建的属性装饰的类:
public class CTermID : Vendor.termsID
{
[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]
[CTERMSIDAttribute(typeof(APInvoice.docDate), typeof(APInvoice.dueDate), typeof(APInvoice.discDate),
typeof(APInvoice.curyOrigDocAmt), typeof(APInvoice.curyOrigDiscAmt))]
public string termsID { get; set; }
}
我不确定这是否需要,也没有使用,但我在 sn-p 中看到了它,所以我实现了它。
2 & 3. 覆盖和装饰
[PXMergeAttributes(Method = MergeMethod.Append)] // add to other properties
[PXRemoveBaseAttribute(typeof(Vendor.termsID))] // remove existing property
[CTERMSIDAttribute(typeof(APInvoice.docDate), typeof(APInvoice.dueDate), typeof(APInvoice.discDate),
typeof(APInvoice.curyOrigDocAmt), typeof(APInvoice.curyOrigDiscAmt))]
public CTermID termsID { get; set; } // redefine termsID to use custom attribute
protected virtual void _(Events.CacheAttached<APInvoice.termsID> e)
{
int i3 = 0;
}
4. CalcDisc() 的覆盖方法
这是在新属性中(之前在步骤 1 中显示):
protected override void CalcDisc(PXCache sender, PXFieldUpdatedEventArgs e)
{
base.CalcDisc(sender, e);
int i2 = 0;
}
同样,它现在什么都不做,我只是在 int i2 = 0 处放置一个断点来检查它是否在运行时命中。事实并非如此。
发生的情况是第一个断点 (i=0) 命中......实际上它命中了好几次......但其他断点都没有,这告诉我覆盖工作不正常。
我错过了什么?
[编辑] 根据 Patrick Chen 的建议,我将其更改为:
[PXMergeAttributes(Method = MergeMethod.Replace)]
[CTERMSIDAttribute(typeof(APInvoice.docDate), typeof(APInvoice.dueDate), typeof(APInvoice.discDate), typeof(APInvoice.curyOrigDocAmt), typeof(APInvoice.curyOrigDiscAmt))]
public CTermID termsID { get; set; } // redefine termsID to use custom attribute
protected virtual void _(Events.CacheAttached<APInvoice.termsID> e)
{
int i = 0;
}
我的 DoCalc() 版本仍然没有被触发。
【问题讨论】: