From 146960fa42ad0ccc00527aa740e4e49a3a6f15a5 Mon Sep 17 00:00:00 2001 From: Vitor Date: Wed, 4 Feb 2026 10:45:04 -0300 Subject: [PATCH 1/4] considering tiny product price list --- .../src/integration/after-tiny-queue.ts | 4 +-- .../integration/import-product-from-tiny.ts | 29 +++++++++++++++++-- .../integration/parsers/product-from-tiny.ts | 11 +++++-- 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/packages/apps/tiny-erp/src/integration/after-tiny-queue.ts b/packages/apps/tiny-erp/src/integration/after-tiny-queue.ts index 621770367..be62127f7 100644 --- a/packages/apps/tiny-erp/src/integration/after-tiny-queue.ts +++ b/packages/apps/tiny-erp/src/integration/after-tiny-queue.ts @@ -70,7 +70,7 @@ export default async ( if (!action) { return null; } - let queueList = appData[action][queue]; + let queueList = appData[action] && appData[action][queue]; if (Array.isArray(queueList)) { const idIndex = queueList.indexOf(nextId); if (idIndex > -1) { @@ -81,7 +81,7 @@ export default async ( } const data = { [action]: { - ...appData[action], + ...(appData[action] || {}), [queue]: queueList, }, }; diff --git a/packages/apps/tiny-erp/src/integration/import-product-from-tiny.ts b/packages/apps/tiny-erp/src/integration/import-product-from-tiny.ts index ec3fc487c..1d66a7211 100644 --- a/packages/apps/tiny-erp/src/integration/import-product-from-tiny.ts +++ b/packages/apps/tiny-erp/src/integration/import-product-from-tiny.ts @@ -5,6 +5,28 @@ import updateAppData from '@cloudcommerce/firebase/lib/helpers/update-app-data'; import postTiny from './post-tiny-erp'; import parseProduct from './parsers/product-from-tiny'; +const getPriceListData = async (productId: number) => { + const priceListId = process.env.TINY_PRICE_LIST_ID; + if (!priceListId) return undefined; + + try { + const { registros } = await postTiny('/listas.precos.excecoes.php', { + idListaPreco: Number(priceListId), + idProduto: productId, + }); + if (Array.isArray(registros) && registros.length > 0) { + const registro = registros[0]; + return { + preco: registro.preco, + preco_promocional: registro.preco_promocional, + }; + } + } catch (err) { + logger.warn(`Failed to get price list data for product ${productId}`, err); + } + return undefined; +}; + const importProduct = async ( apiDoc, queueEntry, @@ -100,7 +122,7 @@ const importProduct = async ( if (!tinyProduct) return null; return postTiny('/produto.obter.php', { id: (tinyProduct.id || produtoSaldo.id) }) - .then(({ produto }) => { + .then(async ({ produto }) => { let method; let endpoint; let productId = product && product._id; @@ -113,8 +135,9 @@ const importProduct = async ( } else { return null; } - // @ts-ignore - return parseProduct(produto, tipo, method === 'POST').then((parsedProduct: Products) => { + const priceListData = await getPriceListData(produto.id); + return parseProduct(produto, appData, tipo, method === 'POST', priceListData) + .then((parsedProduct: Products) => { if (!Number.isNaN(quantity)) { parsedProduct.quantity = quantity >= 0 ? quantity : 0; } diff --git a/packages/apps/tiny-erp/src/integration/parsers/product-from-tiny.ts b/packages/apps/tiny-erp/src/integration/parsers/product-from-tiny.ts index 289693650..06c1283c7 100644 --- a/packages/apps/tiny-erp/src/integration/parsers/product-from-tiny.ts +++ b/packages/apps/tiny-erp/src/integration/parsers/product-from-tiny.ts @@ -92,6 +92,7 @@ export default ( appData: Record, tipo?: string, isNew = true, + priceListData?: { preco?: number; preco_promocional?: number }, ): Promise => new Promise((resolve) => { const sku = tinyProduct.codigo || String(tinyProduct.id); const name = (tinyProduct.nome || sku).trim(); @@ -99,14 +100,18 @@ export default ( const fixToNumber = (shouldBeNumber: any) => { return Number(shouldBeNumber) > 0 ? Number(shouldBeNumber) : 0; }; - const price = fixToNumber(tinyProduct.preco_promocional || tinyProduct.precoPromocional) - || fixToNumber(tinyProduct.preco); + const listPrice = priceListData?.preco; + const listPromoPrice = priceListData?.preco_promocional; + const basePrice = fixToNumber(listPrice) || fixToNumber(tinyProduct.preco); + const price = fixToNumber(listPromoPrice) + || fixToNumber(tinyProduct.preco_promocional || tinyProduct.precoPromocional) + || basePrice; const product: ProductSet = { available: tinyProduct.situacao === 'A', sku, name, price, - base_price: fixToNumber(tinyProduct.preco), + base_price: basePrice, body_html: tinyProduct.descricao_complementar || tinyProduct.descricaoComplementar, }; const costPrice = fixToNumber(tinyProduct.preco_custo || tinyProduct.precoCusto); From 94031e46cd134ae059b096a1f8cc646aea41f90b Mon Sep 17 00:00:00 2001 From: Leonardo Matos Date: Fri, 6 Feb 2026 02:32:23 -0300 Subject: [PATCH 2/4] Refactor product import to include price list data --- .../apps/tiny-erp/src/integration/import-product-from-tiny.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/apps/tiny-erp/src/integration/import-product-from-tiny.ts b/packages/apps/tiny-erp/src/integration/import-product-from-tiny.ts index 69c0033e2..8014dc61a 100644 --- a/packages/apps/tiny-erp/src/integration/import-product-from-tiny.ts +++ b/packages/apps/tiny-erp/src/integration/import-product-from-tiny.ts @@ -139,7 +139,8 @@ const importProduct = async ( if (!canCreateNew) { return null; } - return parseProduct(tinyProduct, appData, tipo, true) + return getPriceListData(tinyProduct.id) + .then((priceListData) => parseProduct(tinyProduct, appData, tipo, true, priceListData)) .then((bodyProduct) => { logger.info(`Creating ${queueSku}`, { bodyProduct }); return api.post('products', bodyProduct); From 681f36641a793312cc2aa399e79ff24045089236 Mon Sep 17 00:00:00 2001 From: Leonardo Matos Date: Fri, 6 Feb 2026 02:32:46 -0300 Subject: [PATCH 3/4] Update packages/apps/tiny-erp/src/integration/import-product-from-tiny.ts --- .../apps/tiny-erp/src/integration/import-product-from-tiny.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/apps/tiny-erp/src/integration/import-product-from-tiny.ts b/packages/apps/tiny-erp/src/integration/import-product-from-tiny.ts index 8014dc61a..11cb5b4d6 100644 --- a/packages/apps/tiny-erp/src/integration/import-product-from-tiny.ts +++ b/packages/apps/tiny-erp/src/integration/import-product-from-tiny.ts @@ -8,7 +8,6 @@ import parseProduct from './parsers/product-from-tiny'; const getPriceListData = async (productId: number) => { const priceListId = process.env.TINY_PRICE_LIST_ID; if (!priceListId) return undefined; - try { const { registros } = await postTiny('/listas.precos.excecoes.php', { idListaPreco: Number(priceListId), From 7579a4f28fcafd9e1e06d511d5aac0f1a6d5a5ba Mon Sep 17 00:00:00 2001 From: Leonardo Matos Date: Fri, 6 Feb 2026 02:38:41 -0300 Subject: [PATCH 4/4] Update packages/apps/tiny-erp/src/integration/import-product-from-tiny.ts --- .../apps/tiny-erp/src/integration/import-product-from-tiny.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/apps/tiny-erp/src/integration/import-product-from-tiny.ts b/packages/apps/tiny-erp/src/integration/import-product-from-tiny.ts index 11cb5b4d6..69bebf976 100644 --- a/packages/apps/tiny-erp/src/integration/import-product-from-tiny.ts +++ b/packages/apps/tiny-erp/src/integration/import-product-from-tiny.ts @@ -6,7 +6,7 @@ import postTiny from './post-tiny-erp'; import parseProduct from './parsers/product-from-tiny'; const getPriceListData = async (productId: number) => { - const priceListId = process.env.TINY_PRICE_LIST_ID; + const priceListId = process.env.TINYERP_PRICE_LIST_ID; if (!priceListId) return undefined; try { const { registros } = await postTiny('/listas.precos.excecoes.php', {