fix: canBeInvoiced only in makeInvoice
gitea/salix/pipeline/head This commit looks good Details
gitea/salix/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Alex Moreno 2025-01-13 09:18:46 +01:00
parent 5ce23ee122
commit 9d05b16404
6 changed files with 38 additions and 31 deletions

View File

@ -211,6 +211,7 @@
"Name should be uppercase": "Name should be uppercase", "Name should be uppercase": "Name should be uppercase",
"You cannot update these fields": "You cannot update these fields", "You cannot update these fields": "You cannot update these fields",
"CountryFK cannot be empty": "Country cannot be empty", "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 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", "You already have the mailAlias": "You already have the mailAlias",
"This machine is already in use.": "This machine is already in use.", "This machine is already in use.": "This machine is already in use.",
@ -251,4 +252,4 @@
"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" "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

@ -339,7 +339,7 @@
"Incorrect pin": "Pin incorrecto.", "Incorrect pin": "Pin incorrecto.",
"You already have the mailAlias": "Ya tienes este alias de correo", "You already have the mailAlias": "Ya tienes este alias de correo",
"The alias cant be modified": "Este alias de correo no puede ser modificado", "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 warehouse has not dms": "El Almacén no acepta documentos",
"This ticket already has a cmr saved": "Este ticket ya tiene un cmr guardado", "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", "Name should be uppercase": "El nombre debe ir en mayúscula",

View File

@ -339,7 +339,7 @@
"Incorrect pin": "Pin incorrect.", "Incorrect pin": "Pin incorrect.",
"You already have the mailAlias": "Vous avez déjà cet alias de courrier", "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é", "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 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é", "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", "Name should be uppercase": "Le nom doit être en majuscules",

View File

@ -339,7 +339,7 @@
"Incorrect pin": "PIN incorreto.", "Incorrect pin": "PIN incorreto.",
"You already have the mailAlias": "Você já tem o alias de e-mail", "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", "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 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", "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", "Name should be uppercase": "O nome deve estar em maiúsculas",

View File

@ -49,12 +49,6 @@ module.exports = Self => {
} }
try { 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; const vIsAllInvoiceable = false;
await Self.rawSql('CALL ticketPackaging_add(?, ?, ?, ?)', [ await Self.rawSql('CALL ticketPackaging_add(?, ?, ?, ?)', [
clientId, clientId,

View File

@ -1,4 +1,5 @@
const models = require('vn-loopback/server/server').models; const models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context');
describe('InvoiceOut clientsToInvoice()', () => { describe('InvoiceOut clientsToInvoice()', () => {
const userId = 1; const userId = 1;
@ -20,6 +21,21 @@ describe('InvoiceOut clientsToInvoice()', () => {
headers: {origin: 'http://localhost'} headers: {origin: 'http://localhost'}
}; };
const ctx = {req: activeCtx}; 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() => { it('should return a list of clients to invoice', async() => {
spyOn(models.InvoiceOut, 'rawSql').and.callFake(query => { spyOn(models.InvoiceOut, 'rawSql').and.callFake(query => {
@ -37,24 +53,14 @@ describe('InvoiceOut clientsToInvoice()', () => {
} }
}); });
const tx = await models.InvoiceOut.beginTransaction({}); const addresses = await models.InvoiceOut.clientsToInvoice(
const options = {transaction: tx}; ctx, clientId, invoiceDate, maxShipped, companyFk, options);
try { expect(addresses.length).toBeGreaterThan(0);
const addresses = await models.InvoiceOut.clientsToInvoice( expect(addresses[0].clientId).toBe(clientId);
ctx, clientId, invoiceDate, maxShipped, companyFk, options); expect(addresses[0].clientName).toBe('Test Client');
expect(addresses[0].id).toBe(1);
expect(addresses.length).toBeGreaterThan(0); expect(addresses[0].nickname).toBe('Address 1');
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;
}
}); });
it('should handle errors and rollback transaction', async() => { it('should handle errors and rollback transaction', async() => {
@ -62,14 +68,20 @@ describe('InvoiceOut clientsToInvoice()', () => {
return Promise.reject(new Error('Test Error')); return Promise.reject(new Error('Test Error'));
}); });
const tx = await models.InvoiceOut.beginTransaction({});
const options = {transaction: tx};
try { try {
await models.InvoiceOut.clientsToInvoice(ctx, clientId, invoiceDate, maxShipped, companyFk, options); await models.InvoiceOut.clientsToInvoice(ctx, clientId, invoiceDate, maxShipped, companyFk, options);
} catch (e) { } catch (e) {
expect(e.message).toBe('Test Error'); 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();
});
}); });