Acumatica - SOLine上的项目状态

时间:2018-06-11 17:00:11

标签: c# acumatica

我创建了一个自定义项,将项状态添加到SOLine。图形代码和DAC编译得很好,没有错误。当我检查新的状态字段时,它只是空白。我是这样做的:

首先是DAC:

public class SOLineExt : PXCacheExtension<PX.Objects.SO.SOLine>
  {
    #region ItemStatus
    public abstract class itemStatus : PX.Data.IBqlField
    {
    }
    protected string _ItemStatus;

    [PXString()]
    [PXDefault()]
    [PXUIField(DisplayName = "Status", IsReadOnly = true)]
    public virtual string ItemStatus
    {
      get
      {
        return this._ItemStatus;
      }
      set
      {
        this._ItemStatus = value;
      }
    }
    #endregion
  }

图表:

  public class SOOrderEntryExt : PXGraphExtension<SOOrderEntry>
  {
    #region Event Handlers
protected void SOLine_RowSelecting(PXCache cache, PXRowSelectingEventArgs e,PXRowSelecting InvokeBaseHandler)
    {
if(InvokeBaseHandler != null)
           InvokeBaseHandler(cache, e);
            var row = (SOLine)e.Row;
            if (row == null) return;

                    InventoryItem item = PXSelect<InventoryItem, Where<InventoryItem.inventoryID, Equal<Required<SOLine.inventoryID>>>>.Select(Base, row.InventoryID);
                    if(item != null){
                      SOLineExt soLinesExt = row.GetExtension<SOLineExt>();
                    if (soLinesExt != null){
                       if (item.ItemStatus == 'AC')
                        soLinesExt.ItemStatus = "Active";
                     if (item.ItemStatus == 'NS')
                      soLinesExt.ItemStatus = "No Sales"; 
                      if (item.ItemStatus == 'NP')
                      soLinesExt.ItemStatus = "No Purchases"; 
                      if (item.ItemStatus == 'NR')
                      soLinesExt.ItemStatus = "No Request"; 
                      if (item.ItemStatus == 'IN')
                      soLinesExt.ItemStatus = "Inatctive"; 
                      if (item.ItemStatus == 'DE')
                      soLinesExt.ItemStatus = "Marked for Deletion"; 

                    }  
                    }


    }
    #endregion
  }

我已经使用了类似的方法将其他字段添加到网格上,它只是这个字段,特别是我遇到了麻烦。注意到我确实希望显示完整的状态名称,而不仅仅是两个字符代码。

1 个答案:

答案 0 :(得分:1)

选项#1

您可以使用以下PXDBScalarPXDefault来实现目标。您可以参考为此自定义字段修饰的每个属性的注释。

public class SOLineExt : PXCacheExtension<PX.Objects.SO.SOLine>
{
    #region UsrItemStatus
    public abstract class usrItemStatus : PX.Data.IBqlField
    {
    }
    protected string _UsrItemStatus;

    [PXString()]
    [PXUIField(DisplayName = "Status", IsReadOnly = true)]
    //Sub-Select or Sub Query - required to get value for Saved SO Lines
    [PXDBScalar(typeof(Search<InventoryItem.itemStatus, 
             Where<InventoryItem.inventoryID, Equal<SOLine.inventoryID>>>))]
    //StringList Attribute so that you don’t need to convert value to display text
    [InventoryItemStatus.List]
    //Defaulted when inserting new SO Line
    [PXDefault(typeof(Search<InventoryItem.itemStatus, 
             Where<InventoryItem.inventoryID, Equal<Current<SOLine.inventoryID>>>>),
               PersistingCheck = PXPersistingCheck.Nothing)]
    //Triggering default assignment upon changing Inventory ID in SO Line 
    [PXFormula(typeof(Default<SOLine.inventoryID>))]
    public virtual string UsrItemStatus
    {
        get
        {
            return this._UsrItemStatus;
        }
        set
        {
            this._UsrItemStatus = value;
        }
    }
    #endregion
}

选项#2

在数据视图中包含InventoryItem DAC(在此特定情况下为Transactions),使用Document Details网格。并将InventoryItem__ItemStatus字段添加到Grid。开箱即用的SOOrderEntry Graph实现了Transactions的数据视图委托,因此我们也必须对其进行修改。

public class SOOrderEntryPXDemoExt : PXGraphExtension<SOOrderEntry>
{
    public override void Initialize()
    {
        Base.Transactions.Join<InnerJoin<InventoryItem, On<InventoryItem.inventoryID, Equal<SOLine.inventoryID>>>>();
    }

    [PX.Api.Export.PXOptimizationBehavior(IgnoreBqlDelegate = true)]
    protected virtual IEnumerable transactions()
    {
        PXSelectBase<SOLine> query =
            new PXSelectJoin<SOLine,
                    LeftJoin<INItemCost, On<INItemCost.inventoryID, Equal<SOLine.inventoryID>>,
                    InnerJoin<InventoryItem, On<InventoryItem.inventoryID, Equal<SOLine.inventoryID>>>>,
                    Where<SOLine.orderType, Equal<Current<SOOrder.orderType>>,
                        And<SOLine.orderNbr, Equal<Current<SOOrder.orderNbr>>>>,
                    OrderBy<Asc<SOLine.orderType, Asc<SOLine.orderNbr, Asc<SOLine.lineNbr>>>>>(Base);

        var ret = new List<PXResult<SOLine, INItemCost, InventoryItem>>();
        int startRow = PXView.StartRow;
        int totalRows = 0;
        foreach (PXResult<SOLine, INItemCost, InventoryItem> record in query.View.Select(
            PXView.Currents, PXView.Parameters, PXView.Searches, PXView.SortColumns,
            PXView.Descendings, PXView.Filters, ref startRow, PXView.MaximumRows, ref totalRows))
        {
            SOLine line = (SOLine)record;
            INItemCost itemCost = (INItemCost)record;

            Base.initemcost.StoreCached(new PXCommandKey(new object[] { line.InventoryID }), new List<object> { itemCost });

            ret.Add(record);
        }
        PXView.StartRow = 0;
        return ret;
    }
}

enter image description here