Xero API 错误"You cannot have multiple line items with the same LineItemID."



我正在尝试Xeronet SDK,并且正在遇到此错误:

这是我正在使用的代码:

var lineItems = new List<LineItem>();
var rnd = new Random();
var count = rnd.Next(1, 20);
var date = DateTime.UtcNow.AddDays(-rnd.Next(1, 600)).Date;
Console.WriteLine($"Adding {count} line items");
for (var i = 0; i < count; i++)
{
  lineItems.Add(new LineItem
  {
    Quantity = rnd.Next(1, 10),
    AccountCode = "200",
    Description = $"BLAH{i}",
    UnitAmount = (decimal)(rnd.NextDouble() * 100) + 1
  });
}
var invoice = new Invoice
{
  Contact = new Contact { Name = "Foo" },
  Type = Heads(rnd) ? InvoiceType.AccountsPayable : InvoiceType.AccountsReceivable,
  Date = date,
  DueDate = date.AddDays(90),
  LineAmountTypes = Heads(rnd) ? LineAmountType.Inclusive : LineAmountType.Exclusive,
  LineItems = lineItems
};
var response = private_app_api.Create(invoice);

我敢肯定这是显而易见的。

我相信,当您构造lineItems时,LineItem模型正在使用默认的GUID值public Guid LineItemId { get; set; }实例化,这就是为什么它被复制

实例化lineItem

时,您应该能够解决此问题。
lineItems.Add(new LineItem
            {
                LineItemId = Guid.NewGuid(),
                Quantity = rnd.Next(1, 10),
                AccountCode = "200",             
                Description = $"BLAH{i}",
                UnitAmount = (decimal)(rnd.NextDouble() * 100) + 1
            });

相关内容

  • 没有找到相关文章

最新更新