Skip to content

Commit

Permalink
fix(create-order-erp): update field obs_pedido
Browse files Browse the repository at this point in the history
  • Loading branch information
wisley7l committed Jun 14, 2024
1 parent ee2a489 commit 43e3e9b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
5 changes: 3 additions & 2 deletions functions/lib/cron-events-horus.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,10 @@ module.exports = async (appSdk) => {
} = appData
const horus = new Horus(username, password, baseURL)
const opts = { appData }
const horusApiOk = await checkHorusApi(horus)
const isHorusApiOk = await checkHorusApi(horus)
const promises = []
if (horusApiOk) {
console.log('>> Horus API ok: ', isHorusApiOk)
if (isHorusApiOk) {
promises.push(productsStocksEvents(horus, storeId, opts))
const now = new Date()

Expand Down
12 changes: 6 additions & 6 deletions functions/lib/integration/exports/orders-to-horus.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,19 @@ module.exports = async ({ appSdk, storeId, auth }, orderId, opts = {}) => {

if (!orderHorus) {
console.log('> amount: ', JSON.stringify(amount))
let obsOrder = ''
// Requirement requested by store 51504 (ministerio ler)
if (customer.corporate_name && storeId === 51504) {
obsOrder = `| ${customer.corporate_name}`
}

const body = {
COD_PEDIDO_ORIGEM: orderId,
COD_EMPRESA: companyCode,
COD_FILIAL: subsidiaryCode,
TIPO_PEDIDO_V_T_D: 'V', // Informar o tipo do pedido, neste caso usar a letra V para VENDA,
COD_CLI: customerCodeHorus, // Código do Cliente - Parâmetro obrigatório!
OBS_PEDIDO: `Pedido #${number} id: ${orderId}`, // Observações do pedido, texto usado para conteúdo variável e livre - Parâmetro opcional!
OBS_PEDIDO: `Pedido #${number} id: ${orderId} ${obsOrder}`, // Observações do pedido, texto usado para conteúdo variável e livre - Parâmetro opcional!
COD_TRANSP: getCodeDelivery(shippingApp, appData.delivery), // Código da Transportadora responsável pela entrega do pedido - Parâmetro obrigatório!
COD_METODO: saleCode, // Código do Método de Venda usado neste pedido para classificação no ERP HORUS - Parâmetro obrigatório.
COD_TPO_END: addressCustomerHorus.COD_TPO_END, // Código do Tipo de endereço do cliente, usado para entrega da mercadoria - Parâmetro obrigatório!
Expand All @@ -150,11 +155,6 @@ module.exports = async ({ appSdk, storeId, auth }, orderId, opts = {}) => {
NOM_RESP: appData.orders?.responsible?.name || 'ecomplus'
}

// Requirement requested by store 51504 (ministerio ler)
if (customer.corporate_name && storeId === 51504) {
body.DADOS_ADICIONAIS_NF = customer.corporate_name
}

console.log('>> body ', JSON.stringify(body))

if (order.status === 'cancelled') {
Expand Down
7 changes: 4 additions & 3 deletions functions/lib/pub-sub/exec-queue-pub-sub.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const replayPubSub = async (_appSdk) => {
const doc = listPubSubs.docs[i]
const docRef = doc.ref
const { eventName, json } = doc.data()
let isSendMessage = true
let isHorusApiOk = true
if (json?.opts?.appData) {
const {
exportation,
Expand All @@ -38,14 +38,15 @@ const replayPubSub = async (_appSdk) => {
if (username && password && baseURL) {
console.log('Queue Pub/Sub => check Horus Api')
const horus = new Horus(username, password, baseURL)
isSendMessage = await checkHorusApi(horus)
isHorusApiOk = await checkHorusApi(horus)
}
}
const run = async () => {
await docRef.delete()
return sendMessageTopic(eventName, json)
}
if (isSendMessage) {
console.log('>> Horus API ok: ', isHorusApiOk)
if (isHorusApiOk) {
promises.push(run())
}

Expand Down

0 comments on commit 43e3e9b

Please sign in to comment.