38299-vm/backend/src/db/models/tax_rates.js
2026-02-09 00:26:43 +00:00

144 lines
1.7 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 tax_rates = sequelize.define(
'tax_rates',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
name: {
type: DataTypes.TEXT,
},
rate_percent: {
type: DataTypes.DECIMAL,
},
is_default: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
},
is_active: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
},
importHash: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
},
},
{
timestamps: true,
paranoid: true,
freezeTableName: true,
},
);
tax_rates.associate = (db) => {
/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity
db.tax_rates.hasMany(db.products, {
as: 'products_tax_rate',
foreignKey: {
name: 'tax_rateId',
},
constraints: false,
});
//end loop
db.tax_rates.belongsTo(db.organizations, {
as: 'organization',
foreignKey: {
name: 'organizationId',
},
constraints: false,
});
db.tax_rates.belongsTo(db.users, {
as: 'createdBy',
});
db.tax_rates.belongsTo(db.users, {
as: 'updatedBy',
});
};
return tax_rates;
};