Merge pull request 'feat: refs #8167 update canBeInvoiced method to include active status check and improve test cases' (!3323) from 8167-incoiceOutCheckIsActive into dev
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
Reviewed-on: #3323 Reviewed-by: Jorge Penadés <jorgep@verdnatura.es>
This commit is contained in:
commit
be50c91299
|
@ -249,5 +249,6 @@
|
||||||
"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"
|
||||||
}
|
}
|
|
@ -2,7 +2,7 @@ const UserError = require('vn-loopback/util/user-error');
|
||||||
|
|
||||||
module.exports = function(Self) {
|
module.exports = function(Self) {
|
||||||
Self.remoteMethod('canBeInvoiced', {
|
Self.remoteMethod('canBeInvoiced', {
|
||||||
description: 'Change property isEqualizated in all client addresses',
|
description: 'Check if a client can be invoiced',
|
||||||
accessType: 'READ',
|
accessType: 'READ',
|
||||||
accepts: [
|
accepts: [
|
||||||
{
|
{
|
||||||
|
@ -38,7 +38,7 @@ module.exports = function(Self) {
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
const client = await models.Client.findById(id, {
|
const client = await models.Client.findById(id, {
|
||||||
fields: ['id', 'isTaxDataChecked', 'hasToInvoice', 'payMethodFk'],
|
fields: ['id', 'isTaxDataChecked', 'hasToInvoice', 'payMethodFk', 'isActive'],
|
||||||
include:
|
include:
|
||||||
{
|
{
|
||||||
relation: 'payMethod',
|
relation: 'payMethod',
|
||||||
|
@ -53,9 +53,6 @@ module.exports = function(Self) {
|
||||||
if (client.payMethod().code === 'wireTransfer' && !company.supplierAccountFk)
|
if (client.payMethod().code === 'wireTransfer' && !company.supplierAccountFk)
|
||||||
throw new UserError('The company has not informed the supplier account for bank transfers');
|
throw new UserError('The company has not informed the supplier account for bank transfers');
|
||||||
|
|
||||||
if (client.isTaxDataChecked && client.hasToInvoice)
|
return client.isTaxDataChecked && client.hasToInvoice && client.isActive;
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,6 +8,8 @@ describe('client canBeInvoiced()', () => {
|
||||||
const activeCtx = {
|
const activeCtx = {
|
||||||
accessToken: {userId: userId}
|
accessToken: {userId: userId}
|
||||||
};
|
};
|
||||||
|
let tx;
|
||||||
|
let options;
|
||||||
|
|
||||||
beforeAll(async() => {
|
beforeAll(async() => {
|
||||||
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
||||||
|
@ -15,60 +17,45 @@ describe('client canBeInvoiced()', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
beforeEach(async() => {
|
||||||
|
tx = await models.Client.beginTransaction({});
|
||||||
|
options = {transaction: tx};
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(async() => {
|
||||||
|
await tx.rollback();
|
||||||
|
});
|
||||||
|
|
||||||
it('should return falsy for a client without the data checked', async() => {
|
it('should return falsy for a client without the data checked', async() => {
|
||||||
const tx = await models.Client.beginTransaction({});
|
|
||||||
|
|
||||||
try {
|
|
||||||
const options = {transaction: tx};
|
|
||||||
|
|
||||||
const client = await models.Client.findById(clientId, null, options);
|
const client = await models.Client.findById(clientId, null, options);
|
||||||
await client.updateAttribute('isTaxDataChecked', false, options);
|
await client.updateAttribute('isTaxDataChecked', false, options);
|
||||||
|
|
||||||
const canBeInvoiced = await models.Client.canBeInvoiced(clientId, companyId, options);
|
const canBeInvoiced = await models.Client.canBeInvoiced(clientId, companyId, options);
|
||||||
|
|
||||||
expect(canBeInvoiced).toEqual(false);
|
expect(canBeInvoiced).toEqual(false);
|
||||||
|
});
|
||||||
|
|
||||||
await tx.rollback();
|
it('should return falsy for a client not active', async() => {
|
||||||
} catch (e) {
|
const client = await models.Client.findById(clientId, null, options);
|
||||||
await tx.rollback();
|
await client.updateAttribute('isActive', false, options);
|
||||||
throw e;
|
|
||||||
}
|
const canBeInvoiced = await models.Client.canBeInvoiced(clientId, companyId, options);
|
||||||
|
|
||||||
|
expect(canBeInvoiced).toEqual(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return falsy for a client with invoicing disabled', async() => {
|
it('should return falsy for a client with invoicing disabled', async() => {
|
||||||
const tx = await models.Client.beginTransaction({});
|
|
||||||
|
|
||||||
try {
|
|
||||||
const options = {transaction: tx};
|
|
||||||
|
|
||||||
const client = await models.Client.findById(clientId, null, options);
|
const client = await models.Client.findById(clientId, null, options);
|
||||||
await client.updateAttribute('hasToInvoice', false, options);
|
await client.updateAttribute('hasToInvoice', false, options);
|
||||||
|
|
||||||
const canBeInvoiced = await models.Client.canBeInvoiced(clientId, companyId, options);
|
const canBeInvoiced = await models.Client.canBeInvoiced(clientId, companyId, options);
|
||||||
|
|
||||||
expect(canBeInvoiced).toEqual(false);
|
expect(canBeInvoiced).toEqual(false);
|
||||||
|
|
||||||
await tx.rollback();
|
|
||||||
} catch (e) {
|
|
||||||
await tx.rollback();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return truthy for an invoiceable client', async() => {
|
it('should return truthy for an invoiceable client', async() => {
|
||||||
const tx = await models.Client.beginTransaction({});
|
|
||||||
|
|
||||||
try {
|
|
||||||
const options = {transaction: tx};
|
|
||||||
|
|
||||||
const canBeInvoiced = await models.Client.canBeInvoiced(clientId, companyId, options);
|
const canBeInvoiced = await models.Client.canBeInvoiced(clientId, companyId, options);
|
||||||
|
|
||||||
expect(canBeInvoiced).toEqual(true);
|
expect(canBeInvoiced).toEqual(true);
|
||||||
|
|
||||||
await tx.rollback();
|
|
||||||
} catch (e) {
|
|
||||||
await tx.rollback();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -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;`;
|
||||||
|
|
|
@ -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';
|
||||||
|
|
|
@ -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`
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue