【问题标题】:How can I specify Product/Service for an Invoice Line Item for QBO IPP .NET SDK V3?如何为 QBO IPP .NET SDK V3 的发票行项目指定产品/服务?
【发布时间】:2013-10-30 21:25:15
【问题描述】:

我正在尝试为要导入 QuickBooks Online (QBO) 公司文件的发票的发票行项目指定产品/服务列表项目,但出现错误。

我收到的错误是:

Intuit.Ipp.Exception.IdsException: InternalServerError ---> Intuit.Ipp.Exception.EndpointNotFoundException: Ids service endpoint was not found.

这个例外没有进一步说明我所做的是否有效。

我的单元测试方法:

    [TestMethod()]
    public void CreateTest()
    {
        Entities.Invoice invoice = new Entities.Invoice();
        invoice.ReferenceId = Guid.NewGuid().ToString("N").Substring(0, 10);
        invoice.CreatedDate = DateTime.Now;
        invoice.CustomerId = 1;
        invoice.LineItems.Add(new InvoiceLine() { ItemName = "Initial Funding", Description = "Initial Funding", Amount = 5500 });
        invoice.LineItems.Add(new InvoiceLine() { ItemName = "Lien Fee", Description = "Lien Fee", Amount = 100 });


        IPPRestProfile restProfile = new IPPRestProfile(realmId, accessToken, accessTokenSecret, Intuit.Ipp.Core.IntuitServicesType.QBO, consumerKey, consumerSecret);
        IPP.Invoices target = new IPP.Invoices(restProfile);
        Intuit.Ipp.Data.Invoice actual = target.Create(invoice);

        if (actual != null)
        {
            Console.WriteLine("QB Invoice ID: {0}", actual.Id);
            Console.WriteLine("QB Sync Token: {0}", actual.SyncToken);
            Console.WriteLine("================================================");
            ObjectDumper.Write(actual, 4);
        }
    }

单元测试调用的方法:

        public Intuit.Ipp.Data.Invoice Create(Entities.Invoice invoice)
    {
        // Check pre-conditions
        if (invoice == null) { throw new ArgumentException("Invoice object is required.", "invoice"); }

        var qboInvoice = new Intuit.Ipp.Data.Invoice();
        BuildInvoiceEntity(qboInvoice, invoice);

        return _Service.Add(qboInvoice) as Intuit.Ipp.Data.Invoice;
    }

最后是生成发票方法:

    private void BuildInvoiceEntity(Intuit.Ipp.Data.Invoice qboInvoice, Entities.Invoice invoice)
    {
        if (qboInvoice != null && invoice != null)
        {
            IQuickBooksHeader header = invoice as IQuickBooksHeader;

            if (String.IsNullOrEmpty(header.Id))
            {
                qboInvoice.DocNumber = invoice.ReferenceId;
                qboInvoice.TxnDate = invoice.CreatedDate;
                qboInvoice.TxnDateSpecified = true;

                // Customer
                qboInvoice.CustomerRef = new ReferenceType()
                {
                    type = objectNameEnumType.Customer.ToString(),
                    Value = invoice.CustomerId.ToString()
                };

                // AR Account
                qboInvoice.ARAccountRef = new ReferenceType()
                {
                    type = objectNameEnumType.Account.ToString(),
                    name = "Accounts Receivable"
                };
            }

            if (invoice.LineItems.Count > 0)
            {
                Intuit.Ipp.Data.Line[] invoiceLineCollection = new Intuit.Ipp.Data.Line[invoice.LineItems.Count];
                for (int i = 0; i < invoice.LineItems.Count; i++)
                {
                    var line = invoice.LineItems[i];
                    var qboInvoiceLine = new Intuit.Ipp.Data.Line()
                    {
                        Amount = line.Amount,
                        AmountSpecified = true,
                        Description = line.Description,
                        DetailType = LineDetailTypeEnum.SalesItemLineDetail,
                        DetailTypeSpecified = true,
                        AnyIntuitObject = new SalesItemLineDetail()
                        {
                            ItemRef = new ReferenceType()
                            {
                                name = line.ItemName,
                            },
                            ItemElementName = ItemChoiceType.UnitPrice,
                            AnyIntuitObject = line.Amount
                        }
                    };
                    invoiceLineCollection[i] = qboInvoiceLine;
                }
                qboInvoice.Line = invoiceLineCollection;
            }
        }
    }

如果我从构建方法中删除这段代码:

      ItemRef = new ReferenceType()
      {
          name = line.ItemName,
      },

发票已成功添加发票行项目的产品/服务的默认“服务”列表项。

IPP .NET SDK V3 的在线文档对于为 ReferenceType 指定什么内容含糊不清。只指定列表项的名称有什么问题?如果我尝试为发票行项目指定产品/服务列表项的方式有误,那么正确的方法是什么?

【问题讨论】:

    标签: c# intuit-partner-platform quickbooks-online


    【解决方案1】:

    经过几天的研究,我从来没有找到答案,说明为什么我不能像我想要的那样使用这个名称,尽管它在指定 AccountRef 时是这样工作的。但我跑题了,这是我的解决方案:

    // Hold a collection of QBO items
    private ReadOnlyCollection<Item> _Items;
    
    // I set the collection in the constructor only once
    public Invoices(Entities.IPPRestProfile restProfile)
    {
        if (restProfile == null)
            throw new ArgumentException("IPPRestProfile object is required.", "restProfile");
    
        OAuthRequestValidator oAuthValidator = new OAuthRequestValidator(restProfile.OAuthAccessToken, restProfile.OAuthAccessTokenSecret,
                restProfile.ConsumerKey, restProfile.ConsumerSecret);
        ServiceContext context = new ServiceContext(restProfile.RealmId, restProfile.DataSource, oAuthValidator);
        _Service = new DataService(context);
        _Items = (new QueryService<Item>(context)).ExecuteIdsQuery("SELECT * FROM Item", QueryOperationType.query);
    }
    

    每当我创建发票时,我都会按名称查询集合中的项目 ID:

    private void BuildInvoiceEntity(Intuit.Ipp.Data.Invoice qboInvoice, Entities.Invoice invoice)
    {
        ...
        // Get the Id value of the item by name
        string itemTypeId = _Items.Where(o => o.Name == line.ItemName).FirstOrDefault().Id;
    
        // Specify the Id value in the item reference of the SalesItemLineDetail
        var qboInvoiceLine = new Intuit.Ipp.Data.Line()
        {
            Amount = (decimal)amount,
            AmountSpecified = true,
            Description = line.Description,
            DetailType = LineDetailTypeEnum.SalesItemLineDetail,
            DetailTypeSpecified = true,
            AnyIntuitObject = new SalesItemLineDetail()
            {
                ItemRef = new ReferenceType() { Value = itemTypeId },
                AnyIntuitObject = (decimal)line.Rate,
                ItemElementName = ItemChoiceType.UnitPrice
            }
        };
        ...
    }
    

    希望这有助于为某人指明正确的方向,找到可能更好的解决方案。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多