refs #4823 Added new supplyLineClockPresale models
This commit is contained in:
parent
aab13f1294
commit
fa34a22c02
|
@ -44,6 +44,8 @@ import supplyLine from './supplyLine/supplyLine.js';
|
||||||
import volumePrice from './supplyLine/volumePrice.js';
|
import volumePrice from './supplyLine/volumePrice.js';
|
||||||
import supplyLinePackingConfiguration from './supplyLine/packingConfiguration.js';
|
import supplyLinePackingConfiguration from './supplyLine/packingConfiguration.js';
|
||||||
import clockPresaleSupply from './supplyLine/clockPresaleSupply.js';
|
import clockPresaleSupply from './supplyLine/clockPresaleSupply.js';
|
||||||
|
import clockPresaleSupplyPackingConfiguration from './supplyLine/clockPresaleSupplyPackingConfiguration.js';
|
||||||
|
import clockPresaleSupplyPackage from './supplyLine/clockPresaleSupplyPackage.js';
|
||||||
|
|
||||||
// TradeItem Models
|
// TradeItem Models
|
||||||
import tradeItem from './tradeItem/tradeItem.js';
|
import tradeItem from './tradeItem/tradeItem.js';
|
||||||
|
@ -54,7 +56,6 @@ import packingConfiguration from './tradeItem/packingConfiguration.js';
|
||||||
import photo from './tradeItem/photo.js';
|
import photo from './tradeItem/photo.js';
|
||||||
import seasonalPeriod from './tradeItem/seasonalPeriod.js';
|
import seasonalPeriod from './tradeItem/seasonalPeriod.js';
|
||||||
import characteristic from './tradeItem/characteristic.js';
|
import characteristic from './tradeItem/characteristic.js';
|
||||||
import { start } from 'repl';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains all the models that are related to the application.
|
* Contains all the models that are related to the application.
|
||||||
|
@ -75,6 +76,8 @@ let models = {
|
||||||
seasonalPeriod: seasonalPeriod(sequelize),
|
seasonalPeriod: seasonalPeriod(sequelize),
|
||||||
supplyLine: supplyLine(sequelize),
|
supplyLine: supplyLine(sequelize),
|
||||||
supplyLinePackingConfiguration: supplyLinePackingConfiguration(sequelize),
|
supplyLinePackingConfiguration: supplyLinePackingConfiguration(sequelize),
|
||||||
|
clockPresaleSupplyPackingConfiguration: clockPresaleSupplyPackingConfiguration(sequelize),
|
||||||
|
clockPresaleSupplyPackage: clockPresaleSupplyPackage(sequelize),
|
||||||
volumePrice: volumePrice(sequelize),
|
volumePrice: volumePrice(sequelize),
|
||||||
clockPresaleSupply: clockPresaleSupply(sequelize),
|
clockPresaleSupply: clockPresaleSupply(sequelize),
|
||||||
package: packageModel(sequelize),
|
package: packageModel(sequelize),
|
||||||
|
|
|
@ -23,9 +23,6 @@ const clockPresaleSupply = {
|
||||||
numberOfPieces: {
|
numberOfPieces: {
|
||||||
type: Sequelize.INTEGER,
|
type: Sequelize.INTEGER,
|
||||||
},
|
},
|
||||||
packingConfigurations: {
|
|
||||||
type: Sequelize.JSON,
|
|
||||||
},
|
|
||||||
tradePeriod_startDateTime: {
|
tradePeriod_startDateTime: {
|
||||||
type: Sequelize.DATE,
|
type: Sequelize.DATE,
|
||||||
},
|
},
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
import { Sequelize } from 'sequelize';
|
||||||
|
|
||||||
|
const clockPresaleSupplyPackage = {
|
||||||
|
packingConfigurationId: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
primaryKey: true,
|
||||||
|
},
|
||||||
|
vbnPackageCode: {
|
||||||
|
type: Sequelize.INTEGER,
|
||||||
|
primaryKey: true,
|
||||||
|
},
|
||||||
|
customPackageId: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default (sequelize) => {
|
||||||
|
return sequelize.define(
|
||||||
|
'supplyLineClockPresaleSupplyPackage',
|
||||||
|
clockPresaleSupplyPackage,
|
||||||
|
{
|
||||||
|
timestamps: false,
|
||||||
|
freezeTableName: true,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
|
@ -0,0 +1,45 @@
|
||||||
|
import { Sequelize } from 'sequelize';
|
||||||
|
|
||||||
|
const supplyLineClockPresaleSupplyPackingConfiguration = {
|
||||||
|
clockPresaleSupplyPackingConfigurationId: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
primaryKey: true,
|
||||||
|
},
|
||||||
|
piecesPerPackage: {
|
||||||
|
type: Sequelize.INTEGER,
|
||||||
|
},
|
||||||
|
bunchesPerPackage: {
|
||||||
|
type: Sequelize.INTEGER,
|
||||||
|
},
|
||||||
|
packagesPerLayer: {
|
||||||
|
type: Sequelize.INTEGER,
|
||||||
|
},
|
||||||
|
layersPerLoadCarrier: {
|
||||||
|
type: Sequelize.INTEGER,
|
||||||
|
},
|
||||||
|
loadCarrier: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
},
|
||||||
|
additionalPricePerPieceCurrency: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
},
|
||||||
|
additionalPricePerPieceValue: {
|
||||||
|
type: Sequelize.INTEGER,
|
||||||
|
},
|
||||||
|
photoUrl: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
},
|
||||||
|
supplyLineClockPresaleSupplyId: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default (sequelize) => {
|
||||||
|
return sequelize.define(
|
||||||
|
'supplyLineClockPresaleSupplyPackingConfiguration',
|
||||||
|
supplyLineClockPresaleSupplyPackingConfiguration, {
|
||||||
|
timestamps: false,
|
||||||
|
freezeTableName: true,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
64
utils.js
64
utils.js
|
@ -252,7 +252,11 @@ export async function insertSequenceNumber(model, sequenceNumber) {
|
||||||
export async function insertTradeItems(tradeItems) {
|
export async function insertTradeItems(tradeItems) {
|
||||||
const tx = await models.sequelize.transaction();
|
const tx = await models.sequelize.transaction();
|
||||||
try {
|
try {
|
||||||
const tradeItemsData = tradeItems.map((tradeItem) => ({
|
let filteredTradeItems = [];
|
||||||
|
for (let tradeItem of tradeItems)
|
||||||
|
if (!tradeItem.isDeleted) filteredTradeItems.push(tradeItem);
|
||||||
|
|
||||||
|
const tradeItemsData = filteredTradeItems.map((tradeItem) => ({
|
||||||
...tradeItem,
|
...tradeItem,
|
||||||
organizationId: tradeItem.supplierOrganizationId,
|
organizationId: tradeItem.supplierOrganizationId,
|
||||||
lastSync: moment().format('YYYY-MM-DD HH:mm:ss'),
|
lastSync: moment().format('YYYY-MM-DD HH:mm:ss'),
|
||||||
|
@ -402,7 +406,11 @@ export async function insertTradeItems(tradeItems) {
|
||||||
export async function insertClockPresalesSupply(clockPresalesSupply) {
|
export async function insertClockPresalesSupply(clockPresalesSupply) {
|
||||||
const tx = await models.sequelize.transaction();
|
const tx = await models.sequelize.transaction();
|
||||||
try {
|
try {
|
||||||
const clockPresalesSupplyWithDefaults = clockPresalesSupply.map((clockPresaleSupply) => ({
|
let filteredclockPresalesSupply = [];
|
||||||
|
for (let clockPresaleSupply of clockPresalesSupply)
|
||||||
|
if (!(clockPresaleSupply.status === 'UNAVAILABLE')) filteredclockPresalesSupply.push(clockPresaleSupply);
|
||||||
|
|
||||||
|
const clockPresalesSupplyWithDefaults = filteredclockPresalesSupply.map((clockPresaleSupply) => ({
|
||||||
...clockPresaleSupply,
|
...clockPresaleSupply,
|
||||||
pricePerPiece_currency: clockPresaleSupply.pricePerPiece.currency,
|
pricePerPiece_currency: clockPresaleSupply.pricePerPiece.currency,
|
||||||
pricePerPiece_value: clockPresaleSupply.pricePerPiece.value,
|
pricePerPiece_value: clockPresaleSupply.pricePerPiece.value,
|
||||||
|
@ -418,7 +426,6 @@ export async function insertClockPresalesSupply(clockPresalesSupply) {
|
||||||
'pricePerPiece_value',
|
'pricePerPiece_value',
|
||||||
'deliveryNoteReference',
|
'deliveryNoteReference',
|
||||||
'numberOfPieces',
|
'numberOfPieces',
|
||||||
'packingConfigurations',
|
|
||||||
'tradePeriod_startDateTime',
|
'tradePeriod_startDateTime',
|
||||||
'tradePeriod_endDateTime',
|
'tradePeriod_endDateTime',
|
||||||
'organizationId',
|
'organizationId',
|
||||||
|
@ -431,6 +438,45 @@ export async function insertClockPresalesSupply(clockPresalesSupply) {
|
||||||
transaction: tx,
|
transaction: tx,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let packingConfigurations = [];
|
||||||
|
|
||||||
|
for (const clockPresale of clockPresalesSupplyWithDefaults) {
|
||||||
|
if (clockPresale.packingConfigurations?.length) {
|
||||||
|
for (const packingConfiguration of clockPresale.packingConfigurations) {
|
||||||
|
const uuid = uuidv4();
|
||||||
|
|
||||||
|
packingConfigurations.push({
|
||||||
|
clockPresaleSupplyPackingConfigurationId: uuid,
|
||||||
|
...packingConfiguration,
|
||||||
|
additionalPricePerPieceCurrency: packingConfiguration.additionalPricePerPiece?.currency,
|
||||||
|
additionalPricePerPieceValue: packingConfiguration.additionalPricePerPiece?.value,
|
||||||
|
supplyLineClockPresaleSupplyId: clockPresale.supplyLineId,
|
||||||
|
});
|
||||||
|
|
||||||
|
models.clockPresaleSupplyPackage.upsert({
|
||||||
|
...packingConfiguration.package,
|
||||||
|
packingConfigurationId: uuid,
|
||||||
|
}, { transaction: tx });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (packingConfigurations?.length)
|
||||||
|
await models.clockPresaleSupplyPackingConfiguration.bulkCreate(packingConfigurations, {
|
||||||
|
updateOnDuplicate: [
|
||||||
|
'clockPresaleSupplyPackingConfigurationId',
|
||||||
|
'piecesPerPackage',
|
||||||
|
'bunchesPerPackage',
|
||||||
|
'packagesPerLayer',
|
||||||
|
'layersPerLoadCarrier',
|
||||||
|
'loadCarrier',
|
||||||
|
'additionalPricePerPieceCurrency',
|
||||||
|
'additionalPricePerPieceValue',
|
||||||
|
'photoUrl',
|
||||||
|
],
|
||||||
|
transaction: tx,
|
||||||
|
});
|
||||||
|
|
||||||
await tx.commit();
|
await tx.commit();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
|
@ -446,7 +492,11 @@ export async function insertClockPresalesSupply(clockPresalesSupply) {
|
||||||
export async function insertWarehouses(warehouses) {
|
export async function insertWarehouses(warehouses) {
|
||||||
const tx = await models.sequelize.transaction();
|
const tx = await models.sequelize.transaction();
|
||||||
try {
|
try {
|
||||||
const warehousesWithDefaults = warehouses.map((warehouse) => ({
|
let filteredWarehouses = [];
|
||||||
|
for (let warehouse of warehouses)
|
||||||
|
if (!warehouse.isDeleted) filteredWarehouses.push(warehouse);
|
||||||
|
|
||||||
|
const warehousesWithDefaults = filteredWarehouses.map((warehouse) => ({
|
||||||
...warehouse,
|
...warehouse,
|
||||||
location_gln: warehouse.location.gln,
|
location_gln: warehouse.location.gln,
|
||||||
location_address_addressLine: warehouse.location.address.addressLine,
|
location_address_addressLine: warehouse.location.address.addressLine,
|
||||||
|
@ -564,7 +614,11 @@ export async function insertOrganizations(organizations) {
|
||||||
export async function insertSupplyLines(supplyLines) {
|
export async function insertSupplyLines(supplyLines) {
|
||||||
const tx = await models.sequelize.transaction();
|
const tx = await models.sequelize.transaction();
|
||||||
try {
|
try {
|
||||||
const supplyLinesData = supplyLines.map((supplyLine) => ({
|
let filteredSupplyLines = [];
|
||||||
|
for (let supplyLine of supplyLines)
|
||||||
|
if (!supplyLine.isDeleted) filteredSupplyLines.push(supplyLine);
|
||||||
|
|
||||||
|
const supplyLinesData = filteredSupplyLines.map((supplyLine) => ({
|
||||||
...supplyLine,
|
...supplyLine,
|
||||||
organizationId: supplyLine.supplierOrganizationId,
|
organizationId: supplyLine.supplierOrganizationId,
|
||||||
deliveryPeriodStartDateTime: supplyLine.deliveryPeriod?.startDateTime ?? null,
|
deliveryPeriodStartDateTime: supplyLine.deliveryPeriod?.startDateTime ?? null,
|
||||||
|
|
Loading…
Reference in New Issue