This commit is contained in:
David Arranz 2026-06-14 21:04:24 +02:00
parent 3a0262cbf7
commit e5fbad0915
7 changed files with 28 additions and 29 deletions

View File

@ -39,10 +39,10 @@ export default (database: Sequelize) => {
code: { code: {
type: DataTypes.STRING(2), type: DataTypes.STRING(2),
allowNull: false, allowNull: false,
unique: true, unique: false,
}, },
description: { description: {
type: DataTypes.STRING, type: DataTypes.STRING(500),
allowNull: false, allowNull: false,
}, },
is_active: { is_active: {
@ -71,8 +71,8 @@ export default (database: Sequelize) => {
indexes: [ indexes: [
{ {
name: "idx_tax_regimes_code", name: "idx_tax_regimes_company_id_code",
fields: ["code", "deleted_at"], fields: ["company_id", "code", "deletedAt"],
unique: true, unique: true,
}, },
], ],

View File

@ -4,10 +4,10 @@ import { Maybe, Result } from "@repo/rdx-utils";
import type { Proforma } from "../../../../domain"; import type { Proforma } from "../../../../domain";
import type { import type {
ProformaFullReadModel, InvocieTaxRegimeFullReadModel,
ProformaPaymentMethodReadModel, InvoicePaymentMethodReadModel,
ProformaTaxRegimeFullReadModel, } from "../../../common/models";
} from "../../models"; import type { ProformaFullReadModel } from "../../models";
export interface IProformaFullReadModelAssembler { export interface IProformaFullReadModelAssembler {
assemble(params: { assemble(params: {
@ -62,7 +62,7 @@ export class ProformaFullReadModelAssembler implements IProformaFullReadModelAss
companyId: UniqueID; companyId: UniqueID;
proforma: Proforma; proforma: Proforma;
transaction?: unknown; transaction?: unknown;
}): Promise<Result<Maybe<ProformaPaymentMethodReadModel>, Error>> { }): Promise<Result<Maybe<InvoicePaymentMethodReadModel>, Error>> {
if (params.proforma.paymentMethodId.isNone()) { if (params.proforma.paymentMethodId.isNone()) {
return Result.ok(Maybe.none()); return Result.ok(Maybe.none());
} }
@ -82,7 +82,7 @@ export class ProformaFullReadModelAssembler implements IProformaFullReadModelAss
if (result.data.isNone()) { if (result.data.isNone()) {
return Result.ok( return Result.ok(
Maybe.some({ Maybe.some({
id: paymentMethodId.toString(), id: paymentMethodId,
name: "", name: "",
description: Maybe.none(), description: Maybe.none(),
}) })
@ -93,7 +93,7 @@ export class ProformaFullReadModelAssembler implements IProformaFullReadModelAss
return Result.ok( return Result.ok(
Maybe.some({ Maybe.some({
id: paymentMethod.id.toString(), id: paymentMethod.id,
name: paymentMethod.name.toString(), name: paymentMethod.name.toString(),
description: paymentMethod.description ?? null, description: paymentMethod.description ?? null,
}) })
@ -104,7 +104,7 @@ export class ProformaFullReadModelAssembler implements IProformaFullReadModelAss
companyId: UniqueID; companyId: UniqueID;
proforma: Proforma; proforma: Proforma;
transaction?: unknown; transaction?: unknown;
}): Promise<Result<Maybe<ProformaTaxRegimeFullReadModel>, Error>> { }): Promise<Result<Maybe<InvocieTaxRegimeFullReadModel>, Error>> {
if (params.proforma.taxRegimeCode.isNone()) { if (params.proforma.taxRegimeCode.isNone()) {
return Result.ok(Maybe.none()); return Result.ok(Maybe.none());
} }

View File

@ -77,6 +77,8 @@ export class ProformaUpdater implements IProformaUpdater {
}): Promise<Result<ProformaPatchProps, Error>> { }): Promise<Result<ProformaPatchProps, Error>> {
const { patch, companyId, currentInvoiceDate } = params; const { patch, companyId, currentInvoiceDate } = params;
console.log(patch);
if (patch.taxRegimeCode !== undefined) { if (patch.taxRegimeCode !== undefined) {
const taxRegimeResult = await this.deps.taxResolver.ensureTaxRegimeByCode({ const taxRegimeResult = await this.deps.taxResolver.ensureTaxRegimeByCode({
companyId, companyId,

View File

@ -1,5 +1,5 @@
import type { ISnapshotBuilder } from "@erp/core/api"; import type { ISnapshotBuilder } from "@erp/core/api";
import { maybeToNullable } from "@repo/rdx-ddd"; import { maybeToEmptyString, maybeToNullable } from "@repo/rdx-ddd";
import type { GetProformaByIdResponseDTO } from "../../../../../common"; import type { GetProformaByIdResponseDTO } from "../../../../../common";
import type { ProformaFullReadModel } from "../../models"; import type { ProformaFullReadModel } from "../../models";
@ -21,7 +21,7 @@ export class ProformaFullSnapshotBuilder implements IProformaFullSnapshotBuilder
) {} ) {}
toOutput(source: ProformaFullReadModel): ProformaFullSnapshot { toOutput(source: ProformaFullReadModel): ProformaFullSnapshot {
const { proforma } = source; const { proforma, paymentMethod, taxRegime } = source;
const calculationContext = { const calculationContext = {
languageCode: proforma.languageCode, languageCode: proforma.languageCode,
@ -58,19 +58,16 @@ export class ProformaFullSnapshotBuilder implements IProformaFullSnapshotBuilder
linked_invoice_id: maybeToNullable(proforma.linkedInvoiceId, (value) => value.toString()), linked_invoice_id: maybeToNullable(proforma.linkedInvoiceId, (value) => value.toString()),
/*payment_method: { payment_method: maybeToNullable(paymentMethod, (paymentMethod) => ({
id: source.paymentMethod., id: paymentMethod.id.toString(),
name: value.name, name: paymentMethod.name,
description: maybeToNullable(value.description, (description) => description), description: maybeToEmptyString(paymentMethod.description),
}, })),
tax_regime: maybeToNullable(taxRegime, (taxRegime) => taxRegime),
payment_term: null, payment_term: null,
tax_regime: {
code: value.code,
description: maybeToNullable(value.description, (description) => description),
},*/
subtotal_amount: allTotals.subtotalAmount.toObjectString(), subtotal_amount: allTotals.subtotalAmount.toObjectString(),
items_discount_amount: allTotals.itemsDiscountAmount.toObjectString(), items_discount_amount: allTotals.itemsDiscountAmount.toObjectString(),

View File

@ -315,7 +315,7 @@ export default (database: Sequelize) => {
}, },
tax_regime_code: { tax_regime_code: {
type: DataTypes.STRING(), type: DataTypes.STRING(2),
allowNull: true, allowNull: true,
}, },

View File

@ -17,7 +17,7 @@ import {
SelectTrigger, SelectTrigger,
SelectValue, SelectValue,
} from "@repo/shadcn-ui/components"; } from "@repo/shadcn-ui/components";
import { FileText } from "lucide-react"; import { LandmarkIcon } from "lucide-react";
import { useTranslation } from "../../../../i18n"; import { useTranslation } from "../../../../i18n";
@ -29,7 +29,7 @@ export const ProformaTaxesCard = () => {
<CardHeader className="px-6 pb-7 pt-3"> <CardHeader className="px-6 pb-7 pt-3">
<div className="flex items-start gap-3"> <div className="flex items-start gap-3">
<div className="flex size-12 shrink-0 items-center justify-center rounded-lg bg-primary-50 text-primary-600"> <div className="flex size-12 shrink-0 items-center justify-center rounded-lg bg-primary-50 text-primary-600">
<FileText aria-hidden="true" className="size-5" /> <LandmarkIcon aria-hidden="true" className="size-5" />
</div> </div>
<div className="space-y-1"> <div className="space-y-1">

View File

@ -7,7 +7,7 @@ import {
} from "@repo/rdx-ui/components"; } from "@repo/rdx-ui/components";
import { PercentageHelper } from "@repo/rdx-utils"; import { PercentageHelper } from "@repo/rdx-utils";
import { Separator } from "@repo/shadcn-ui/components"; import { Separator } from "@repo/shadcn-ui/components";
import { ReceiptTextIcon } from "lucide-react"; import { LandmarkIcon } from "lucide-react";
import { useTranslation } from "../../../../i18n"; import { useTranslation } from "../../../../i18n";
import { import {
@ -45,7 +45,7 @@ export const ProformaUpdateTaxEditor = ({
"Configuración fiscal de la proforma" "Configuración fiscal de la proforma"
)} )}
disabled={disabled} disabled={disabled}
icon={<ReceiptTextIcon className="size-5" />} icon={<LandmarkIcon className="size-5" />}
title={t("form_groups.proformas.taxes.title", "Impuestos y retenciones")} title={t("form_groups.proformas.taxes.title", "Impuestos y retenciones")}
> >
<FormSectionGrid> <FormSectionGrid>