refs #4823 Changes

This commit is contained in:
Guillermo Bonet 2023-05-08 14:55:18 +02:00
parent 168f97275b
commit a7bc5a807c
2 changed files with 7 additions and 18 deletions

View File

@ -4,7 +4,7 @@ import moment from 'moment';
import chalk from 'chalk'; import chalk from 'chalk';
// Añade la hora a todos los console.log // Añade la hora a todos los console.log
// console.log = (...args) => console.info(`${new moment().format('HH:mm:ss')} -`, ...args); // console.log = (...args) => console.info(`[${new moment().format('YYYY-MM-DD hh:mm:ss A')}]`, ...args);
const env = process.env; const env = process.env;
class Floriday { class Floriday {
async start() { async start() {

View File

@ -406,7 +406,6 @@ export async function syncTradeItems(){
const spinner = ora(`Syncing trade items...`).start(); const spinner = ora(`Syncing trade items...`).start();
const suppliers = await models.supplier.findAll(); const suppliers = await models.supplier.findAll();
let i = 1; let i = 1;
let x = 1;
for (let supplier of suppliers) { for (let supplier of suppliers) {
if (!supplier.isConnected) continue; if (!supplier.isConnected) continue;
@ -429,16 +428,11 @@ export async function syncTradeItems(){
for (let tradeItem of tradeItems) { for (let tradeItem of tradeItems) {
await insertItem(tradeItem, supplier); await insertItem(tradeItem, supplier);
spinner.text = `Syncing ${x++} suppliers` spinner.text = `Syncing ${i++} trade items...`
}; };
} catch (err) {
console.log('Synced trade items for: ', supplier.commercialName);
console.log('Remaining suppliers: ', suppliers.length - i++, 'of', suppliers.length);
console.log('Total trade items: ', tradeItems.length);
} catch (error) {
spinner.fail(); spinner.fail();
console.log('Error while syncing trade items for: ', supplier.commercialName); throw err;
console.log(error);
} }
} }
spinner.succeed() spinner.succeed()
@ -610,13 +604,7 @@ export async function syncSupplyLines(){
} }
export async function insertItem(tradeItem, supplier) { export async function insertItem(tradeItem, supplier) {
let tx = await models.sequelize.transaction();
console.log('Syncing trade item: ', tradeItem.name);
try { try {
// Temporal connection to all suppliers that have trade items // Temporal connection to all suppliers that have trade items
let currentSupp = await models.supplier.findOne({ let currentSupp = await models.supplier.findOne({
@ -627,6 +615,7 @@ export async function insertItem(tradeItem, supplier) {
currentSupp.isConnected = true; currentSupp.isConnected = true;
let tx = await models.sequelize.transaction();
await currentSupp.save({transaction: tx}); await currentSupp.save({transaction: tx});
await models.connection.upsert({ await models.connection.upsert({
@ -673,7 +662,7 @@ export async function insertItem(tradeItem, supplier) {
let photos = tradeItem.photos; let photos = tradeItem.photos;
for (let photo of photos) { for (let photo of photos)
await models.photo.upsert({ await models.photo.upsert({
id: photo.id, id: photo.id,
url: photo.url, url: photo.url,
@ -681,7 +670,6 @@ export async function insertItem(tradeItem, supplier) {
primary: photo.primary, primary: photo.primary,
tradeItemFk: tradeItem.tradeItemId, tradeItemFk: tradeItem.tradeItemId,
}, {transaction: tx}); }, {transaction: tx});
}
let packingConfigurations = tradeItem.packingConfigurations; let packingConfigurations = tradeItem.packingConfigurations;
@ -702,6 +690,7 @@ export async function insertItem(tradeItem, supplier) {
isPrimary: packingConfiguration.isPrimary, isPrimary: packingConfiguration.isPrimary,
tradeItemFk: tradeItem.tradeItemId, tradeItemFk: tradeItem.tradeItemId,
}, {transaction: tx}); }, {transaction: tx});
await models.package.upsert({ await models.package.upsert({
vbnPackageCode: packingConfiguration.package.vbnPackageCode, vbnPackageCode: packingConfiguration.package.vbnPackageCode,
customPackageId: packingConfiguration.package.customPackageId, customPackageId: packingConfiguration.package.customPackageId,