From e0f52da54fa5711a90138df79a07be0b793262ff Mon Sep 17 00:00:00 2001 From: David Arranz Date: Mon, 5 Oct 2026 14:31:17 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20agregar=20soporte=20para=20m=C3=BAltipl?= =?UTF-8?q?es=20idiomas=20en=20el=20informe=20de=20presupuesto?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reporter/ReportQuote.labels.ts | 57 +++++++++++++++++++ .../reporter/ReportQuote.reporter.test.ts | 30 +++++++++- .../reporter/ReportQuote.reporter.ts | 5 +- .../reporter/templates/quote/template.hbs | 46 +++++++-------- 4 files changed, 112 insertions(+), 26 deletions(-) create mode 100644 server/src/contexts/sales/infrastructure/express/controllers/quotes/reportQuote/reporter/ReportQuote.labels.ts diff --git a/server/src/contexts/sales/infrastructure/express/controllers/quotes/reportQuote/reporter/ReportQuote.labels.ts b/server/src/contexts/sales/infrastructure/express/controllers/quotes/reportQuote/reporter/ReportQuote.labels.ts new file mode 100644 index 0000000..a4563d3 --- /dev/null +++ b/server/src/contexts/sales/infrastructure/express/controllers/quotes/reportQuote/reporter/ReportQuote.labels.ts @@ -0,0 +1,57 @@ +export const reportLabels = { + es: { + official_distributor: "DISTRIBUIDOR OFICIAL", + dealer_logo: "Logo distribuidor", + document_title: "PRESUPUESTO", + browser_title: "Presupuesto", + quote_number: "Presupuesto nº:", + date: "Fecha:", + validity: "Validez:", + salesperson: "Vendedor:", + customer_reference: "Referencia cliente:", + page: "Página", + of: "de", + quantity: "Cant.", + description: "Descripción", + unit_price: "Prec. Unitario", + subtotal: "Subtotal", + discount: "Dto (%)", + total_amount: "Importe total", + payment_method: "Forma de pago:", + notes: "Notas:", + net_amount: "Importe neto", + discounts: "Descuentos", + percentage_discount: "% Descuento", + taxable_amount: "Base imponible", + }, + en: { + official_distributor: "OFFICIAL DISTRIBUTOR", + dealer_logo: "Dealer logo", + document_title: "QUOTE", + browser_title: "Quote", + quote_number: "Quote no.:", + date: "Date:", + validity: "Validity:", + salesperson: "Salesperson:", + customer_reference: "Customer reference:", + page: "Page", + of: "of", + quantity: "Qty.", + description: "Description", + unit_price: "Unit price", + subtotal: "Subtotal", + discount: "Discount (%)", + total_amount: "Total amount", + payment_method: "Payment method:", + notes: "Notes:", + net_amount: "Net amount", + discounts: "Discounts", + percentage_discount: "% Discount", + taxable_amount: "Taxable amount", + }, +} as const; + +export type ReportLanguage = keyof typeof reportLabels; + +export const resolveReportLanguage = (language: string): ReportLanguage => + language === "en" ? "en" : "es"; diff --git a/server/src/contexts/sales/infrastructure/express/controllers/quotes/reportQuote/reporter/ReportQuote.reporter.test.ts b/server/src/contexts/sales/infrastructure/express/controllers/quotes/reportQuote/reporter/ReportQuote.reporter.test.ts index e464a8d..b9c0dd1 100644 --- a/server/src/contexts/sales/infrastructure/express/controllers/quotes/reportQuote/reporter/ReportQuote.reporter.test.ts +++ b/server/src/contexts/sales/infrastructure/express/controllers/quotes/reportQuote/reporter/ReportQuote.reporter.test.ts @@ -2,7 +2,12 @@ import { ISalesContext } from "@/contexts/sales/infrastructure/Sales.context"; import { createQuoteMapper } from "@/contexts/sales/infrastructure/mappers/quote.mapper"; import { ReportQuotePresenter } from "./ReportQuote.reporter"; -const source = (showLineDiscountColumn: boolean, generalDiscount: number, taxLabel = "% IVA") => +const source = ( + showLineDiscountColumn: boolean, + generalDiscount: number, + taxLabel = "% IVA", + langCode = "es" +) => ({ show_line_discount_column: showLineDiscountColumn, items: [], @@ -12,7 +17,7 @@ const source = (showLineDiscountColumn: boolean, generalDiscount: number, taxLab date: "2026-10-03", reference: "Q-1", currency_code: "EUR", - lang_code: "es", + lang_code: langCode, customer_reference: "", customer_information: "Customer", validity: "", @@ -51,4 +56,25 @@ describe("ReportQuotePresenter", () => { expect(html).toContain("% IGIC"); }); + + it("renders English report labels while preserving quote item snapshots", async () => { + const html = await ReportQuotePresenter.toHTML( + mapper.mapToDomain(source(false, 0, "% IVA", "en")), + context + ); + + expect(html).toContain(''); + expect(html).toContain("QUOTE"); + expect(html).toContain("Description"); + expect(html).not.toContain(">PRESUPUESTO<"); + }); + + it("falls back to Spanish labels and language for unsupported quote languages", async () => { + const html = await ReportQuotePresenter.toHTML(mapper.mapToDomain(source(false, 0, "% IGIC", "fr")), context); + + expect(html).toContain(''); + expect(html).toContain("PRESUPUESTO"); + expect(html).toContain("Descripción"); + expect(html).toContain("% IGIC"); + }); }); diff --git a/server/src/contexts/sales/infrastructure/express/controllers/quotes/reportQuote/reporter/ReportQuote.reporter.ts b/server/src/contexts/sales/infrastructure/express/controllers/quotes/reportQuote/reporter/ReportQuote.reporter.ts index ab5d94d..fe1c75e 100644 --- a/server/src/contexts/sales/infrastructure/express/controllers/quotes/reportQuote/reporter/ReportQuote.reporter.ts +++ b/server/src/contexts/sales/infrastructure/express/controllers/quotes/reportQuote/reporter/ReportQuote.reporter.ts @@ -7,6 +7,7 @@ import * as handlebars from "handlebars"; import path from "path"; import puppeteer from "puppeteer"; import report from "puppeteer-report"; +import { reportLabels, resolveReportLanguage } from "./ReportQuote.labels"; export interface IReportQuoteReporter { toHTML: (quote: Quote, context: ISalesContext) => Promise; @@ -63,6 +64,7 @@ export const ReportQuotePresenter: IReportQuoteReporter = { const map = async (quote: Quote, context: ISalesContext) => { const { dealer } = context; + const langCode = resolveReportLanguage(quote.language.toString()); return { id: quote.id.toString(), @@ -71,7 +73,8 @@ const map = async (quote: Quote, context: ISalesContext) => { reference: quote.reference.toString(), customer_reference: quote.customerReference.toString(), customer_information: quote.customer.toString(), - lang_code: quote.language.toString(), + lang_code: langCode, + labels: reportLabels[langCode], currency_code: quote.currency.toString(), payment_method: quote.paymentMethod.toString(), diff --git a/server/src/contexts/sales/infrastructure/express/controllers/quotes/reportQuote/reporter/templates/quote/template.hbs b/server/src/contexts/sales/infrastructure/express/controllers/quotes/reportQuote/reporter/templates/quote/template.hbs index 7b21f86..ef0062c 100644 --- a/server/src/contexts/sales/infrastructure/express/controllers/quotes/reportQuote/reporter/templates/quote/template.hbs +++ b/server/src/contexts/sales/infrastructure/express/controllers/quotes/reportQuote/reporter/templates/quote/template.hbs @@ -4,7 +4,7 @@ - Presupuesto #{{id}} + {{labels.browser_title}} #{{id}}