108 lines
2.5 KiB
TypeScript
108 lines
2.5 KiB
TypeScript
|
|
import {
|
||
|
|
DataTypes,
|
||
|
|
InferAttributes,
|
||
|
|
InferCreationAttributes,
|
||
|
|
Model,
|
||
|
|
NonAttribute,
|
||
|
|
Sequelize,
|
||
|
|
} from "sequelize";
|
||
|
|
import { CustomerInvoiceItem } from "../../domain";
|
||
|
|
|
||
|
|
export type CustomerInvoiceItemTaxesCreationAttributes = InferCreationAttributes<
|
||
|
|
CustomerInvoiceItemTaxesModel,
|
||
|
|
{}
|
||
|
|
>;
|
||
|
|
|
||
|
|
export class CustomerInvoiceItemTaxesModel extends Model<
|
||
|
|
InferAttributes<CustomerInvoiceItemTaxesModel>,
|
||
|
|
InferCreationAttributes<CustomerInvoiceItemTaxesModel>
|
||
|
|
> {
|
||
|
|
declare id: string;
|
||
|
|
declare item_id: string;
|
||
|
|
|
||
|
|
declare tax_code: string; //"iva_21"
|
||
|
|
|
||
|
|
// Taxable amount (base imponible) // 100,00 €
|
||
|
|
declare taxable_amount_value: number;
|
||
|
|
declare taxable_amount_scale: number;
|
||
|
|
|
||
|
|
// Total tax amount / taxes total // 21,00 €
|
||
|
|
declare tax_amount_value: number;
|
||
|
|
declare tax_amount_scale: number;
|
||
|
|
|
||
|
|
// Relaciones
|
||
|
|
declare item: NonAttribute<CustomerInvoiceItem>;
|
||
|
|
|
||
|
|
static associate(database: Sequelize) {
|
||
|
|
const { CustomerInvoiceItemModel } = database.models;
|
||
|
|
|
||
|
|
CustomerInvoiceItemTaxesModel.belongsTo(CustomerInvoiceItemModel, {
|
||
|
|
as: "item",
|
||
|
|
targetKey: "id",
|
||
|
|
foreignKey: "item_id",
|
||
|
|
onDelete: "CASCADE",
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
static hooks(database: Sequelize) {}
|
||
|
|
}
|
||
|
|
|
||
|
|
export default (database: Sequelize) => {
|
||
|
|
CustomerInvoiceItemTaxesModel.init(
|
||
|
|
{
|
||
|
|
id: {
|
||
|
|
type: new DataTypes.UUID(),
|
||
|
|
primaryKey: true,
|
||
|
|
},
|
||
|
|
|
||
|
|
item_id: {
|
||
|
|
type: DataTypes.UUID,
|
||
|
|
allowNull: false,
|
||
|
|
},
|
||
|
|
|
||
|
|
tax_code: {
|
||
|
|
type: new DataTypes.STRING(),
|
||
|
|
allowNull: false,
|
||
|
|
},
|
||
|
|
|
||
|
|
taxable_amount_value: {
|
||
|
|
type: new DataTypes.BIGINT(), // importante: evita problemas de precisión con valores grandes
|
||
|
|
allowNull: true,
|
||
|
|
defaultValue: null,
|
||
|
|
},
|
||
|
|
taxable_amount_scale: {
|
||
|
|
type: new DataTypes.SMALLINT(),
|
||
|
|
allowNull: false,
|
||
|
|
defaultValue: 2,
|
||
|
|
},
|
||
|
|
|
||
|
|
tax_amount_value: {
|
||
|
|
type: new DataTypes.BIGINT(), // importante: evita problemas de precisión con valores grandes
|
||
|
|
allowNull: true,
|
||
|
|
defaultValue: null,
|
||
|
|
},
|
||
|
|
tax_amount_scale: {
|
||
|
|
type: new DataTypes.SMALLINT(),
|
||
|
|
allowNull: false,
|
||
|
|
defaultValue: 2,
|
||
|
|
},
|
||
|
|
},
|
||
|
|
{
|
||
|
|
sequelize: database,
|
||
|
|
tableName: "customer_invoices_item_taxes",
|
||
|
|
|
||
|
|
underscored: true,
|
||
|
|
|
||
|
|
indexes: [{ name: "tax_code_idx", fields: ["tax_code"], unique: false }],
|
||
|
|
|
||
|
|
whereMergeStrategy: "and", // <- cómo tratar el merge de un scope
|
||
|
|
|
||
|
|
defaultScope: {},
|
||
|
|
|
||
|
|
scopes: {},
|
||
|
|
}
|
||
|
|
);
|
||
|
|
|
||
|
|
return CustomerInvoiceItemTaxesModel;
|
||
|
|
};
|