import { CreationOptional, DataTypes, InferAttributes, InferCreationAttributes, Model, NonAttribute, Sequelize, } from "sequelize"; import { Invoice_Model } from "./invoice.model"; export type TCreationInvoiceItem_Model = InferCreationAttributes< InvoiceItem_Model, { omit: "invoice" } >; export class InvoiceItem_Model extends Model< InferAttributes, InferCreationAttributes > { static associate(connection: Sequelize) { const { Invoice_Model, InvoiceItem_Model } = connection.models; InvoiceItem_Model.belongsTo(Invoice_Model, { as: "invoice", foreignKey: "invoice_id", onDelete: "CASCADE", }); } declare invoice_id: string; declare item_id: string; declare parent_id: CreationOptional; declare position: number; declare item_type: string; declare description: CreationOptional; declare quantity: CreationOptional; declare unit_price: CreationOptional; declare subtotal: CreationOptional; declare total: CreationOptional; declare invoice?: NonAttribute; } export default (sequelize: Sequelize) => { InvoiceItem_Model.init( { item_id: { type: new DataTypes.UUID(), primaryKey: true, }, invoice_id: { type: new DataTypes.UUID(), primaryKey: true, }, parent_id: { type: new DataTypes.UUID(), allowNull: true, // Puede ser nulo para elementos de nivel superior }, position: { type: new DataTypes.MEDIUMINT(), autoIncrement: false, allowNull: false, }, item_type: { type: new DataTypes.STRING(), allowNull: false, defaultValue: "simple", }, description: { type: new DataTypes.TEXT(), allowNull: true, }, quantity: { type: DataTypes.BIGINT(), allowNull: true, }, unit_price: { type: new DataTypes.BIGINT(), allowNull: true, }, /*tax_slug: { type: new DataTypes.DECIMAL(3, 2), allowNull: true, }, tax_rate: { type: new DataTypes.DECIMAL(3, 2), allowNull: true, }, tax_equalization: { type: new DataTypes.DECIMAL(3, 2), allowNull: true, },*/ subtotal: { type: new DataTypes.BIGINT(), allowNull: true, }, /*tax_amount: { type: new DataTypes.BIGINT(), allowNull: true, },*/ total: { type: new DataTypes.BIGINT(), allowNull: true, }, }, { sequelize, tableName: "invoice_items", }, ); return InvoiceItem_Model; };