feat: normalize percentage.value to string in resolvePaymentTerm method
This commit is contained in:
parent
cf7ce088f8
commit
595e08459d
@ -2,7 +2,7 @@ import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
|
||||
import { DiscountPercentage } from "@erp/core/api";
|
||||
import { UniqueID } from "@repo/rdx-ddd";
|
||||
import { CurrencyCode, LanguageCode, UniqueID, UtcDate } from "@repo/rdx-ddd";
|
||||
import { Maybe, Result } from "@repo/rdx-utils";
|
||||
|
||||
import { ProformaToIssuedInvoiceConverter } from "./proforma-to-issued-invoice-props-converter";
|
||||
@ -68,3 +68,89 @@ test("toCreateProps no materializa VerifactuRecord ni policy en el converter", (
|
||||
assert.equal(result.isSuccess, true);
|
||||
assert.equal(result.data.verifactu.isNone(), true);
|
||||
});
|
||||
|
||||
test("resolvePaymentTerm normaliza percentage.value cuando llega numérico del catálogo", () => {
|
||||
const converter = new ProformaToIssuedInvoiceConverter();
|
||||
const companyId = UniqueID.generateNewID();
|
||||
const paymentTermId = UniqueID.generateNewID();
|
||||
const invoiceDateResult = UtcDate.createFromISO("2026-08-20");
|
||||
const languageCodeResult = LanguageCode.create("es");
|
||||
const currencyCodeResult = CurrencyCode.create("EUR");
|
||||
const discountResult = DiscountPercentage.create({ value: 0 });
|
||||
|
||||
assert.equal(invoiceDateResult.isSuccess, true);
|
||||
assert.equal(languageCodeResult.isSuccess, true);
|
||||
assert.equal(currencyCodeResult.isSuccess, true);
|
||||
assert.equal(discountResult.isSuccess, true);
|
||||
|
||||
const result = converter["resolvePaymentTerm"]({
|
||||
proforma: {
|
||||
companyId,
|
||||
id: UniqueID.generateNewID(),
|
||||
targetInvoiceSeriesCode: Maybe.none(),
|
||||
operationDate: Maybe.some(invoiceDateResult.data),
|
||||
description: {
|
||||
unwrap: () => "Servicio mensual",
|
||||
},
|
||||
languageCode: languageCodeResult.data,
|
||||
currencyCode: currencyCodeResult.data,
|
||||
notes: Maybe.none(),
|
||||
reference: Maybe.none(),
|
||||
customerId: UniqueID.generateNewID(),
|
||||
totals: () => ({
|
||||
subtotalAmount: {} as never,
|
||||
itemsDiscountAmount: {} as never,
|
||||
globalDiscountAmount: {} as never,
|
||||
totalDiscountAmount: {} as never,
|
||||
taxableAmount: {} as never,
|
||||
ivaAmount: {} as never,
|
||||
recAmount: {} as never,
|
||||
retentionAmount: {} as never,
|
||||
taxesAmount: {} as never,
|
||||
totalAmount: {} as never,
|
||||
}),
|
||||
globalDiscountPercentage: discountResult.data,
|
||||
} as never,
|
||||
paymentMethod: {
|
||||
id: UniqueID.generateNewID(),
|
||||
name: "Transferencia",
|
||||
description: Maybe.none(),
|
||||
},
|
||||
paymentTerm: Maybe.some({
|
||||
id: paymentTermId.toPrimitive(),
|
||||
name: "30 días",
|
||||
description: "Pago estándar",
|
||||
isActive: true,
|
||||
dueRules: [
|
||||
{
|
||||
dueDays: "30",
|
||||
percentage: {
|
||||
value: 10000,
|
||||
scale: 2,
|
||||
},
|
||||
},
|
||||
],
|
||||
} as never),
|
||||
taxRegime: {
|
||||
code: "01",
|
||||
description: "Régimen general",
|
||||
},
|
||||
fiscalClassification: {
|
||||
operationQualificationCode: null,
|
||||
exemptionReasonCode: null,
|
||||
},
|
||||
usesVerifactu: false,
|
||||
});
|
||||
|
||||
assert.equal(result.isSuccess, true);
|
||||
assert.equal(result.data.isSome(), true);
|
||||
assert.deepEqual(result.data.unwrap().dueRules, [
|
||||
{
|
||||
dueDays: "30",
|
||||
percentage: {
|
||||
value: "10000",
|
||||
scale: 2,
|
||||
},
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
@ -306,7 +306,7 @@ export class ProformaToIssuedInvoiceConverter implements IProformaToIssuedInvoic
|
||||
dueRules: paymentTerm.dueRules.map((rule) => ({
|
||||
dueDays: rule.dueDays,
|
||||
percentage: {
|
||||
value: rule.percentage.value,
|
||||
value: String(rule.percentage.value),
|
||||
scale: rule.percentage.scale,
|
||||
},
|
||||
})),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user