如何正确扩展 CustomerPaymentMethod?

How do I extend CustomerPaymentMethod correctly?

我有一些东西可以运行,但肯定不正确

希望:添加一个字段作为 CustomerPaymentMethod 的扩展 代码/Table下面都是

问题: 为什么我需要 PaymentMethodID 字段,如果需要我该如何填写?

在 DB Table OR Dac 中没有这个开始。此 loads/works 直接访问 AR303010(客户付款方式),但在 SQL 从 AR303000(AR 客户)

加入时失败

如果我只是添加到table,那么得到"Unable to insert null into field"

如果我添加到 DAC 中,然后在 DB 中继续获取 Null(仅在扩展 table 上)

所以这可以运行,但肯定看起来不正确。我希望不需要扩展 table 上的 PaymentMethodID,因为在 "CustomerPaymentMethod.cs" 的 DAC 中,它没有用 "IsKey=true" 标记。如果我确实需要它,那么我希望它会作为密钥的一部分自动填充

Table:

Create Table XPMCustomerPaymentMethodExt (
    [CompanyID] [int] NOT NULL DEFAULT ((0)),
    [PMInstanceID] [int] NOT NULL,
    [BAccountID] [int] NOT NULL,
    [PaymentMethodID] [nvarchar](10) NULL,  /* Problem Child, if not here, fails to load customer screen (AR303000) */
    [CanConsolidate] [bit] NULL,
    [DeletedDatabaseRecord] [bit] NOT NULL DEFAULT ((0)),
 CONSTRAINT [PK_XPMCustomerPaymentMethodExt] PRIMARY KEY CLUSTERED 
(
    [CompanyID] ASC,
    [PMInstanceID] ASC
    )
    )

解码器:

[PXTable(IsOptional = true)]
public class XPMCustomerPaymentMethodExt : PXCacheExtension<PX.Objects.AR.CustomerPaymentMethod>
{
    #region CanConsolidate
    public abstract class canConsolidate : PX.Data.IBqlField
    {
    }
    protected bool? _CanConsolidate = false;
    [PXDBBool]
    [PXDefault(false, PersistingCheck = PXPersistingCheck.Nothing)]
    [PXUIField(DisplayName = "Payments may be consolidated")]
    public virtual bool? CanConsolidate
    {
        get
        {
            return _CanConsolidate;
        }
        set
        {
            _CanConsolidate = value;
        }
    }
    #endregion

    #region PaymentMethodID
    public abstract class paymentMethodID : PX.Data.IBqlField
    {
    }
    protected string _PaymentMethodID; // = Base.PaymentMethodID;
    [PXMergeAttributes(Method = MergeMethod.Merge)]
    [PXDBString(10, IsUnicode = true)]
    //[PXDefault(typeof(CustomerPaymentMethod.paymentMethodID), PersistingCheck = PXPersistingCheck.Nothing)]
    //[PXFormula(typeof(Selector<CustomerPaymentMethod.pMInstanceID, CustomerPaymentMethod.paymentMethodID>))]
    public virtual String PaymentMethodID
    {
        get
        {
            //return Base.PaymentMethodID;
            return _PaymentMethodID;
        }
        set
        {
            // Base.PaymentMethodID = value;
            _PaymentMethodID = value;
        }
    }
    #endregion
}

在缓存扩展中通常找不到 PXMergeAttributes。最接近错误消息 "Unable to insert null into field" 的是 PXDefault PXPersistingCheck 验证。

当您在字段上具有此属性时,尝试为该字段保留 null 值将导致类似于您提到的错误:

[PXDefault(PersistingCheck = PXPersistingCheck.Nothing)]

你好像把它注释掉了,但我认为它仍然存在,因为 PXMergeAttributes:

[PXMergeAttributes(Method = MergeMethod.Merge)]
[PXDBString(10, IsUnicode = true)]
//[PXDefault(typeof(CustomerPaymentMethod.paymentMethodID), PersistingCheck = PXPersistingCheck.Nothing)]
//[PXFormula(typeof(Selector<CustomerPaymentMethod.pMInstanceID, CustomerPaymentMethod.paymentMethodID>))]

如果 Base DAC 字段有 PXDefault 并且您添加属性 PXMergeAttributes 那么这会合并 Base DACExtension DAC 属性从而保持Base DACPXDefault 并通过抛出验证错误强制该字段的值永远不为空。