我正在尝试通过适用于QuickBooks v3.0的IPP .NET SDK更新Item.QtyOnHand
。
我选择了
我跟踪此产品的现有数量
复选框,用于我想要更新的产品。但我总是得到一个错误:
详细信息=业务验证错误:销售的库存成本 如果您要跟踪此库存数量,则需要帐户 产品
如何更新手头的数量? 我的代码:
var oauthValidator = new OAuthRequestValidator(RestProfile.OAuthAccessToken, RestProfile.OAuthAccessTokenSecret, this.ConsumerProfile.ConsumerKey, this.ConsumerProfile.ConsumerSecret);
var serviceContext = new ServiceContext(this.RestProfile.AppToken, this.RestProfile.CompanyId, IntuitServicesType.QBO, oauthValidator);
var dataService = new DataService( serviceContext );
var queryService = new QueryService<Item>( serviceContext );
var items = queryService.Where(x=>x.Type == ItemTypeEnum.Inventory).ToList();
var batch = dataService.CreateNewBatch();
foreach( var item in items )
{
batch.Add(new Item()
{
Name = item.Name,
Id = item.Id,
QtyOnHand = item.QtyOnHand+1,
QtyOnHandSpecified = true
}, item.Id, OperationEnum.update);
}
batch.Execute();
我总是收到这个错误:
{
"BatchItemResponse" : [{
"Fault" : {
"Error" : [{
"Message" : "A business validation error has occurred while processing your request",
"Detail" : "Business Validation Error: An inventory cost-of-goods-sold account is required if you are tracking inventory quantities for this product.",
"code" : "6000",
"element" : ""
}
],
"type" : "ValidationFault"
},
"bId" : "20"
}, {
"Fault" : {
"Error" : [{
"Message" : "A business validation error has occurred while processing your request",
"Detail" : "Business Validation Error: An inventory cost-of-goods-sold account is required if you are tracking inventory quantities for this product.",
"code" : "6000",
"element" : ""
}
],
"type" : "ValidationFault"
},
"bId" : "23"
}, {
"Fault" : {
"Error" : [{
"Message" : "A business validation error has occurred while processing your request",
"Detail" : "Business Validation Error: An inventory cost-of-goods-sold account is required if you are tracking inventory quantities for this product.",
"code" : "6000",
"element" : ""
}
],
"type" : "ValidationFault"
},
"bId" : "21"
}, {
"Fault" : {
"Error" : [{
"Message" : "A business validation error has occurred while processing your request",
"Detail" : "Business Validation Error: An inventory cost-of-goods-sold account is required if you are tracking inventory quantities for this product.",
"code" : "6000",
"element" : ""
}
],
"type" : "ValidationFault"
},
"bId" : "22"
}
],
"time" : "2014-10-09T12:42:48.715-07:00"
}
答案 0 :(得分:0)
问题是糟糕的要求。为了避免这些错误,我添加了AccountRef来请求。例如:
var accReference = accounts["Cost of Goods Sold"];
var expenseAccountRef = new ReferenceType { type = accReference.AccountType.ToString(), name = accReference.Name, Value = accReference.Id };
foreach( var item in items )
{
batch.Add( new Item()
{
Name = item.Name,
Id = item.Id,
SyncToken = item.SyncToken,
QtyOnHand = item.QtyOnHand + 1,
QtyOnHandSpecified = true,
ExpenseAccountRef = expenseAccountRef,
}, item.Id, OperationEnum.update );
}