Xero API错误“您不能有多个具有相同LineItemID的订单项。”

时间:2019-03-17 00:47:14

标签: xero-api

我正在尝试XeroNet SDK,并收到以下错误消息:“您不能有多个具有相同LineItemID的订单项。”

这是我正在使用的代码:

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);

我确定这很明显。

1 个答案:

答案 0 :(得分:0)

我相信在构造LineItems时,会使用默认的GUID值public Guid LineItemId { get; set; }实例化LineItem模型,这就是为什么它会重复的原因

当实例化LineItem时,您应该可以解决此问题

lineItems.Add(new LineItem
            {
                LineItemId = Guid.NewGuid(),
                Quantity = rnd.Next(1, 10),
                AccountCode = "200",             
                Description = $"BLAH{i}",
                UnitAmount = (decimal)(rnd.NextDouble() * 100) + 1
            });