#5914 - hotFix-transferInvoice #1893

Merged
alexm merged 17 commits from 5914-hotFix-transferInvoice into test 2024-01-04 07:13:01 +00:00
9 changed files with 50 additions and 37 deletions
Showing only changes of commit 1e3a7e5f91 - Show all commits

View File

@ -0,0 +1,7 @@
ALTER TABLE `vn`.`invoiceCorrection` DROP FOREIGN KEY `cplusInvoiceTyoeFk`;
ALTER TABLE `vn`.`invoiceCorrection` DROP FOREIGN KEY `invoiceCorrectionType_Fk33`;
ALTER TABLE `vn`.`invoiceCorrection` DROP FOREIGN KEY `invoiceCorrection_ibfk_1`;
ALTER TABLE `vn`.`invoiceCorrection` ADD CONSTRAINT `siiTypeInvoiceOut_FK` FOREIGN KEY (`siiTypeInvoiceOutFk`) REFERENCES `vn`.`siiTypeInvoiceOut`(id) ON UPDATE CASCADE;
ALTER TABLE `vn`.`invoiceCorrection` ADD CONSTRAINT `invoiceCorrectionType_FK` FOREIGN KEY (`invoiceCorrectionTypeFk`) REFERENCES `vn`.`invoiceCorrectionType`(id) ON UPDATE CASCADE;
ALTER TABLE `vn`.`invoiceCorrection` ADD CONSTRAINT `cplusRectificationType_FK` FOREIGN KEY (`cplusRectificationTypeFk`) REFERENCES `vn`.`cplusRectificationType`(id) ON UPDATE CASCADE;

View File

@ -14,7 +14,7 @@ BEGIN
CALL getTaxBases();
SELECT positive > 0 INTO hasAnyPositiveBase
SELECT positive INTO hasAnyPositiveBase
FROM tmp.taxBases;
alexm marked this conversation as resolved Outdated

sino poses un limit uno açò pot donar error si hi ha 2 en el into

sino poses un limit uno açò pot donar error si hi ha 2 en el into
DROP TEMPORARY TABLE

View File

@ -14,7 +14,7 @@ BEGIN
CALL getTaxBases();
SELECT negative > 0 INTO hasAnyNegativeBase
SELECT negative INTO hasAnyNegativeBase
FROM tmp.taxBases;
alexm marked this conversation as resolved Outdated

limit 1

limit 1
DROP TEMPORARY TABLE

View File

@ -26,6 +26,33 @@
"invoiceCorrectionTypeFk": {
"type": "number",
"required": true
},
"relations": {
"correcting": {
alexm marked this conversation as resolved Outdated

No hay relación con las tablas de "types"?

No hay relación con las tablas de "types"?
"type": "belongsTo",
"model": "InvoiceOut",
"foreignKey": "correctingFk"
},
"corrected": {
"type": "belongsTo",
"model": "InvoiceOut",
"foreignKey": "correctedFk"
},
"cplusRectificationType": {
"type": "belongsTo",
"model": "cplusRectificationType",
"foreignKey": "cplusRectificationTypeFk"
},
"siiTypeInvoiceOut": {
"type": "belongsTo",
"model": "siiTypeInvoiceOut",
"foreignKey": "siiTypeInvoiceOutFk"
},
"invoiceCorrectionType": {
"type": "belongsTo",
"model": "invoiceCorrectionType",
"foreignKey": "invoiceCorrectionTypeFk"
}
}
}
}

View File

@ -17,11 +17,6 @@ module.exports = function(Self) {
type: 'boolean'
}
],
returns: {
arg: 'data',
type: 'boolean',
root: true
},
http: {
path: `/canBeInvoiced`,
verb: 'get'
@ -63,7 +58,5 @@ module.exports = function(Self) {
if (ticketsIds.length == 1 && priceZero)
throw new UserError(`A ticket with an amount of zero can't be invoiced`);
});
return true;
};
};

View File

@ -61,20 +61,19 @@ module.exports = function(Self) {
if (!isSameClient)
throw new UserError(`You can't invoice tickets from multiple clients`);
const client = await models.Client.findById(clientId, {
fields: ['id', 'hasToInvoiceByAddress']
const {hasToInvoiceByAddress} = await models.Client.findById(clientId, {
fields: ['hasToInvoiceByAddress']
alexm marked this conversation as resolved Outdated

La propiedad id no la usas, al igual que en la línea 50, aunque es poco significativo.

La propiedad id no la usas, al igual que en la línea 50, aunque es poco significativo.
}, myOptions);
let ticketsByAddress = {[firstTicket.addressFk]: ticketsIds};
if (client.hasToInvoiceByAddress) {
ticketsByAddress = tickets.reduce((group, ticket) => {
const {addressFk} = ticket;
let ticketsByAddress = hasToInvoiceByAddress
alexm marked this conversation as resolved Outdated

Asignas unos valores que luego puede que se machaquen
Quizás declararia la variable vacía y pondria un else, o también mover a un método aparte

Asignas unos valores que luego puede que se machaquen Quizás declararia la variable vacía y pondria un else, o también mover a un método aparte
? Object.values(tickets.reduce((group, {id, addressFk}) => {
alexm marked this conversation as resolved Outdated

Si es la única llamada a client, porque no haces const { hasToInvoiceByAddress} en la línea 64

Si es la única llamada a client, porque no haces const { hasToInvoiceByAddress} en la línea 64
group[addressFk] = group[addressFk] ?? [];
alexm marked this conversation as resolved
Review

Todo esto es para hacer un Set de los Ids de tickets?
Porque más abajo haces object.values entonces las keys(addressFk) te dan igual, correcto?

Todo esto es para hacer un Set de los Ids de tickets? Porque más abajo haces object.values entonces las keys(addressFk) te dan igual, correcto?
group[addressFk].push(ticket.id);
group[addressFk].push(id);
return group;
}, {});
}
for (const ticketIds of Object.values(ticketsByAddress))
}, {}))
: [[ticketsIds]];
for (const ticketIds of ticketsByAddress)
invoicesIds.push(await createInvoice(ctx, companyId, ticketIds, invoiceCorrection, myOptions));
if (tx) await tx.commit();

View File

@ -106,7 +106,6 @@ module.exports = function(Self) {
);
}
if (resultInvoice.id)
await Self.rawSql('CALL invoiceOutBooking(?)', [resultInvoice.id], myOptions);
alexm marked this conversation as resolved Outdated

Puede ser resultInvoice.id nulo? Porque en la línea 99 ya se emitiría un error

Puede ser resultInvoice.id nulo? Porque en la línea 99 ya se emitiría un error
if (tx) await tx.commit();

View File

@ -27,10 +27,7 @@ describe('ticket canBeInvoiced()', () => {
WHERE id IN (?)
`, [ticketId], options);
const canBeInvoiced = await models.Ticket.canBeInvoiced(ctx, [ticketId], false, options);
expect(canBeInvoiced).toEqual(false);
await models.Ticket.canBeInvoiced(ctx, [ticketId], false, options);
alexm marked this conversation as resolved
Review

no hi ha cap test a de canBeInvoiced amb el 3 parametro a true

no hi ha cap test a de canBeInvoiced amb el 3 parametro a true
await tx.rollback();
} catch (e) {
error = e;
@ -59,10 +56,7 @@ describe('ticket canBeInvoiced()', () => {
WHERE id IN (?)
`, [ticketId], options);
const canBeInvoiced = await models.Ticket.canBeInvoiced(ctx, [ticketId], false, options);
expect(canBeInvoiced).toEqual(false);
await models.Ticket.canBeInvoiced(ctx, [ticketId], false, options);
await tx.rollback();
} catch (e) {
error = e;
@ -95,10 +89,7 @@ describe('ticket canBeInvoiced()', () => {
WHERE id IN (?)
`, [ticketId], options);
const canBeInvoiced = await models.Ticket.canBeInvoiced(ctx, [ticketId], false, options);
expect(canBeInvoiced).toEqual(false);
await models.Ticket.canBeInvoiced(ctx, [ticketId], false, options);
await tx.rollback();
} catch (e) {
error = e;
@ -123,10 +114,7 @@ describe('ticket canBeInvoiced()', () => {
WHERE id IN (?)
`, [ticketId], options);
const canBeInvoiced = await models.Ticket.canBeInvoiced(ctx, [ticketId], false, options);
expect(canBeInvoiced).toEqual(true);
await models.Ticket.canBeInvoiced(ctx, [ticketId], false, options);
await tx.rollback();
} catch (e) {
await tx.rollback();