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

如何基于所选物料类别重写InventoryCD编号序列生成规则

Acumatica 按物料类别自动生成InventoryCD编号实现方案

问题根因

  • 系统原生InventoryCD的默认值逻辑优先级高于自定义FieldDefaulting事件,且该事件仅在页面首次初始化字段时触发,此时用户还未选择物料类别(ItemClass),无法读取对应类别的编号序列配置
  • 直接在InventoryItemMaint扩展中编写的InventoryCD_FieldDefaulting事件,会被系统自带的自动编号逻辑覆盖,因此不会生效

可行实现方案

方案思路

监听物料类别(ItemClassID)字段更新事件,在用户选定类别后主动拉取对应配置的编号序列,生成下一个编号赋值给InventoryCD,同时屏蔽系统原生自动编号逻辑的冲突。

具体实现步骤

  1. 扩展InventoryItemMaint图形,添加ItemClassID字段的FieldUpdated事件
public class InventoryItemMaintExt : PXGraphExtension<InventoryItemMaint>
{
    protected virtual void InventoryItem_ItemClassID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
    {
        InventoryItem row = e.Row as InventoryItem;
        if (row == null || row.ItemClassID == null) return;
        
        // 读取物料类别配置中对应的编号序列ID,示例为自定义扩展字段UsrNumberingID,可替换为你偏好设置中的对应字段
        ItemClass itemClass = PXSelect<ItemClass, Where<ItemClass.itemClassID, Equal<Required<ItemClass.itemClassID>>>>.Select(Base, row.ItemClassID);
        if (itemClass == null) return;
        var classExt = itemClass.GetExtension<ItemClassExt>();
        if (string.IsNullOrEmpty(classExt.UsrNumberingID)) return;
        
        // 调用编号序列生成下一个编号
        string nextNumber = AutoNumberAttribute.GetNextNumber(cache, row, classExt.UsrNumberingID, DateTime.Now);
        if (!string.IsNullOrEmpty(nextNumber))
        {
            cache.SetValueExt<InventoryItem.inventoryCD>(row, nextNumber);
        }
    }
}
  1. 屏蔽InventoryCD原生默认值逻辑冲突
    通过CacheAttached事件移除原生AutoNumberAttribute,避免系统自动生成的编号覆盖自定义编号:
[PXMergeAttributes(Method = MergeMethod.Merge)]
[PXRemoveBaseAttribute(typeof(AutoNumberAttribute))]
protected virtual void InventoryItem_InventoryCD_CacheAttached(PXCache sender)
{
}
  1. 兼容首次新增场景
    如果需要用户进入新增页面、还未手动选择类别时就提前生成默认编号,可添加RowInserting事件:
protected virtual void InventoryItem_RowInserting(PXCache cache, PXRowInsertingEventArgs e)
{
    InventoryItem row = e.Row as InventoryItem;
    if (row == null || row.ItemClassID == null || !string.IsNullOrEmpty(row.InventoryCD)) return;
    // 复用上述编号生成逻辑即可
}

注意事项

  • 确保你用到的编号序列已在系统**编号序列(CS201010)**页面完成配置,且开启了自动编号
  • 如果编号序列需要按分支/公司区分,调用GetNextNumber方法时传入对应分支参数即可
  • 不要直接修改InventoryID字段的赋值,InventoryID是系统自动生成的主键,仅需操作InventoryCD即可

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.26 13:15:06