从代码中添加非库存库存项目

时间:2015-05-04 02:53:52

标签: acumatica

我试图从代码中添加一个库存项目,但是当我保留该行时,我当前收到错误。

来源:PX.Data 目标站点:布尔MoveNext() Stack Trace:at System.Collections.Generic.Dictionary 2.FindEntry(TKey key) at System.Collections.Generic.Dictionary 2.TryGetValue(TKey key,TValue&amp; value)    at PX.Objects.IN.INUnitSelect 7.INUnit_RowPersisted(PXCache sender, PXRowPersistedEventArgs e) at PX.Data.PXCache.OnRowPersisted(Object item, PXDBOperation operation, PXTranStatus tranStatus, Exception exception) at PX.Data.PXCache 1.Persisted(Boolean isAborted,Exception exception)    在PX.Data.PXGraph.Persist()    在PX.Data.PXSave 1.<Handler>d__4.MoveNext() at PX.Data.PXAction 1.d__c.MoveNext()    在PX.Data.PXAction`1.d__c.MoveNext()    在PX.Data.PXActionCollection.PressSave(PXAction调用者)    在PX.Data.PXActionCollection.PressSave()

这是我的代码

    PX.Objects.IN.NonStockItemMaint graph = new PX.Objects.IN.NonStockItemMaint();

        graph.Clear(PXClearOption.ClearAll);

        graph.Item.Current = item;

        item.InventoryCD = "RP" + product._id;
        item.Descr = product.product_name;

        item.ItemClassID = "REXPRODUCT";

        item.BaseUnit = "PC";
        item.SalesUnit = "PC";
        item.PurchaseUnit = "PC";

        item.ItemStatus = "AC";

        item.TaxCategoryID = "TAXABLE";
        item.ItemType = "N";
        item.PostClassID = "DEFAULT";
        item.PriceClassID = "INPRICE001";
        item.MarkupPct = 0;
        item.MinGrossProfitPct = 0;

        item.BasePrice = (decimal) product.price_inc_tax;
        item.RecPrice = (decimal)product.price_inc_tax;

        item.PreferredVendorID = vend.ID;
        item.PreferredVendorLocationID = vend.DefLocationID;

        if (insert)
        {
            item = graph.Item.Insert(item);
        }
        else
        {
            item = graph.Item.Update(item);
        }

        graph.Actions.PressSave();

1 个答案:

答案 0 :(得分:0)

明白了。我执行了graph.Item.Insert(item),然后设置了itemclass。

           private PX.Objects.IN.InventoryItem UpdateProduct(ProviderProduct product, PX.Objects.IN.InventoryItem item, PX.Objects.AP.VendorR vend, bool insert = true)
    {

        PX.Objects.PO.POVendorInventory vendInv = null;

        PX.Objects.IN.NonStockItemMaint graph = new PX.Objects.IN.NonStockItemMaint();

        graph.Clear(PXClearOption.ClearAll);

        graph.Item.Current = item;

        item.InventoryCD = "RP" + product._id;
        item.Descr = product.product_name;

        item.ItemStatus = "AC";

        item.TaxCategoryID = "INCLUSIVE";
        item.ItemType = "N";
        item.PostClassID = "DEFAULT";
        item.ValMethod = "T";

        item.BasePrice = (decimal)(product.price_inc_tax ?? 0);
        item.RecPrice = (decimal)(product.price_inc_tax ?? 0);

        if (insert)
        {
            item = graph.Item.Insert(item);

            vendInv = new PX.Objects.PO.POVendorInventory();
        }
        else
        {
            item = graph.Item.Update(item);
        }

        item.ItemClassID = "REXPRODUCT";

        graph.Item.Update(item);

        if (vendInv != null)
        {
            graph.VendorItems.Current = vendInv;

            vendInv.IsDefault = true;
            vendInv.VendorID = vend.ID;
            vendInv.VendorLocationID = vend.DefLocationID;
            vendInv.Active = true;

            graph.VendorItems.Insert(vendInv);
        }

        graph.Actions.PressSave();

        return item;
    }