From 38eaa10cb4815c890c8e26cfb381381a8ea8eb41 Mon Sep 17 00:00:00 2001 From: david Date: Wed, 26 Aug 2026 13:19:15 +0200 Subject: [PATCH] Error al duplicar las proformas --- modules/audit/src/web/list/ui/audit-page.tsx | 2 ++ .../payment-term-public-model.mapper.test.ts | 32 +++++++++++++++++++ .../payment-term-public-model.mapper.ts | 2 +- .../models/payment-term-public.model.ts | 6 ++-- .../models/invoice-payment-term-read.model.ts | 7 ++-- .../proforma-full-snapshot-builder.test.ts | 6 +++- 6 files changed, 45 insertions(+), 10 deletions(-) create mode 100644 modules/catalogs/src/api/application/payment-terms/public/mappers/payment-term-public-model.mapper.test.ts diff --git a/modules/audit/src/web/list/ui/audit-page.tsx b/modules/audit/src/web/list/ui/audit-page.tsx index 28245e21..f54854e0 100644 --- a/modules/audit/src/web/list/ui/audit-page.tsx +++ b/modules/audit/src/web/list/ui/audit-page.tsx @@ -47,9 +47,11 @@ export const AuditPage = () => { + {controller.isError && controller.hasUsableData ? ( ) : null} +
diff --git a/modules/catalogs/src/api/application/payment-terms/public/mappers/payment-term-public-model.mapper.test.ts b/modules/catalogs/src/api/application/payment-terms/public/mappers/payment-term-public-model.mapper.test.ts new file mode 100644 index 00000000..c2524948 --- /dev/null +++ b/modules/catalogs/src/api/application/payment-terms/public/mappers/payment-term-public-model.mapper.test.ts @@ -0,0 +1,32 @@ +import assert from "node:assert/strict"; +import test from "node:test"; + +import { PaymentTermPublicModelMapper } from "./payment-term-public-model.mapper"; + +test("serializa los porcentajes de las reglas de vencimiento como DTO", () => { + const mapper = new PaymentTermPublicModelMapper(); + + const result = mapper.toPublicModel({ + id: { toString: () => "payment-term-id" }, + companyId: { toString: () => "company-id" }, + name: { toPrimitive: () => "Al contado" }, + description: { map: () => null }, + isActive: true, + dueRules: { + getAll: () => [ + { + dueDays: { toPrimitive: () => 0 }, + percentage: { + toPrimitive: () => ({ value: 10000, scale: 2 }), + toObjectString: () => ({ value: "10000", scale: "2" }), + }, + }, + ], + }, + } as never); + + assert.deepEqual(result.dueRules[0]?.percentage, { + value: "10000", + scale: "2", + }); +}); diff --git a/modules/catalogs/src/api/application/payment-terms/public/mappers/payment-term-public-model.mapper.ts b/modules/catalogs/src/api/application/payment-terms/public/mappers/payment-term-public-model.mapper.ts index 5b939d00..ad4afc48 100644 --- a/modules/catalogs/src/api/application/payment-terms/public/mappers/payment-term-public-model.mapper.ts +++ b/modules/catalogs/src/api/application/payment-terms/public/mappers/payment-term-public-model.mapper.ts @@ -11,7 +11,7 @@ export class PaymentTermPublicModelMapper { isActive: paymentTerm.isActive, dueRules: paymentTerm.dueRules.getAll().map((rule) => ({ dueDays: String(rule.dueDays.toPrimitive()), - percentage: rule.percentage.toPrimitive(), + percentage: rule.percentage.toObjectString(), })), }; } diff --git a/modules/catalogs/src/api/application/payment-terms/public/models/payment-term-public.model.ts b/modules/catalogs/src/api/application/payment-terms/public/models/payment-term-public.model.ts index 3f1230ed..3575a950 100644 --- a/modules/catalogs/src/api/application/payment-terms/public/models/payment-term-public.model.ts +++ b/modules/catalogs/src/api/application/payment-terms/public/models/payment-term-public.model.ts @@ -1,3 +1,4 @@ +import type { PercentageDTO } from "@erp/core"; import type { UniqueID } from "@repo/rdx-ddd"; import type { Maybe } from "@repo/rdx-utils"; @@ -11,9 +12,6 @@ export interface PaymentTermPublicModel { isActive: boolean; dueRules: Array<{ dueDays: string; - percentage: { - value: string; - scale: number; - }; + percentage: PercentageDTO; }>; } diff --git a/modules/customer-invoices/src/api/application/common/models/invoice-payment-term-read.model.ts b/modules/customer-invoices/src/api/application/common/models/invoice-payment-term-read.model.ts index ca04a3a7..c386be76 100644 --- a/modules/customer-invoices/src/api/application/common/models/invoice-payment-term-read.model.ts +++ b/modules/customer-invoices/src/api/application/common/models/invoice-payment-term-read.model.ts @@ -1,3 +1,5 @@ +import type { PercentageDTO } from "@erp/core"; + /** * Datos del plazo de pago que completan a la proforma. */ @@ -8,9 +10,6 @@ export interface InvoicePaymentTermReadModel { isActive: boolean; dueRules: Array<{ dueDays: string; - percentage: { - value: string; - scale: number; - }; + percentage: PercentageDTO; }>; } diff --git a/modules/customer-invoices/src/api/application/proformas/snapshot-builders/full/proforma-full-snapshot-builder.test.ts b/modules/customer-invoices/src/api/application/proformas/snapshot-builders/full/proforma-full-snapshot-builder.test.ts index aa3f359a..8e686d8a 100644 --- a/modules/customer-invoices/src/api/application/proformas/snapshot-builders/full/proforma-full-snapshot-builder.test.ts +++ b/modules/customer-invoices/src/api/application/proformas/snapshot-builders/full/proforma-full-snapshot-builder.test.ts @@ -76,7 +76,7 @@ test("detail devuelve payment_term enriquecido cuando existe", () => { dueRules: [ { dueDays: "0", - percentage: { value: "5000", scale: 2 }, + percentage: { value: "5000", scale: "2" }, }, ], }), @@ -87,4 +87,8 @@ test("detail devuelve payment_term enriquecido cuando existe", () => { assert.equal(snapshot.payment_term?.name, "50/50"); assert.equal(snapshot.payment_term?.is_active, false); assert.equal(snapshot.payment_term?.due_rules.length, 1); + assert.deepEqual(snapshot.payment_term?.due_rules[0]?.percentage, { + value: "5000", + scale: "2", + }); });