0

我正在尝试将产品添加到 QuickBooks,但出现此错误:

错误:

{System.InvalidOperationException: XML 文档 (1, 2) 中存在错误。---> System.InvalidOperationException:不是预期的。在 Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderFaultInfo.Read3_FaultInfo() --- 内部异常堆栈跟踪结束 --- 在 System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events) 在 System.Xml .Serialization.XmlSerializer.Deserialize(TextReader textReader) at Intuit.Ipp.Utility.XmlObjectSerializer.Deserialize[T](String message)}

这是我的代码:

    private Item BuildInventoryItemAddRq(JMAOrderDetail _OrderItem)
    {
        // Make sure we have a SKU value
        if (string.IsNullOrEmpty(_OrderItem.Sku))
        {
            ErrorMessageDataSource.Insert(new ErrorMessage(MessageSeverity.Info, "QBO", "OrderItemId " + _OrderItem.OrderId.ToString() + " has no SKU.  Using default QuickBooks Item Name of 'Unknown Item'"));
            _OrderItem.Sku = "Unknown Item";
        }

        // create the item as an inventoryitem in Quickbooks
        Item QBItem = new Item();
        QBItem.Active = true;
        QBItem.Name = _OrderItem.Sku;
        string _ItemName = IsProductVariantNamed(_OrderItem);
        //if (!string.IsNullOrEmpty(_ItemName))
        //{  // its a variant product
        //    _ItemName += "(" + _ItemName + ")";
        //    if (_OrderItem != null)
        //        QBItem.QtyOnHand = _OrderItem.StockQuantity;
        //    else
        //        QBItem.QtyOnHand = 0;
        //}
        //else
        //{ // regular product
        //    if (_OrderItem != null)
        //        QBItem.QtyOnHand = _OrderItem.StockQuantity;
        //    else
        //        QBItem.QtyOnHand = 0;
        //}

        QBItem.PurchaseDesc = _ItemName;
        //QBItem.SalesDesc = _ItemName;
        QBItem.PurchaseCost = new Money() { Amount = _OrderItem.Product.PurchaseCost };
        //QBItem.SalesPrice = (Double)_OrderItem.UnitPriceExclTax;
        QBItem.IncomeAccountRef = new AccountRef { AccountName = _qboSettings.ItemIncomeAcct };
        QBItem.COGSAccountRef = new AccountRef() { AccountName = _qboSettings.ItemCOGSAcct };
        QBItem.AssetAccountRef = new AccountRef() { AccountName = _qboSettings.ItemAssetAcct };

        try
        {
            Item it = dataServices.Add(QBItem);
            return it;
        }
        catch (Exception ex)
        {
            ErrorMessageDataSource.Insert(new ErrorMessage(MessageSeverity.Error, "QBO", String.Format("Error adding item : {0}", ex.ToString())));
            return new Item();
        }


    }
4

1 回答 1

2

回答问题(来自 Joseph) 指定 QBItem.Type 变量:QBItem.Type = ItemTypeEnum.Inventory; QBItem.TypeSpecified = true;

谢谢贾里德
_

于 2013-03-28T14:20:14.263 回答