diff --git a/loopback/locale/en.json b/loopback/locale/en.json index 80da13ae5..8d5eab4bc 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -211,6 +211,7 @@ "Name should be uppercase": "Name should be uppercase", "You cannot update these fields": "You cannot update these fields", "CountryFK cannot be empty": "Country cannot be empty", + "No tickets to invoice": "There are no tickets to invoice that meet the invoicing requirements", "You are not allowed to modify the alias": "You are not allowed to modify the alias", "You already have the mailAlias": "You already have the mailAlias", "This machine is already in use.": "This machine is already in use.", @@ -251,4 +252,4 @@ "Price cannot be blank": "Price cannot be blank", "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" -} \ No newline at end of file +} diff --git a/loopback/locale/es.json b/loopback/locale/es.json index fcee0e111..cde81e0cb 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -339,7 +339,7 @@ "Incorrect pin": "Pin incorrecto.", "You already have the mailAlias": "Ya tienes este alias de correo", "The alias cant be modified": "Este alias de correo no puede ser modificado", - "No tickets to invoice": "No hay tickets para facturar", + "No tickets to invoice": "No hay tickets para facturar que cumplan los requisitos de facturación", "this warehouse has not dms": "El Almacén no acepta documentos", "This ticket already has a cmr saved": "Este ticket ya tiene un cmr guardado", "Name should be uppercase": "El nombre debe ir en mayúscula", diff --git a/loopback/locale/fr.json b/loopback/locale/fr.json index 9941358be..f49196a8f 100644 --- a/loopback/locale/fr.json +++ b/loopback/locale/fr.json @@ -339,7 +339,7 @@ "Incorrect pin": "Pin incorrect.", "You already have the mailAlias": "Vous avez déjà cet alias de courrier", "The alias cant be modified": "Cet alias de courrier ne peut pas être modifié", - "No tickets to invoice": "Pas de tickets à facturer", + "No tickets to invoice": "Il n'y a pas de tickets à facturer qui répondent aux exigences de facturation", "this warehouse has not dms": "L'entrepôt n'accepte pas les documents", "This ticket already has a cmr saved": "Ce ticket a déjà un cmr enregistré", "Name should be uppercase": "Le nom doit être en majuscules", diff --git a/loopback/locale/pt.json b/loopback/locale/pt.json index e84b30f3d..e2374d35f 100644 --- a/loopback/locale/pt.json +++ b/loopback/locale/pt.json @@ -339,7 +339,7 @@ "Incorrect pin": "PIN incorreto.", "You already have the mailAlias": "Você já tem o alias de e-mail", "The alias cant be modified": "O alias não pode ser modificado", - "No tickets to invoice": "Não há tickets para faturar", + "No tickets to invoice": "Não há bilhetes para faturar que atendam aos requisitos de faturamento", "this warehouse has not dms": "Este armazém não tem DMS", "This ticket already has a cmr saved": "Este ticket já tem um CMR salvo", "Name should be uppercase": "O nome deve estar em maiúsculas", diff --git a/modules/invoiceOut/back/methods/invoiceOut/clientsToInvoice.js b/modules/invoiceOut/back/methods/invoiceOut/clientsToInvoice.js index 7befdcbeb..f66221409 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/clientsToInvoice.js +++ b/modules/invoiceOut/back/methods/invoiceOut/clientsToInvoice.js @@ -49,12 +49,6 @@ module.exports = Self => { } try { - 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; await Self.rawSql('CALL ticketPackaging_add(?, ?, ?, ?)', [ clientId, diff --git a/modules/invoiceOut/back/methods/invoiceOut/specs/clientsToInvoice.spec.js b/modules/invoiceOut/back/methods/invoiceOut/specs/clientsToInvoice.spec.js index df0566c54..6e536f433 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/specs/clientsToInvoice.spec.js +++ b/modules/invoiceOut/back/methods/invoiceOut/specs/clientsToInvoice.spec.js @@ -1,4 +1,5 @@ const models = require('vn-loopback/server/server').models; +const LoopBackContext = require('loopback-context'); describe('InvoiceOut clientsToInvoice()', () => { const userId = 1; @@ -20,6 +21,21 @@ describe('InvoiceOut clientsToInvoice()', () => { headers: {origin: 'http://localhost'} }; const ctx = {req: activeCtx}; + let tx; + let options; + + beforeEach(async() => { + LoopBackContext.getCurrentContext = () => ({ + active: activeCtx, + }); + + tx = await models.InvoiceOut.beginTransaction({}); + options = {transaction: tx}; + }); + + afterEach(async() => { + await tx.rollback(); + }); it('should return a list of clients to invoice', async() => { spyOn(models.InvoiceOut, 'rawSql').and.callFake(query => { @@ -37,24 +53,14 @@ describe('InvoiceOut clientsToInvoice()', () => { } }); - const tx = await models.InvoiceOut.beginTransaction({}); - const options = {transaction: tx}; + const addresses = await models.InvoiceOut.clientsToInvoice( + ctx, clientId, invoiceDate, maxShipped, companyFk, options); - try { - const addresses = await models.InvoiceOut.clientsToInvoice( - ctx, clientId, invoiceDate, maxShipped, companyFk, options); - - expect(addresses.length).toBeGreaterThan(0); - expect(addresses[0].clientId).toBe(clientId); - expect(addresses[0].clientName).toBe('Test Client'); - expect(addresses[0].id).toBe(1); - expect(addresses[0].nickname).toBe('Address 1'); - - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } + expect(addresses.length).toBeGreaterThan(0); + expect(addresses[0].clientId).toBe(clientId); + expect(addresses[0].clientName).toBe('Test Client'); + expect(addresses[0].id).toBe(1); + expect(addresses[0].nickname).toBe('Address 1'); }); it('should handle errors and rollback transaction', async() => { @@ -62,14 +68,20 @@ describe('InvoiceOut clientsToInvoice()', () => { return Promise.reject(new Error('Test Error')); }); - const tx = await models.InvoiceOut.beginTransaction({}); - const options = {transaction: tx}; - try { await models.InvoiceOut.clientsToInvoice(ctx, clientId, invoiceDate, maxShipped, companyFk, options); } catch (e) { expect(e.message).toBe('Test Error'); - await tx.rollback(); } }); + + it('should return all list', async() => { + const minShipped = Date.vnNew(); + minShipped.setFullYear(maxShipped.getFullYear() - 1); + + const toInvoice = await models.InvoiceOut.clientsToInvoice( + ctx, null, invoiceDate, maxShipped, companyFk, options); + + expect(toInvoice).toBeDefined(); + }); });