115 lines
2.7 KiB
TypeScript
115 lines
2.7 KiB
TypeScript
|
|
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<InvoiceItem_Model, { omit: "invoice" }>,
|
||
|
|
InferCreationAttributes<InvoiceItem_Model, { omit: "invoice" }>
|
||
|
|
> {
|
||
|
|
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<string>;
|
||
|
|
declare position: number;
|
||
|
|
declare item_type: string;
|
||
|
|
declare description: CreationOptional<string>;
|
||
|
|
declare quantity: CreationOptional<number>;
|
||
|
|
declare unit_price: CreationOptional<number>;
|
||
|
|
declare subtotal: CreationOptional<number>;
|
||
|
|
declare total: CreationOptional<number>;
|
||
|
|
|
||
|
|
declare invoice?: NonAttribute<Invoice_Model>;
|
||
|
|
}
|
||
|
|
|
||
|
|
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;
|
||
|
|
};
|