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

如何确保Acumatica两个物料向导屏幕的生产数量均默认设为1.00?

解决方案:设置Acumatica Material Wizard 1和2的默认数量为1.00

问题背景

需求:将Material Wizard 1(AM300010)屏幕的默认生产数量设为1.00,将Material Wizard 2(AM300020)屏幕的需求数量设为1.00。
已实现:通过扩展MatlWizard1图,实现选中物料时生产数量默认1.00,但选中记录发送到Material Wizard 2时,数量仍沿用原有逻辑,需确保两个屏幕数量均默认1.00。

已实现的MatlWizard1代码

namespace PX.Objects.AM
{
  public class MatlWizard1_Extension : PXGraphExtension<PX.Objects.AM.MatlWizard1>
  {
    #region Event Handlers

    protected void AMProdItem_Selected_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e, PXFieldUpdated baseHandler)
    {
      baseHandler?.Invoke(cache, e);
      var row = (AMProdItem)e.Row;
      if (row.Selected == true) // Only if the item is selected
      {
          row.QtytoProd = 1.0000m;
      }
    }
  }
}

实现MatlWizard2默认数量的方案

要让Material Wizard 2的需求数量默认设为1.00,需要扩展MatlWizard2图,针对对应的字段设置默认值。通常Material Wizard 2中处理的是物料需求,对应表为AMProdMatl,需求数量字段为QtyReq。可以通过以下两种方式实现:

方式1:字段默认值事件(FieldDefaulting)

在MatlWizard2的扩展中,为AMProdMatl.QtyReq添加FieldDefaulting事件处理,设置默认值为1.00:

namespace PX.Objects.AM
{
  public class MatlWizard2_Extension : PXGraphExtension<PX.Objects.AM.MatlWizard2>
  {
    #region Event Handlers

    protected void AMProdMatl_QtyReq_FieldDefaulting(PXCache cache, PXFieldDefaultingEventArgs e)
    {
      var row = (AMProdMatl)e.Row;
      // 设置需求数量默认值为1.00
      e.NewValue = 1.0000m;
    }
  }
}

方式2:处理从MatlWizard1传递过来的数据

如果需要确保从MatlWizard1选中的记录传递到MatlWizard2时数量保持1.00,可以在MatlWizard2的初始化或数据加载事件中修正数量:

namespace PX.Objects.AM
{
  public class MatlWizard2_Extension : PXGraphExtension<PX.Objects.AM.MatlWizard2>
  {
    public override void Initialize()
    {
      base.Initialize();
      Base.ProdMatl.Cache.Attached += ProdMatl_Cache_Attached;
    }

    private void ProdMatl_Cache_Attached(PXCache sender)
    {
      sender.RowInserting += ProdMatl_RowInserting;
    }

    protected void ProdMatl_RowInserting(PXCache cache, PXRowInsertingEventArgs e)
    {
      var row = (AMProdMatl)e.Row;
      if (row != null)
      {
        // 强制设置需求数量为1.00
        row.QtyReq = 1.0000m;
        cache.SetValueExt<AMProdMatl.qtyReq>(row, 1.0000m);
      }
    }
  }
}

验证步骤

  • 部署两个扩展代码到Acumatica环境
  • 打开Material Wizard 1(AM300010),选中物料,确认生产数量默认1.00
  • 点击发送到Material Wizard 2,进入AM300020屏幕,检查需求数量是否为1.00
  • 直接打开Material Wizard 2新增记录,确认需求数量默认值为1.00

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.16 02:34:52