WIP: 5874-refactor_makeInvoice #1649

Closed
vicent wants to merge 6 commits from 5874-refactor_makeInvoice into dev
4 changed files with 16 additions and 13 deletions
Showing only changes of commit aa666ee08d - Show all commits

View File

@ -304,7 +304,5 @@
"Mail not sent": "Se ha producido un fallo al enviar la factura al cliente [{{clientId}}]({{{clientUrl}}}), por favor revisa la dirección de correo electrónico", "Mail not sent": "Se ha producido un fallo al enviar la factura al cliente [{{clientId}}]({{{clientUrl}}}), por favor revisa la dirección de correo electrónico",
"The renew period has not been exceeded": "El periodo de renovación no ha sido superado", "The renew period has not been exceeded": "El periodo de renovación no ha sido superado",
"Valid priorities": "Prioridades válidas: %d", "Valid priorities": "Prioridades válidas: %d",
"There are no tickets to bill": "There are no tickets to bill", "Negative basis of tickets": "Base negativa para los tickets: {{ticketsIds}}"
"Negative basis of tickets": "Base negativa para los tickets: {{ticketsIds}}", }
"Base negativa para los tickets: 10": "Base negativa para los tickets: 10"
}

View File

@ -74,7 +74,8 @@ module.exports = Self => {
], options); ], options);
} }
const invoiceId = await models.Ticket.makeInvoice(ctx, 'G', args.companyFk, options); const invoiceType = 'G';
const invoiceId = await models.Ticket.makeInvoice(ctx, invoiceType, args.companyFk, options);
if (tx) await tx.commit(); if (tx) await tx.commit();

View File

@ -56,15 +56,21 @@ module.exports = function(Self) {
const today = Date.vnNew(); const today = Date.vnNew();
const invalidTickets = tickets.some(ticket => { tickets.some(ticket => {
const shipped = new Date(ticket.shipped); const shipped = new Date(ticket.shipped);
const shippingInFuture = shipped.getTime() > today.getTime(); const shippingInFuture = shipped.getTime() > today.getTime();
const isInvoiced = ticket.refFk; if (shippingInFuture)
const priceZero = ticket.totalWithVat == 0; throw new UserError(`Can't invoice to future`);
return isInvoiced || priceZero || shippingInFuture; const isInvoiced = ticket.refFk;
if (isInvoiced)
throw new UserError(`This ticket is already invoiced`);
const priceZero = ticket.totalWithVat == 0;
if (priceZero)
throw new UserError(`A ticket with an amount of zero can't be invoiced`);
}); });
return !(invalidTickets || hasAnyNegativeBase); return true;
}; };
}; };

View File

@ -59,9 +59,7 @@ module.exports = function(Self) {
fields: ['id', 'clientFk'] fields: ['id', 'clientFk']
}, myOptions); }, myOptions);
const ticketCanBeInvoiced = await models.Ticket.canBeInvoiced(ctx, ticketsIds, myOptions); await models.Ticket.canBeInvoiced(ctx, ticketsIds, myOptions);
if (!ticketCanBeInvoiced || !ticketToInvoice.length)
throw new UserError(`Some of the selected tickets are not billable`);
const [firstTicket] = tickets; const [firstTicket] = tickets;
const clientId = firstTicket.clientFk; const clientId = firstTicket.clientFk;