Uecko_ERP/apps/server/src/contexts/customer-billing/infraestructure/sequelize/customer-invoice-item.model.ts

101 lines
2.5 KiB
TypeScript
Raw Normal View History

2025-02-24 19:00:28 +00:00
import {
CreationOptional,
DataTypes,
InferAttributes,
InferCreationAttributes,
Model,
NonAttribute,
Sequelize,
} from "sequelize";
import { CustomerInvoiceModel } from "./customer-invoice.model";
export type CustomerInvoiceItemCreationAttributes = InferCreationAttributes<
CustomerInvoiceItemModel,
{ omit: "invoice" }
>;
export class CustomerInvoiceItemModel extends Model<
InferAttributes<CustomerInvoiceItemModel, { omit: "invoice" }>,
InferCreationAttributes<CustomerInvoiceItemModel, { omit: "invoice" }>
> {
static associate(connection: Sequelize) {
const { CustomerInvoiceModel, CustomerInvoiceItemModel } = connection.models;
CustomerInvoiceItemModel.belongsTo(CustomerInvoiceModel, {
as: "invoice",
foreignKey: "invoice_id",
onDelete: "CASCADE",
});
}
declare invoice_id: string;
declare item_id: string;
declare id_article: CreationOptional<number | null>;
declare position: number;
declare description: CreationOptional<string | null>;
declare quantity: CreationOptional<number | null>;
declare unit_price: CreationOptional<number | null>;
declare subtotal_price: CreationOptional<number | null>;
declare discount: CreationOptional<number | null>;
declare total_price: CreationOptional<number | null>;
declare invoice: NonAttribute<CustomerInvoiceModel>;
}
export default (sequelize: Sequelize) => {
CustomerInvoiceItemModel.init(
{
item_id: {
type: new DataTypes.UUID(),
primaryKey: true,
},
invoice_id: {
type: new DataTypes.UUID(),
primaryKey: true,
},
id_article: {
type: DataTypes.BIGINT().UNSIGNED,
allowNull: true,
},
position: {
type: new DataTypes.MEDIUMINT(),
autoIncrement: false,
allowNull: false,
},
description: {
type: new DataTypes.TEXT(),
allowNull: true,
},
quantity: {
type: DataTypes.BIGINT(),
allowNull: true,
},
unit_price: {
type: new DataTypes.BIGINT(),
allowNull: true,
},
subtotal_price: {
type: new DataTypes.BIGINT(),
allowNull: true,
},
discount: {
type: new DataTypes.SMALLINT(),
allowNull: true,
},
total_price: {
type: new DataTypes.BIGINT(),
allowNull: true,
},
},
{
sequelize,
tableName: "invoice_items",
timestamps: false,
indexes: [],
}
);
return CustomerInvoiceItemModel;
};