feat: refs #8167 update locale and improve invoicing logic with error handling
gitea/salix/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Javi Gallego 2024-12-29 09:38:51 +01:00
parent 5acd4520f8
commit 98e2483565
4 changed files with 18 additions and 11 deletions

View File

@ -246,8 +246,9 @@
"ticketLostExpedition": "The ticket [{{ticketId}}]({{{ticketUrl}}}) has the following lost expedition:{{ expeditionId }}", "ticketLostExpedition": "The ticket [{{ticketId}}]({{{ticketUrl}}}) has the following lost expedition:{{ expeditionId }}",
"The raid information is not correct": "The raid information is not correct", "The raid information is not correct": "The raid information is not correct",
"Payment method is required": "Payment method is required", "Payment method is required": "Payment method is required",
"Sales already moved": "Sales already moved", "Sales already moved": "Sales already moved",
"Holidays to past days not available": "Holidays to past days not available", "Holidays to past days not available": "Holidays to past days not available",
"Price cannot be blank": "Price cannot be blank", "Price cannot be blank": "Price cannot be blank",
"There are tickets to be invoiced": "There are tickets to be invoiced" "There are tickets to be invoiced": "There are tickets to be invoiced",
"The address of the customer must have information about Incoterms and Customs Agent": "The address of the customer must have information about Incoterms and Customs Agent"
} }

View File

@ -1,3 +1,5 @@
const UserError = require('vn-loopback/util/user-error');
module.exports = Self => { module.exports = Self => {
Self.remoteMethodCtx('clientsToInvoice', { Self.remoteMethodCtx('clientsToInvoice', {
description: 'Get the clients to make global invoicing', description: 'Get the clients to make global invoicing',
@ -47,7 +49,12 @@ module.exports = Self => {
} }
try { try {
// Packaging liquidation const clientCanBeInvoiced =
await Self.app.models.Client.canBeInvoiced(clientId, companyFk, myOptions);
if (!clientCanBeInvoiced)
throw new UserError(`This client can't be invoiced`);
const vIsAllInvoiceable = false; const vIsAllInvoiceable = false;
await Self.rawSql('CALL ticketPackaging_add(?, ?, ?, ?)', [ await Self.rawSql('CALL ticketPackaging_add(?, ?, ?, ?)', [
clientId, clientId,
@ -71,9 +78,6 @@ module.exports = Self => {
AND t.shipped BETWEEN ? AND util.dayEnd(?) AND t.shipped BETWEEN ? AND util.dayEnd(?)
AND (t.clientFk = ? OR ? IS NULL ) AND (t.clientFk = ? OR ? IS NULL )
AND t.companyFk = ? AND t.companyFk = ?
AND c.hasToInvoice
AND c.isTaxDataChecked
AND c.isActive
AND NOT t.isDeleted AND NOT t.isDeleted
GROUP BY IF(c.hasToInvoiceByAddress, a.id, c.id) GROUP BY IF(c.hasToInvoiceByAddress, a.id, c.id)
HAVING SUM(t.totalWithVat) > 0;`; HAVING SUM(t.totalWithVat) > 0;`;

View File

@ -4,11 +4,11 @@ describe('InvoiceOut clientsToInvoice()', () => {
const userId = 1; const userId = 1;
const clientId = 1101; const clientId = 1101;
const companyFk = 442; const companyFk = 442;
const maxShipped = new Date(); const maxShipped = Date.vnNew();
maxShipped.setMonth(11); maxShipped.setMonth(11);
maxShipped.setDate(31); maxShipped.setDate(31);
maxShipped.setHours(23, 59, 59, 999); maxShipped.setHours(23, 59, 59, 999);
const invoiceDate = new Date(); const invoiceDate = Date.vnNew();
const activeCtx = { const activeCtx = {
getLocale: () => { getLocale: () => {
return 'en'; return 'en';

View File

@ -77,6 +77,8 @@ describe('ticket makeInvoice()', () => {
await tx.rollback(); await tx.rollback();
} }
expect(error.message).toEqual(`The address of the customer must have information about Incoterms and Customs Agent`); expect(error.message).toEqual(
`The address of the customer must have information about Incoterms and Customs Agent`
);
}); });
}); });