181 lines
2.5 KiB
JavaScript
181 lines
2.5 KiB
JavaScript
const config = require('../../config');
|
|
const providers = config.providers;
|
|
const crypto = require('crypto');
|
|
const bcrypt = require('bcrypt');
|
|
const moment = require('moment');
|
|
|
|
module.exports = function(sequelize, DataTypes) {
|
|
const storage_locations = sequelize.define(
|
|
'storage_locations',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
code: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
name: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
location_type: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"receiving",
|
|
|
|
|
|
"raw_storage",
|
|
|
|
|
|
"wip",
|
|
|
|
|
|
"finished_goods",
|
|
|
|
|
|
"quarantine",
|
|
|
|
|
|
"shipping",
|
|
|
|
|
|
"scrap"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
storage_locations.associate = (db) => {
|
|
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.storage_locations.hasMany(db.inventory_balances, {
|
|
as: 'inventory_balances_location',
|
|
foreignKey: {
|
|
name: 'locationId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.storage_locations.hasMany(db.inventory_transactions, {
|
|
as: 'inventory_transactions_from_location',
|
|
foreignKey: {
|
|
name: 'from_locationId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.storage_locations.hasMany(db.inventory_transactions, {
|
|
as: 'inventory_transactions_to_location',
|
|
foreignKey: {
|
|
name: 'to_locationId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.storage_locations.hasMany(db.production_material_issues, {
|
|
as: 'production_material_issues_from_location',
|
|
foreignKey: {
|
|
name: 'from_locationId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
db.storage_locations.hasMany(db.production_lots, {
|
|
as: 'production_lots_stored_location',
|
|
foreignKey: {
|
|
name: 'stored_locationId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//end loop
|
|
|
|
|
|
|
|
db.storage_locations.belongsTo(db.warehouses, {
|
|
as: 'warehouse',
|
|
foreignKey: {
|
|
name: 'warehouseId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
db.storage_locations.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.storage_locations.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return storage_locations;
|
|
};
|
|
|
|
|