QuickBooks актуализирано количество артикул не работи

Опитвам се да актуализирам Item.QtyOnHand чрез IPP .NET SDK за QuickBooks v3.0. Бях избрал

Проследявам наличните количества за този продукт

квадратче за отметка за продукти, които искам да бъдат актуализирани. Но винаги получавам грешка:

Детайл=Грешка при валидиране на бизнеса: Необходим е акаунт за себестойност на продадените стоки в инвентара, ако проследявате количествата в инвентара за този продукт.

Как да актуализирате количеството на ръка? Моят код:

    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"
}

person Maxim Kitsenko    schedule 09.10.2014    source източник


Отговори (1)


Проблемът беше в лоша заявка. За да избегна този вид грешки, добавих 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 );
            }
person Maxim Kitsenko    schedule 10.10.2014