This commit is contained in:
David Arranz 2026-07-29 11:32:25 +02:00
parent 16118da1ee
commit 647528b128
6 changed files with 39 additions and 33 deletions

View File

@ -70,18 +70,18 @@ export class UpdateProformaInputMapper implements IUpdateProformaInputMapper {
); );
}); });
toPatchField(dto.invoice_date).ifSet((invoiceDate) => { toPatchField(dto.proforma_date).ifSet((proformaDate) => {
if (isNullishOrEmpty(invoiceDate)) { if (isNullishOrEmpty(proformaDate)) {
errors.push({ errors.push({
path: "invoice_date", path: "proforma_date",
message: "Invoice date cannot be empty", message: "Proforma date cannot be empty",
}); });
return; return;
} }
proformaPatchProps.proformaDate = extractOrPushError( proformaPatchProps.proformaDate = extractOrPushError(
UtcDate.createFromISO(invoiceDate), UtcDate.createFromISO(proformaDate),
"invoice_date", "proforma_date",
errors errors
); );
}); });
@ -340,5 +340,4 @@ export class UpdateProformaInputMapper implements IUpdateProformaInputMapper {
throw new ValidationErrorCollection("Proforma props mapping failed", errors); throw new ValidationErrorCollection("Proforma props mapping failed", errors);
} }
} }
} }

View File

@ -1,10 +1,11 @@
import type { Maybe } from "@repo/rdx-utils";
import type { import type {
InvoiceSerie,
ProformaItemPatchProps, ProformaItemPatchProps,
ProformaPatchProps, ProformaPatchProps,
ProformaTaxMode, ProformaTaxMode,
} from "../../../domain"; } from "../../../domain";
import type { Maybe } from "@repo/rdx-utils";
import type { InvoiceSerie } from "../../../domain";
import type { ProformaItemTaxCodesInput } from "./proforma-item-tax-codes-input.model"; import type { ProformaItemTaxCodesInput } from "./proforma-item-tax-codes-input.model";

View File

@ -8,16 +8,15 @@ import {
InvoiceNumber, InvoiceNumber,
Proforma, Proforma,
ProformaTaxConfig, ProformaTaxConfig,
type ProformaTaxMode,
} from "../../../domain"; } from "../../../domain";
import type { ProformaCreateInputProps, ProformaTaxConfigInputProps } from "../models"; import type { ProformaCreateInputProps, ProformaTaxConfigInputProps } from "../models";
import type { IProformaRepository } from "../repositories"; import type { IProformaRepository } from "../repositories";
import type { ProformaPaymentResolver } from "./catalog-resolver/proforma-payment-resolver"; import type { ProformaPaymentResolver } from "./catalog-resolver/proforma-payment-resolver";
import type { ProformaSeriesValidator } from "./proforma-series-validator.interface";
import type { ProformaTargetInvoiceSeriesValidator } from "./proforma-target-invoice-series-validator.interface";
import type { ProformaTaxResolver } from "./catalog-resolver/proforma-tax-resolver"; import type { ProformaTaxResolver } from "./catalog-resolver/proforma-tax-resolver";
import type { IProformaNumberGenerator } from "./proforma-number-generator.interface"; import type { IProformaNumberGenerator } from "./proforma-number-generator.interface";
import type { ProformaSeriesValidator } from "./proforma-series-validator.interface";
import type { ProformaTargetInvoiceSeriesValidator } from "./proforma-target-invoice-series-validator.interface";
export interface IProformaCreatorParams { export interface IProformaCreatorParams {
companyId: UniqueID; companyId: UniqueID;
@ -46,16 +45,18 @@ export class ProformaCreator implements IProformaCreator {
async create(params: IProformaCreatorParams): Promise<Result<Proforma, Error>> { async create(params: IProformaCreatorParams): Promise<Result<Proforma, Error>> {
const { companyId, id, props, transaction } = params; const { companyId, id, props, transaction } = params;
const resolvedProps = await this.resolveCreateProps(props, transaction); const resolvedPropsResult = await this.resolveCreateProps(props, transaction);
if (resolvedProps.isFailure) { if (resolvedPropsResult.isFailure) {
return Result.fail(resolvedProps.error); return Result.fail(resolvedPropsResult.error);
} }
const resolvedProps = resolvedPropsResult.data;
const proformaSeriesValidationResult = const proformaSeriesValidationResult =
await this.deps.proformaSeriesValidator.ensureValidProformaSeries({ await this.deps.proformaSeriesValidator.ensureValidProformaSeries({
companyId, companyId,
proformaSeriesCode: resolvedProps.data.proformaSeriesCode, proformaSeriesCode: resolvedProps.proformaSeriesCode,
transaction, transaction,
}); });
@ -66,7 +67,7 @@ export class ProformaCreator implements IProformaCreator {
// 1. Obtener siguiente número // 1. Obtener siguiente número
const numberResult = await this.deps.numberService.getNextForCompany( const numberResult = await this.deps.numberService.getNextForCompany(
companyId, companyId,
resolvedProps.data.proformaSeriesCode, resolvedProps.proformaSeriesCode,
transaction transaction
); );
@ -77,7 +78,7 @@ export class ProformaCreator implements IProformaCreator {
const targetInvoiceSeriesValidationResult = const targetInvoiceSeriesValidationResult =
await this.deps.targetInvoiceSeriesValidator.ensureValidIssuedInvoiceSeries({ await this.deps.targetInvoiceSeriesValidator.ensureValidIssuedInvoiceSeries({
companyId, companyId,
targetInvoiceSeriesCode: resolvedProps.data.targetInvoiceSeriesCode, targetInvoiceSeriesCode: resolvedPropsResult.data.targetInvoiceSeriesCode,
transaction, transaction,
}); });
@ -102,12 +103,12 @@ export class ProformaCreator implements IProformaCreator {
// 2. Crear agregado // 2. Crear agregado
const proformaResult = Proforma.create( const proformaResult = Proforma.create(
{ {
...resolvedProps.data, ...resolvedPropsResult.data,
companyId, companyId,
documentSeriesId: Maybe.some(numberResult.data.documentSeriesId), documentSeriesId: Maybe.some(numberResult.data.documentSeriesId),
proformaNumber: Maybe.some(proformaNumberResult.data), proformaNumber: Maybe.some(proformaNumberResult.data),
proformaReference, proformaReference,
series: resolvedProps.data.targetInvoiceSeriesCode, series: resolvedPropsResult.data.targetInvoiceSeriesCode,
}, },
id id
); );
@ -139,7 +140,10 @@ export class ProformaCreator implements IProformaCreator {
props: ProformaCreateInputProps, props: ProformaCreateInputProps,
transaction?: unknown transaction?: unknown
): Promise< ): Promise<
Result<Omit<IProformaCreateProps, "proformaReference" | "proformaNumber" | "documentSeriesId">, Error> Result<
Omit<IProformaCreateProps, "proformaReference" | "proformaNumber" | "documentSeriesId">,
Error
>
> { > {
const customerResult = await this.deps.customerServices.getCustomerById(props.customerId, { const customerResult = await this.deps.customerServices.getCustomerById(props.customerId, {
companyId: props.companyId, companyId: props.companyId,
@ -154,12 +158,11 @@ export class ProformaCreator implements IProformaCreator {
const _newProps = { const _newProps = {
...props, ...props,
taxRegimeCode: taxRegimeCode: props.taxRegimeCode.isNone()
props.taxRegimeCode.isNone() ? customer.taxRegimeCode.isSome()
? customer.taxRegimeCode.isSome() ? customer.taxRegimeCode
? customer.taxRegimeCode : Maybe.some("01")
: Maybe.some("01") : props.taxRegimeCode,
: props.taxRegimeCode,
}; };
// Tax Regime => comprobar que existe // Tax Regime => comprobar que existe

View File

@ -2,10 +2,10 @@ import { DomainValidationError, type UniqueID, type UtcDate } from "@repo/rdx-dd
import { Maybe, Result } from "@repo/rdx-utils"; import { Maybe, Result } from "@repo/rdx-utils";
import { import {
ProformaTaxConfig,
type Proforma, type Proforma,
type ProformaItemPatchProps, type ProformaItemPatchProps,
type ProformaPatchProps, type ProformaPatchProps,
ProformaTaxConfig,
} from "../../../domain"; } from "../../../domain";
import type { ProformaPatchInputProps } from "../models"; import type { ProformaPatchInputProps } from "../models";
import type { IProformaRepository } from "../repositories"; import type { IProformaRepository } from "../repositories";
@ -246,8 +246,7 @@ export class ProformaUpdater implements IProformaUpdater {
companyId: params.companyId, companyId: params.companyId,
atDate: params.currentInvoiceDate, atDate: params.currentInvoiceDate,
usesRetention, usesRetention,
requestedCode: requestedCode: patchTaxConfig.defaultRetentionCode ?? currentTaxConfig.defaultRetentionCode,
patchTaxConfig.defaultRetentionCode ?? currentTaxConfig.defaultRetentionCode,
}); });
if (defaultRetentionCode.isFailure) { if (defaultRetentionCode.isFailure) {

View File

@ -2,7 +2,7 @@ import type { ISnapshotBuilder } from "@erp/core/api";
import { DomainValidationError, maybeToNullable } from "@repo/rdx-ddd"; import { DomainValidationError, maybeToNullable } from "@repo/rdx-ddd";
import type { ProformaRecipientSummaryDTO } from "../../../../../common"; import type { ProformaRecipientSummaryDTO } from "../../../../../common";
import type { InvoiceRecipient, Proforma } from "../../../../domain"; import type { Proforma } from "../../../../domain";
export interface IProformaRecipientFullSnapshotBuilder export interface IProformaRecipientFullSnapshotBuilder
extends ISnapshotBuilder<Proforma, ProformaRecipientSummaryDTO> {} extends ISnapshotBuilder<Proforma, ProformaRecipientSummaryDTO> {}
@ -16,7 +16,7 @@ export class ProformaRecipientFullSnapshotBuilder implements IProformaRecipientF
} }
return proforma.recipient.match( return proforma.recipient.match(
(recipient: InvoiceRecipient) => ({ (recipient) => ({
id: proforma.customerId.toString(), id: proforma.customerId.toString(),
name: recipient.name.toString(), name: recipient.name.toString(),
tin: maybeToNullable(recipient.tin, (v) => v.toString()), tin: maybeToNullable(recipient.tin, (v) => v.toString()),

View File

@ -29,7 +29,11 @@ import {
import { InvalidProformaTransitionError, ProformaItemMismatch } from "../errors"; import { InvalidProformaTransitionError, ProformaItemMismatch } from "../errors";
import type { IProformaTaxTotals, ProformaCalculationContext } from "../services"; import type { IProformaTaxTotals, ProformaCalculationContext } from "../services";
import { canManuallyTransitionProformaStatus } from "../services"; import { canManuallyTransitionProformaStatus } from "../services";
import { ProformaItemTaxes, ProformaTaxConfig, type ProformaRecipient } from "../value-objects"; import {
ProformaItemTaxes,
type ProformaRecipient,
type ProformaTaxConfig,
} from "../value-objects";
export interface IProformaCreateProps { export interface IProformaCreateProps {
companyId: UniqueID; companyId: UniqueID;