You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Acumatica项目中CustomerOrOrganizationInNoUpdateDocRestrictor无法访问问题

问题解决:无法访问CustomerOrOrganizationInNoUpdateDocRestrictor属性

错误原因

CustomerOrOrganizationInNoUpdateDocRestrictor是Acumatica中PX.Objects.SO程序集的**内部访问级别(internal)**成员,只有SO模块自身的代码能直接调用,你的自定义项目属于外部程序集,哪怕添加了AR引用也无法访问该属性,这就是编译报错CS0122的根本原因。

解决方法

方法一:自定义限制器属性复刻原逻辑

你可以自己实现一个功能完全一致的自定义属性,复刻原属性的限制逻辑。以下是示例代码:

首先创建自定义限制器:

public class CustomCustomerInNoUpdateDocRestrictor : PXRestrictorAttribute
{
    public CustomCustomerInNoUpdateDocRestrictor()
        : base(typeof(Where<Current<NXBOL.status>.IsNotIn<NXBOLStatus.open, NXBOLStatus.hold>>),
              PXMessages.Localize("无法修改客户,当前单据状态不允许编辑"))
    {
    }

    public override void FieldVerifying(PXCache cache, PXFieldVerifyingEventArgs e)
    {
        base.FieldVerifying(cache, e);
        NXBOL currentDoc = e.Row as NXBOL;
        if (currentDoc == null) return;

        // 复刻原属性核心逻辑:检查是否存在关联的已完成发货单(可根据业务调整)
        bool hasCompletedShipments = PXSelectReadonly<NXBOLShipment,
            Where<NXBOLShipment.bOLNbr, Equal<Current<NXBOL.bOLNbr>>,
                And<NXBOLShipment.status, Equal<NXBOLShipmentStatus.completed>>>>
            .Select(cache.Graph).Any();

        if (hasCompletedShipments)
        {
            throw new PXSetPropertyException(PXMessages.LocalizeFormatNoPrefix("无法修改客户,单据已关联完成的发货单: {0}", currentDoc.BOLNbr));
        }
    }
}

然后替换DAC字段上的属性:

#region CustomerID
public abstract class customerID : BqlInt.Field<customerID>
{
    // 保留你原有的内部类代码
}
protected Int32? _CustomerID;
[CustomerActive(
    typeof(Search<BAccountR.bAccountID, Where<True, Equal<True>>>), // TODO: remove fake Where after AC-101187
    Visibility = PXUIVisibility.SelectorVisible, Required = true)]
[CustomCustomerInNoUpdateDocRestrictor] // 替换为自定义属性
[PXForeignReference(typeof(Field<NXBOL.customerID>.IsRelatedTo<BAccount.bAccountID>))]
public virtual Int32? CustomerID
{
    get => _CustomerID;
    set => _CustomerID = value;
}
#endregion

方法二:用PXUIEnabled动态控制字段可编辑状态

如果不需要完全复刻复杂逻辑,仅需在单据不可编辑时灰掉CustomerID字段,可以直接使用PXUIEnabled属性:

[CustomerActive(/*...现有配置...*/)]
[PXUIEnabled(typeof(Where<Current<NXBOL.status>.IsIn<NXBOLStatus.open, NXBOLStatus.hold>>))]
[PXForeignReference(/*...现有配置...*/)]
public virtual Int32? CustomerID { /*...现有代码...*/ }

这种方式会根据单据状态自动控制字段是否可编辑,简单直接,能满足大部分场景需求。

补充说明

如果需要完全匹配SO模块中CustomerOrOrganizationInNoUpdateDocRestrictor的行为,可以通过反编译工具查看该属性的内部实现,将其中的业务逻辑完全复制到自定义属性中,确保限制规则和原属性一致。

内容的提问来源于stack exchange,提问作者KDub97

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 01:58:25