Skip to content

Commit 27301f6

Browse files
committed
feat: add option to automatically export orders on ready for shipping only
1 parent 7f5085e commit 27301f6

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

functions/ecom.config.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,16 @@ const app = {
161161
type: 'boolean',
162162
default: false,
163163
title: 'Apenas pedidos aprovados',
164-
description: 'Criar pedido no Bling após aprovação'
164+
description: 'Criar pedido no Tiny após aprovação'
165+
},
166+
hide: true
167+
},
168+
ready_for_shipping_only: {
169+
schema: {
170+
type: 'boolean',
171+
default: false,
172+
title: 'Apenas pedidos prontos para envio',
173+
description: 'Criar pedido no Tiny a partir do status "preparado para envio"'
165174
},
166175
hide: true
167176
},

functions/lib/integration/export-order.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,19 @@ module.exports = ({ appSdk, storeId, auth }, tinyToken, queueEntry, appData, can
6969
return null
7070
}
7171
}
72+
if (appData.ready_for_shipping_only) {
73+
switch (tinyStatus) {
74+
case 'aberto':
75+
case 'cancelado':
76+
case 'aprovado':
77+
case 'preparando_envio':
78+
case 'faturado':
79+
if (!order.fulfillment_status || order.fulfillment_status.current !== 'ready_for_shipping') {
80+
console.log(`#${storeId} ${orderId} skipped with status "${tinyStatus}"`)
81+
return null
82+
}
83+
}
84+
}
7285
const tinyOrder = parseOrder(order, appData, storeId)
7386
console.log(`#${storeId} ${orderId} ${JSON.stringify(tinyOrder)}`)
7487
return tiny.post('/pedido.incluir.php', {
@@ -80,7 +93,6 @@ module.exports = ({ appSdk, storeId, auth }, tinyToken, queueEntry, appData, can
8093
console.log(`#${storeId} ${orderId} found with tiny status ${tinyStatus}`)
8194
}
8295

83-
8496
if (tinyStatus) {
8597
return tiny.post('/pedido.alterar.situacao', {
8698
id: originalTinyOrder.id,

0 commit comments

Comments
 (0)