188 lines
2.4 KiB
JavaScript
188 lines
2.4 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 material_allocations = sequelize.define(
|
|
'material_allocations',
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
|
|
required_qty: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
issued_qty: {
|
|
type: DataTypes.DECIMAL,
|
|
|
|
|
|
|
|
},
|
|
|
|
uom: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
issue_status: {
|
|
type: DataTypes.ENUM,
|
|
|
|
|
|
|
|
values: [
|
|
|
|
"not_issued",
|
|
|
|
|
|
"partially_issued",
|
|
|
|
|
|
"issued",
|
|
|
|
|
|
"backflushed"
|
|
|
|
],
|
|
|
|
},
|
|
|
|
notes: {
|
|
type: DataTypes.TEXT,
|
|
|
|
|
|
|
|
},
|
|
|
|
importHash: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true,
|
|
unique: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
paranoid: true,
|
|
freezeTableName: true,
|
|
},
|
|
);
|
|
|
|
material_allocations.associate = (db) => {
|
|
|
|
|
|
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//end loop
|
|
|
|
|
|
|
|
db.material_allocations.belongsTo(db.production_orders, {
|
|
as: 'production_order',
|
|
foreignKey: {
|
|
name: 'production_orderId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.material_allocations.belongsTo(db.materials, {
|
|
as: 'component_material',
|
|
foreignKey: {
|
|
name: 'component_materialId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.material_allocations.belongsTo(db.lots, {
|
|
as: 'lot',
|
|
foreignKey: {
|
|
name: 'lotId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.material_allocations.belongsTo(db.locations, {
|
|
as: 'from_location',
|
|
foreignKey: {
|
|
name: 'from_locationId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
db.material_allocations.belongsTo(db.organizations, {
|
|
as: 'organizations',
|
|
foreignKey: {
|
|
name: 'organizationsId',
|
|
},
|
|
constraints: false,
|
|
});
|
|
|
|
|
|
|
|
|
|
db.material_allocations.belongsTo(db.users, {
|
|
as: 'createdBy',
|
|
});
|
|
|
|
db.material_allocations.belongsTo(db.users, {
|
|
as: 'updatedBy',
|
|
});
|
|
};
|
|
|
|
|
|
|
|
return material_allocations;
|
|
};
|
|
|
|
|