无法获取 Events.CacheAttached 以识别 Acuamtica 中的自定义属性 [英] Cannot get Events.CacheAttached to recognize custom Attribute in Acuamtica

查看:9
本文介绍了无法获取 Events.CacheAttached 以识别 Acuamtica 中的自定义属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我在此处发布的问题的后续内容

FieldUpdated 方法不存在于自定义属性中,因此该方法不会被任何机制调用.自定义属性必须更紧密地遵循原始实现,其中包含大约十几种方法.

This is a follow-up to the question I posted here Override action on curyOrigDiscAmt

Following the advice there, I am trying to:

  1. Create a custom attribute based on the original TermsAttribute class.

  2. Override field APInvoice.TermsID

  3. Decorate the field APInvoice.TermsID with the custom attribute and use this to replace the original Terms.

  4. Finally change the logic of the CalcDisc() method

Here is what I have done:

1. Custom Attribute:

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;
        
    }
}

NOTE: there is nothing being done in this for right now. I just put a break point on the int i = 0 to make sure my code is getting executed at run time.

I also create a class that is decorated with the newly minted attribute:

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; }
}

I am not sure this is needed, nor used, but I saw it in a snippet, so I implemented it.

2 & 3. Override and decorate

    [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. Override Method for CalcDisc()

This is in the new attribute (previously shown in step 1):

    protected override void CalcDisc(PXCache sender, PXFieldUpdatedEventArgs e)
    {
        base.CalcDisc(sender, e);
        int i2 = 0;            
    }

Again, it doesn't do anything right now, I just put a breakpoint at the int i2 = 0 to check if it is hitting at runtime. And it isn't.

What happens is that the first breakpoint (i=0) hits.. in fact it hits several times... but none of the others do, which tells me that the override isn't working correctly.

What am I missing?

[EDIT] Per Patrick Chen's suggestion, I changed it to this:

[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;
      }

And still my version of DoCalc() is not fired.

解决方案

There's no mechanism to call CalcDisc method in your custom attribute.

In TermsAttribute a FieldUpdated event handler is used to call the CalcDisc method:

This FieldUpdated method is not present in the custom attribute so the method isn't called by any mechanism. The custom attribute has to follow more closely the original implementation which has about a dozen methods.

这篇关于无法获取 Events.CacheAttached 以识别 Acuamtica 中的自定义属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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