InventoryItem BasePrice导致“投放无效”

时间:2018-08-10 16:36:21

标签: acumatica

我正在尝试创建一个处理页面,以从几个表中提取数据,这些表将用于更新EDI服务项目列表。我不断收到错误消息,指出为BasePrice指定的强制类型转换无效。

enter image description here

这只是BLC中的内部DAC。数据库中没有物理表。如果我排除BasePrice字段,则一切正常。如果包含它,则插入内容会出错。请参见下面的代码。

public class EDInventoryProcess : PXGraph<EDInventoryProcess>
{
    public PXCancel<EDInventoryFilter> Cancel;
    public PXFilter<EDInventoryFilter> Filter;

    [PXFilterable]

    public PXFilteredProcessingOrderBy<EDInventory, EDInventoryFilter,
        OrderBy<Asc<EDInventory.partnerID, Asc<EDInventory.inventoryCD>>>> EDItem;

    protected virtual IEnumerable eDItem()
    {
        EDItem.Cache.Clear();
        var cmd = new PXSelectJoin<InventoryItem,
            InnerJoin<INItemXRef, On<InventoryItem.inventoryID, Equal<INItemXRef.inventoryID>>,
            InnerJoin<EDPartnerInfo, On<INItemXRef.bAccountID, Equal<EDPartnerInfo.customerID>>>>,
            Where<INItemXRef.alternateType, Equal<INAlternateType.cPN>,
                And<InventoryItem.itemStatus, Equal<InventoryItemStatus.active>>>>(this);
        cmd.View.Clear();
        var ret = cmd.Select();
        if (ret != null)
        {
            EDInventoryFilter filt = (EDInventoryFilter)Filter.Cache.Current;
            EDInventory edInv = new EDInventory();
            foreach (PXResult<InventoryItem, INItemXRef, EDPartnerInfo> record in ret)
            {
                edInv = new EDInventory();
                InventoryItem item = (InventoryItem)record;
                INItemXRef xref = (INItemXRef)record;
                EDPartnerInfo partner = (EDPartnerInfo)record;

                edInv.PartnerID = partner.PartnerID;
                edInv.InventoryID = item.InventoryID;
                edInv.InventoryCD = item.InventoryCD;
                edInv.ItemDescr = item.Descr;
                edInv.ItemStatus = item.ItemStatus;
                edInv.BaseUnit = item.BaseUnit;
                edInv.SalesUnit = item.SalesUnit;
                edInv.PurchaseUnit = item.PurchaseUnit;
                edInv.BasePrice = Convert.ToDecimal(item.BasePrice);

        //This is the lint that generates the error.
                edInv = EDItem.Insert(edInv);

                EDItem.Cache.SetStatus(edInv, PXEntryStatus.Held);
                yield return edInv;
            }
        }
        EDItem.Cache.IsDirty = false;
    }

这是DAC的定义:

    [Serializable]
    public partial class EDInventoryFilter : IBqlTable
    {
        #region TradingPartner
        public abstract class tradingPartner : PX.Data.IBqlField
        {
        }
        protected string _TradingPartner;
        [PXString(15)]
        [PXUIField(DisplayName = "Trading Partner")]
        [PXStringList(new string[] { }, new string[] { })]
        public virtual String TradingPartner { get; set; }
        #endregion 

        #region Action
        public abstract class action : PX.Data.IBqlField { }
        protected string _Action;
        [PXString(15)]
        [PXUIField(DisplayName = "Action")]
        [PXStringList(new string[] { "P" }, new string[] { "Push to EDI" })]
        public virtual String Action { get; set; }
        #endregion
    }

    [Serializable]
    public partial class EDInventory : IBqlTable
    {
        #region PartnerID
        public abstract class partnerID : IBqlField { }
        [PXString(30, IsUnicode = true, IsKey = true)]
        [PXDefault("")]
        [PXUIField(DisplayName = "Partner")]
        public virtual string PartnerID { get; set; }
        #endregion

        #region InventoryID
        public abstract class inventoryID : PX.Data.IBqlField { }
        protected Int32? _InventoryID;
        [PXInt]
        [PXUIField(DisplayName = "Inventory ID", Visibility = PXUIVisibility.Visible, Visible = false)]
        public virtual Int32? InventoryID { get; set; }
        #endregion

        #region InventoryCD
        public abstract class inventoryCD : PX.Data.IBqlField { }
        protected String _InventoryCD;
        [PXDefault()]
        [InventoryRaw(IsKey = true, DisplayName = "Inventory ID")]
        public virtual String InventoryCD { get; set; }
        #endregion

        #region ItemDescr
        public abstract class itemDescr : PX.Data.IBqlField { }
        protected String _ItemDescr;
        [PXString(255, IsUnicode = true)]
        [PXUIField(DisplayName = "Item Description")]
        public virtual String ItemDescr { get; set; }
        #endregion

        #region ItemStatus
        public abstract class itemStatus : PX.Data.IBqlField { }
        protected String _ItemStatus;
        [PXString(2, IsFixed = true)]
        [PXDefault("AC")]
        [PXUIField(DisplayName = "Item Status", Visibility = PXUIVisibility.SelectorVisible)]
        public virtual String ItemStatus { get; set; }
        #endregion

        #region BaseUnit
        public abstract class baseUnit : PX.Data.IBqlField { }
        protected String _BaseUnit;
        [PXString]
        [PXDefault("")]
        [PXUIField(DisplayName = "Base Unit", Visibility = PXUIVisibility.SelectorVisible)]
        public virtual String BaseUnit { get; set; }
        #endregion

        #region SalesUnit
        public abstract class salesUnit : PX.Data.IBqlField { }
        protected String _SalesUnit;
        [PXString]
        [PXDefault("")]
        [PXUIField(DisplayName = "Sales Unit", Visibility = PXUIVisibility.SelectorVisible)]
        public virtual String SalesUnit { get; set; }
        #endregion

        #region PurchaseUnit
        public abstract class purchaseUnit : PX.Data.IBqlField { }
        protected String _PurchaseUnit;
        [PXString]
        [PXDefault("")]
        [PXUIField(DisplayName = "Purchase Unit", Visibility = PXUIVisibility.SelectorVisible)]
        public virtual String PurchaseUnit { get; set; }
        #endregion

        #region BasePrice
        public abstract class basePrice : PX.Data.IBqlField { }
        protected Decimal? _BasePrice;
        [PXPriceCost()]
        [PXDefault(0.0)]
        [PXUIField(DisplayName = "Default Price", Visibility = PXUIVisibility.SelectorVisible)]
        public virtual Decimal? BasePrice { get; set; }
        #endregion
    }

2 个答案:

答案 0 :(得分:0)

我刚刚发现了答案。我将默认值列为

[PXDefault(0.0)]

但是我找到了另一个十进制默认值的引用

[PXDefault(TypeCode.Decimal, "0.0")]

这似乎有效。我不再收到该错误,并且我的处理屏幕按预期显示。我以为默认值是从对象中提取其类型的。

答案 1 :(得分:-1)

为小数字段

是,设置了 [PXDefault(TypeCode.Decimal,“ 0.0”)] 属性,以避免强制转换问题。