diff --git a/db/changes/240001/00-getTaxBases.sql b/db/changes/240001/00-getTaxBases.sql index fa43c32f7..8bd1b745a 100644 --- a/db/changes/240001/00-getTaxBases.sql +++ b/db/changes/240001/00-getTaxBases.sql @@ -2,8 +2,8 @@ DELIMITER $$ $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`getTaxBases`() BEGIN - -/* Calcula y devuelve en número de bases imponibles postivas y negativas +/** +* Calcula y devuelve en número de bases imponibles postivas y negativas * Requiere la tabla temporal tmp.ticketToInvoice(id) * * returns tmp.taxBases @@ -21,10 +21,10 @@ BEGIN CREATE TEMPORARY TABLE tmp.taxBases ENGINE = MEMORY SELECT - SUM(CASE WHEN taxableBase > 0 THEN 1 ELSE 0 END) as positive, - SUM(CASE WHEN taxableBase < 0 THEN 1 ELSE 0 END) as negative + SUM(taxableBase > 0) as positive, + SUM(taxableBase < 0) as negative FROM( - SELECT SUM(taxableBase) as taxableBase + SELECT SUM(taxableBase) taxableBase FROM tmp.ticketTax GROUP BY pgcFk ) t; diff --git a/db/changes/240001/01-newHasAnyPositiveBase.sql b/db/changes/240001/01-newHasAnyPositiveBase.sql index 70fd51bcc..c4edfaed0 100644 --- a/db/changes/240001/01-newHasAnyPositiveBase.sql +++ b/db/changes/240001/01-newHasAnyPositiveBase.sql @@ -4,7 +4,8 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`hasAnyPositiveBase`( DETERMINISTIC BEGIN -/* Calcula si existe alguna base imponible positiva +/** +* Calcula si existe alguna base imponible positiva * Requiere la tabla temporal tmp.ticketToInvoice(id) para getTaxBases() * * returns BOOLEAN @@ -15,7 +16,8 @@ BEGIN CALL getTaxBases(); SELECT positive INTO hasAnyPositiveBase - FROM tmp.taxBases; + FROM tmp.taxBases + LIMIT 1; DROP TEMPORARY TABLE tmp.ticketTax, diff --git a/db/changes/240001/01-refactorHasAnyNegativeBase.sql b/db/changes/240001/01-refactorHasAnyNegativeBase.sql index f851ee6b9..a3eb2d9c7 100644 --- a/db/changes/240001/01-refactorHasAnyNegativeBase.sql +++ b/db/changes/240001/01-refactorHasAnyNegativeBase.sql @@ -4,7 +4,8 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`hasAnyNegativeBase`( DETERMINISTIC BEGIN -/* Calcula si existe alguna base imponible negativa +/** +* Calcula si existe alguna base imponible negativa * Requiere la tabla temporal tmp.ticketToInvoice(id) para getTaxBases() * * returns BOOLEAN @@ -15,7 +16,8 @@ BEGIN CALL getTaxBases(); SELECT negative INTO hasAnyNegativeBase - FROM tmp.taxBases; + FROM tmp.taxBases + LIMIT 1; DROP TEMPORARY TABLE tmp.ticketTax, @@ -27,3 +29,4 @@ BEGIN END$$ DELIMITER ; + diff --git a/modules/invoiceOut/front/descriptor-menu/locale/es.yml b/modules/invoiceOut/front/descriptor-menu/locale/es.yml index 9456646af..bf89b2ba0 100644 --- a/modules/invoiceOut/front/descriptor-menu/locale/es.yml +++ b/modules/invoiceOut/front/descriptor-menu/locale/es.yml @@ -23,3 +23,4 @@ The following refund tickets have been created: "Se han creado los siguientes ti Refund...: Abono... Transfer invoice to...: Transferir factura a... Rectificative type: Tipo rectificativa +Invoice trasfered!: ¡Factura transferida! diff --git a/modules/ticket/back/methods/ticket/invoiceTickets.js b/modules/ticket/back/methods/ticket/invoiceTickets.js index 57f623289..06429836e 100644 --- a/modules/ticket/back/methods/ticket/invoiceTickets.js +++ b/modules/ticket/back/methods/ticket/invoiceTickets.js @@ -71,7 +71,7 @@ module.exports = function(Self) { group[addressFk].push(id); return group; }, {})) - : [[ticketsIds]]; + : [ticketsIds]; for (const ticketIds of ticketsByAddress) invoicesIds.push(await createInvoice(ctx, companyId, ticketIds, invoiceCorrection, myOptions)); diff --git a/modules/ticket/back/methods/ticket/specs/canBeInvoiced.spec.js b/modules/ticket/back/methods/ticket/specs/canBeInvoiced.spec.js index 1509b87df..78973e040 100644 --- a/modules/ticket/back/methods/ticket/specs/canBeInvoiced.spec.js +++ b/modules/ticket/back/methods/ticket/specs/canBeInvoiced.spec.js @@ -121,4 +121,29 @@ describe('ticket canBeInvoiced()', () => { throw e; } }); + + it('should return falsy for a ticket has positiveBase', async() => { + const tx = await models.Ticket.beginTransaction({}); + + try { + const options = {transaction: tx}; + + await models.Ticket.rawSql(` + CREATE OR REPLACE TEMPORARY TABLE tmp.ticketToInvoice + (PRIMARY KEY (id)) + ENGINE = MEMORY + SELECT id + FROM vn.ticket + WHERE id IN (?) + `, [ticketId], options); + + await models.Ticket.canBeInvoiced(ctx, [ticketId], true, options); + await tx.rollback(); + } catch (e) { + error = e; + await tx.rollback(); + } + + expect(error.message).toEqual(`hasAnyPositiveBase`); + }); });