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';
// 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;
class Floriday {
async start() {

View File

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