Last active
May 19, 2017 17:34
-
-
Save wmakeev/f0785d3bfe27b5b5b2fcea05549c6d0f to your computer and use it in GitHub Desktop.
Обновление позиций МойСклад JSON API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function reserveCustomerOrder (orderId) { | |
// получаем заказа | |
let customerorder = await moysklad.GET(['entity/customerorder', orderId], { expand: 'positions' }) | |
// убеждаемся что все позиции загружены, если нет, то подгрузим оставщиеся | |
let positions = await moysklad.loadPositions(customerorder.positions, { limit: 100 }) | |
// ставим позиции в резерв | |
positions.forEach(pos => { | |
pos.reserve = pos.quantity | |
}) | |
// обновляем заказ | |
return await moysklad.POST(['entity/customerorder', orderId], { | |
positions, | |
description: 'Заказ зарезервирован' | |
}) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function reserveCustomerOrder (orderId) { | |
// получаем заказа | |
let customerorder = await moysklad.GET(['entity/customerorder', orderId], { expand: 'positions' }) | |
// убеждаемся что все позиции загружены, если нет, то подгрузим оставщиеся | |
let positions = await moysklad.loadPositions(customerorder.positions, { limit: 100 }) | |
// ставим позиции в резерв | |
positions.forEach(pos => { | |
pos.reserve = pos.quantity | |
}) | |
let patch = { | |
positions, | |
description: 'Заказ зарезервирован' | |
} | |
if (positions.length > 100) { | |
await moysklad.POST(['entity/customerorder', orderId, 'positions'], positions) | |
} else { | |
patch.positions = positions | |
} | |
// обновляем заказ | |
return await moysklad.POST(['entity/customerorder', orderId], patch) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment