refs #4823 Added supplyLinePackingConfiguration
This commit is contained in:
parent
9aaf5a9485
commit
af488b4cd6
|
@ -65,6 +65,7 @@ export default (sequelize) => {
|
||||||
organization, {
|
organization, {
|
||||||
timestamps: false,
|
timestamps: false,
|
||||||
freezeTableName: true,
|
freezeTableName: true,
|
||||||
|
comment: 'Contains suppliers',
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
|
@ -41,7 +41,8 @@ import warehouse from './warehouse/warehouse.js';
|
||||||
|
|
||||||
// Supply Line Models
|
// Supply Line Models
|
||||||
import supplyLine from './supplyLine/supplyLine.js';
|
import supplyLine from './supplyLine/supplyLine.js';
|
||||||
import volumePric from './supplyLine/volumePrice.js';
|
import volumePrice from './supplyLine/volumePrice.js';
|
||||||
|
import supplyLinePackingConfiguration from './supplyLine/packingConfiguration.js';
|
||||||
import clockPresaleSupply from './supplyLine/clockPresaleSupply.js';
|
import clockPresaleSupply from './supplyLine/clockPresaleSupply.js';
|
||||||
|
|
||||||
// TradeItem Models
|
// TradeItem Models
|
||||||
|
@ -71,7 +72,8 @@ let models = {
|
||||||
photo: photo(sequelize),
|
photo: photo(sequelize),
|
||||||
seasonalPeriod: seasonalPeriod(sequelize),
|
seasonalPeriod: seasonalPeriod(sequelize),
|
||||||
supplyLine: supplyLine(sequelize),
|
supplyLine: supplyLine(sequelize),
|
||||||
volumePrice: volumePric(sequelize),
|
supplyLinePackingConfiguration: supplyLinePackingConfiguration(sequelize),
|
||||||
|
volumePrice: volumePrice(sequelize),
|
||||||
clockPresaleSupply: clockPresaleSupply(sequelize),
|
clockPresaleSupply: clockPresaleSupply(sequelize),
|
||||||
package: packageModel(sequelize),
|
package: packageModel(sequelize),
|
||||||
};
|
};
|
||||||
|
@ -134,6 +136,10 @@ try {
|
||||||
foreignKey: 'organizationId',
|
foreignKey: 'organizationId',
|
||||||
targetKey: 'organizationId',
|
targetKey: 'organizationId',
|
||||||
});
|
});
|
||||||
|
models.supplyLinePackingConfiguration.belongsTo(models.supplyLine, {
|
||||||
|
foreignKey: 'supplyLineId',
|
||||||
|
targetKey: 'supplyLineId',
|
||||||
|
});
|
||||||
models.warehouse.belongsTo(models.organization, {
|
models.warehouse.belongsTo(models.organization, {
|
||||||
foreignKey: 'organizationId',
|
foreignKey: 'organizationId',
|
||||||
targetKey: 'organizationId',
|
targetKey: 'organizationId',
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
import { Sequelize } from 'sequelize';
|
||||||
|
|
||||||
|
const packingConfiguration = {
|
||||||
|
packingConfigurationId: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
primaryKey: true,
|
||||||
|
},
|
||||||
|
packageVbnPackageCode: {
|
||||||
|
type: Sequelize.INTEGER,
|
||||||
|
},
|
||||||
|
packageCustomPackageId: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
},
|
||||||
|
piecesPerPackage: {
|
||||||
|
type: Sequelize.INTEGER,
|
||||||
|
},
|
||||||
|
bunchesPerPackage: {
|
||||||
|
type: Sequelize.INTEGER,
|
||||||
|
},
|
||||||
|
photoUrl: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
},
|
||||||
|
packagesPerLayer: {
|
||||||
|
type: Sequelize.INTEGER,
|
||||||
|
},
|
||||||
|
layersPerLoadCarrier: {
|
||||||
|
type: Sequelize.INTEGER,
|
||||||
|
},
|
||||||
|
transportHeightInCm: {
|
||||||
|
type: Sequelize.INTEGER,
|
||||||
|
},
|
||||||
|
loadCarrierType: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
},
|
||||||
|
additionalPricePerPieceCurrency: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
},
|
||||||
|
additionalPricePerPieceValue: {
|
||||||
|
type: Sequelize.INTEGER,
|
||||||
|
},
|
||||||
|
isPrimary: {
|
||||||
|
type: Sequelize.BOOLEAN,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default (sequelize) => {
|
||||||
|
return sequelize.define(
|
||||||
|
'supplyLinePackingConfiguration',
|
||||||
|
packingConfiguration,
|
||||||
|
{
|
||||||
|
timestamps: false,
|
||||||
|
freezeTableName: true,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
|
@ -8,25 +8,19 @@ const supplyLine = {
|
||||||
status: {
|
status: {
|
||||||
type: Sequelize.STRING,
|
type: Sequelize.STRING,
|
||||||
},
|
},
|
||||||
pricePerPiece_currency: {
|
|
||||||
type: Sequelize.STRING,
|
|
||||||
},
|
|
||||||
pricePerPiece_value: {
|
|
||||||
type: Sequelize.DECIMAL(10,2),
|
|
||||||
},
|
|
||||||
numberOfPieces : {
|
numberOfPieces : {
|
||||||
type: Sequelize.INTEGER,
|
type: Sequelize.INTEGER,
|
||||||
},
|
},
|
||||||
deliveryPeriod_startDateTime: {
|
deliveryPeriodStartDateTime: {
|
||||||
type: Sequelize.DATE,
|
type: Sequelize.DATE,
|
||||||
},
|
},
|
||||||
deliveryPeriod_endDateTime: {
|
deliveryPeriodEndDateTime: {
|
||||||
type: Sequelize.DATE,
|
type: Sequelize.DATE,
|
||||||
},
|
},
|
||||||
orderPeriod_startDateTime: {
|
orderPeriodStartDateTime: {
|
||||||
type: Sequelize.DATE,
|
type: Sequelize.DATE,
|
||||||
},
|
},
|
||||||
orderPeriod_endDateTime: {
|
orderPeriodEndDateTime: {
|
||||||
type: Sequelize.DATE,
|
type: Sequelize.DATE,
|
||||||
},
|
},
|
||||||
warehouseId: {
|
warehouseId: {
|
||||||
|
@ -44,10 +38,10 @@ const supplyLine = {
|
||||||
salesUnit: {
|
salesUnit: {
|
||||||
type: Sequelize.STRING,
|
type: Sequelize.STRING,
|
||||||
},
|
},
|
||||||
agreementReference_code: {
|
agreementReferenceCode: {
|
||||||
type: Sequelize.STRING,
|
type: Sequelize.STRING,
|
||||||
},
|
},
|
||||||
agreementReference_description: {
|
agreementReferenceDescription: {
|
||||||
type: Sequelize.STRING,
|
type: Sequelize.STRING,
|
||||||
},
|
},
|
||||||
isLimited: {
|
isLimited: {
|
||||||
|
|
72
utils.js
72
utils.js
|
@ -146,7 +146,7 @@ export async function syncOrganizations(){
|
||||||
const orgs = response.results;
|
const orgs = response.results;
|
||||||
for (let org of orgs) {
|
for (let org of orgs) {
|
||||||
spinner.text = `Syncing ${i} organizations, ${maxSequenceNumber - curSequenceNumber} missing...`
|
spinner.text = `Syncing ${i} organizations, ${maxSequenceNumber - curSequenceNumber} missing...`
|
||||||
if (JSON.parse(env.APPLY_ORG_FILTER) && org.companyGln && !org.endDate) { // Filtro para quitar los que parecen test
|
if (JSON.parse(env.APPLY_ORG_FILTER) && org.companyGln && !org.endDate) { // Filtro
|
||||||
await insertOrganization(org);
|
await insertOrganization(org);
|
||||||
spinner.text = `Syncing ${i++} organizations, ${maxSequenceNumber - curSequenceNumber} missing...`
|
spinner.text = `Syncing ${i++} organizations, ${maxSequenceNumber - curSequenceNumber} missing...`
|
||||||
}
|
}
|
||||||
|
@ -156,7 +156,8 @@ export async function syncOrganizations(){
|
||||||
model: 'organization',
|
model: 'organization',
|
||||||
maxSequenceNumber,
|
maxSequenceNumber,
|
||||||
});
|
});
|
||||||
spinner.text = `Syncing ${i} organizations, 0 missing...`
|
spinner.text = (i) ? `Syncing ${i} organizations...`
|
||||||
|
: `Syncing organizations... (Not found)`
|
||||||
spinner.succeed();
|
spinner.succeed();
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
|
@ -232,7 +233,7 @@ export async function syncTradeItems(){
|
||||||
if (!tradeItems.length) continue;
|
if (!tradeItems.length) continue;
|
||||||
|
|
||||||
for (let tradeItem of tradeItems) {
|
for (let tradeItem of tradeItems) {
|
||||||
await insertItem(tradeItem);
|
await insertTradeItem(tradeItem);
|
||||||
spinner.text = `Syncing ${i++} trade items of [${x}|${orgs.length}] organizations...`
|
spinner.text = `Syncing ${i++} trade items of [${x}|${orgs.length}] organizations...`
|
||||||
};
|
};
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -291,23 +292,11 @@ export async function syncSupplyLines() {
|
||||||
});
|
});
|
||||||
if (!tradeItem) {
|
if (!tradeItem) {
|
||||||
let tradeItem = (await vnRequest('GET', `${env.API_URL}/trade-items/${supplyLine.tradeItemId}`, null, null, spinner)).data;
|
let tradeItem = (await vnRequest('GET', `${env.API_URL}/trade-items/${supplyLine.tradeItemId}`, null, null, spinner)).data;
|
||||||
await insertItem(tradeItem);
|
await insertTradeItem(tradeItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
spinner.text = `Syncing ${i++} supply lines of [${x}|${conOrgs.length}] organizations...`
|
spinner.text = `Syncing ${i++} supply lines of [${x}|${conOrgs.length}] organizations...`
|
||||||
await models.supplyLine.upsert({
|
await insertSupplyLine(supplyLine);
|
||||||
...supplyLine,
|
|
||||||
organizationId: supplyLine.supplierOrganizationId,
|
|
||||||
pricePerPiece_currency: supplyLine.pricePerPiece?.currency ?? null,
|
|
||||||
pricePerPiece_value: supplyLine.pricePerPiece?.value ?? null,
|
|
||||||
deliveryPeriod_startDateTime: supplyLine.deliveryPeriod?.startDateTime ?? null,
|
|
||||||
deliveryPeriod_endDateTime: supplyLine.deliveryPeriod?.endDateTime ?? null,
|
|
||||||
orderPeriod_startDateTime: supplyLine.orderPeriod?.startDateTime ?? null,
|
|
||||||
orderPeriod_endDateTime: supplyLine.orderPeriod?.endDateTime ?? null,
|
|
||||||
agreementReference_code: supplyLine.agreementReference?.code ?? null,
|
|
||||||
agreementReference_description: supplyLine.agreementReference?.description ?? null,
|
|
||||||
lastSync: moment(),
|
|
||||||
});
|
|
||||||
|
|
||||||
for (let volumePrice of supplyLine.volumePrices)
|
for (let volumePrice of supplyLine.volumePrices)
|
||||||
await models.volumePrice.upsert({
|
await models.volumePrice.upsert({
|
||||||
|
@ -362,7 +351,7 @@ export async function syncClockPresalesSupply() {
|
||||||
});
|
});
|
||||||
if (!tradeItem) {
|
if (!tradeItem) {
|
||||||
let tradeItem = (await vnRequest('GET', `${env.API_URL}/trade-items/${clockPresalesSupply.tradeItemId}`, null, null, spinner)).data;
|
let tradeItem = (await vnRequest('GET', `${env.API_URL}/trade-items/${clockPresalesSupply.tradeItemId}`, null, null, spinner)).data;
|
||||||
await insertItem(tradeItem);
|
await insertTradeItem(tradeItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
await insertClockPresalesSupply(clockPresalesSupply);
|
await insertClockPresalesSupply(clockPresalesSupply);
|
||||||
|
@ -381,7 +370,7 @@ export async function syncClockPresalesSupply() {
|
||||||
*
|
*
|
||||||
* @param {Array} tradeItem
|
* @param {Array} tradeItem
|
||||||
*/
|
*/
|
||||||
export async function insertItem(tradeItem) {
|
export async function insertTradeItem(tradeItem) {
|
||||||
const tx = await models.sequelize.transaction();
|
const tx = await models.sequelize.transaction();
|
||||||
try {
|
try {
|
||||||
// Upsert trade item
|
// Upsert trade item
|
||||||
|
@ -506,7 +495,7 @@ export async function insertWarehouse(warehouse) {
|
||||||
location_address_postalCode: warehouse.location.address.postalCode,
|
location_address_postalCode: warehouse.location.address.postalCode,
|
||||||
location_address_stateOrProvince: warehouse.location.address.stateOrProvince,
|
location_address_stateOrProvince: warehouse.location.address.stateOrProvince,
|
||||||
lastSync: moment(),
|
lastSync: moment(),
|
||||||
});
|
}, { transaction: tx });
|
||||||
await tx.commit();
|
await tx.commit();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
|
@ -526,7 +515,48 @@ export async function insertOrganization(organization) {
|
||||||
...organization,
|
...organization,
|
||||||
isConnected: JSON.parse(env.ORGS_ALWAYS_CONN),
|
isConnected: JSON.parse(env.ORGS_ALWAYS_CONN),
|
||||||
lastSync: moment(),
|
lastSync: moment(),
|
||||||
});
|
}, { transaction: tx });
|
||||||
|
await tx.commit();
|
||||||
|
} catch (err) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Insert supply line and dependences in the database.
|
||||||
|
*
|
||||||
|
* @param {Array} supplyLine
|
||||||
|
*/
|
||||||
|
export async function insertSupplyLine(supplyLine) {
|
||||||
|
const tx = await models.sequelize.transaction();
|
||||||
|
try {
|
||||||
|
await models.supplyLine.upsert({
|
||||||
|
...supplyLine,
|
||||||
|
organizationId: supplyLine.supplierOrganizationId,
|
||||||
|
deliveryPeriodStartDateTime: supplyLine.deliveryPeriod?.startDateTime ?? null,
|
||||||
|
deliveryPeriodEndDateTime: supplyLine.deliveryPeriod?.endDateTime ?? null,
|
||||||
|
orderPeriodStartDateTime: supplyLine.orderPeriod?.startDateTime ?? null,
|
||||||
|
orderPeriodEndDateTime: supplyLine.orderPeriod?.endDateTime ?? null,
|
||||||
|
agreementReference_code: supplyLine.agreementReference?.code ?? null,
|
||||||
|
agreementReference_description: supplyLine.agreementReference?.description ?? null,
|
||||||
|
lastSync: moment(),
|
||||||
|
}, { transaction: tx });
|
||||||
|
|
||||||
|
// Upsert packing configurations
|
||||||
|
if (supplyLine.packingConfigurations.length)
|
||||||
|
for (const packingConfiguration of supplyLine.packingConfigurations) {
|
||||||
|
await models.supplyLinePackingConfiguration.upsert({
|
||||||
|
packingConfigurationId: uuidv4(),
|
||||||
|
...packingConfiguration,
|
||||||
|
packageVbnPackageCode: packingConfiguration.package.vbnPackageCode,
|
||||||
|
packageCustomPackageId: packingConfiguration.package.customPackageId,
|
||||||
|
additionalPricePerPieceCurrency: packingConfiguration.additionalPricePerPiece.currency,
|
||||||
|
additionalPricePerPieceValue: packingConfiguration.additionalPricePerPiece.value,
|
||||||
|
supplyLineId: supplyLine.supplyLineId,
|
||||||
|
}, { transaction: tx });
|
||||||
|
}
|
||||||
|
|
||||||
await tx.commit();
|
await tx.commit();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
|
|
Loading…
Reference in New Issue