erp-core-backend-v2/src/modules/inventory/entities/stock-quant.entity.ts
Adrian Flores Cortes 6a12ff0844 [TASK-2026-02-05-EJECUCION-REMEDIATION-ERP-CORE] feat: Complete Sprint 0-4 data modeling remediation
Sprint 0: Updated inventories (MASTER/BACKEND/DATABASE) with verified baseline
Sprint 1: Fixed 8 P0 blockers - CFDI entities (schema cfdi→fiscal), auth base DDL,
  billing duplication (→operations), 5 project entities, PaymentInvoiceAllocation,
  core.companies DDL, recreate-database.sh array
Sprint 2: 4 new auth entities, session/role/permission DDL reconciliation,
  CFDI PAC+StampQueue, partner address+contact alignment
Sprint 3: CFDI service+controller+routes, mobile service+controller+routes,
  inventory extended DDL (7 tables)
Sprint 4: timestamp→timestamptz (40 files), field divergences, token/roles/permissions
  service alignment with new DDL-aligned entities

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-05 21:51:55 -06:00

67 lines
1.8 KiB
TypeScript

import {
Entity,
PrimaryGeneratedColumn,
Column,
CreateDateColumn,
UpdateDateColumn,
Index,
ManyToOne,
JoinColumn,
Unique,
} from 'typeorm';
import { Product } from './product.entity.js';
import { Location } from './location.entity.js';
import { Lot } from './lot.entity.js';
@Entity({ schema: 'inventory', name: 'stock_quants' })
@Index('idx_stock_quants_product_id', ['productId'])
@Index('idx_stock_quants_location_id', ['locationId'])
@Index('idx_stock_quants_lot_id', ['lotId'])
@Unique('uq_stock_quants_product_location_lot', ['productId', 'locationId', 'lotId'])
export class StockQuant {
@PrimaryGeneratedColumn('uuid')
id: string;
@Column({ type: 'uuid', nullable: false, name: 'tenant_id' })
tenantId: string;
@Column({ type: 'uuid', nullable: false, name: 'product_id' })
productId: string;
@Column({ type: 'uuid', nullable: false, name: 'location_id' })
locationId: string;
@Column({ type: 'uuid', nullable: true, name: 'lot_id' })
lotId: string | null;
@Column({ type: 'decimal', precision: 16, scale: 4, default: 0 })
quantity: number;
@Column({ type: 'decimal', precision: 16, scale: 4, default: 0, name: 'reserved_quantity' })
reservedQuantity: number;
// Relations
@ManyToOne(() => Product, (product) => product.stockQuants)
@JoinColumn({ name: 'product_id' })
product: Product;
@ManyToOne(() => Location, (location) => location.stockQuants)
@JoinColumn({ name: 'location_id' })
location: Location;
@ManyToOne(() => Lot, (lot) => lot.stockQuants, { nullable: true })
@JoinColumn({ name: 'lot_id' })
lot: Lot | null;
// Auditoría
@CreateDateColumn({ name: 'created_at', type: 'timestamptz' })
createdAt: Date;
@UpdateDateColumn({
name: 'updated_at',
type: 'timestamptz',
nullable: true,
})
updatedAt: Date | null;
}