8179-testToMaster #3176

Merged
alexm merged 407 commits from 8179-testToMaster into master 2024-11-12 06:41:52 +00:00
10 changed files with 144 additions and 71 deletions
Showing only changes of commit be9f711cc1 - Show all commits

View File

@ -16,6 +16,10 @@
"name": { "name": {
"type": "string", "type": "string",
"required": true "required": true
},
"hasDailyInvoice": {
"type": "boolean",
"description": "Indicates if the autonomy has daily invoice enabled"
} }
}, },
"relations": { "relations": {
@ -40,4 +44,4 @@
"permission": "ALLOW" "permission": "ALLOW"
} }
] ]
} }

View File

@ -28,6 +28,10 @@
}, },
"continentFk": { "continentFk": {
"type": "number" "type": "number"
},
"hasDailyInvoice": {
"type": "boolean",
"description": "Indicates if the autonomy has daily invoice enabled"
} }
}, },
"relations": { "relations": {

View File

@ -16,6 +16,9 @@
"name": { "name": {
"type": "string", "type": "string",
"required": true "required": true
},
"autonomyFk": {
"type": "number"
} }
}, },
"relations": { "relations": {
@ -55,4 +58,4 @@
"permission": "ALLOW" "permission": "ALLOW"
} }
] ]
} }

View File

@ -34,22 +34,19 @@ BEGIN
DECLARE vIsTaxDataChecked TINYINT(1); DECLARE vIsTaxDataChecked TINYINT(1);
DECLARE vHasCoreVnl BOOLEAN; DECLARE vHasCoreVnl BOOLEAN;
DECLARE vMandateTypeFk INT; DECLARE vMandateTypeFk INT;
DECLARE vHasDailyInvoice BOOLEAN;
SELECT cc.defaultPayMethodFk, SELECT cc.defaultPayMethodFk,
cc.defaultDueDay, cc.defaultDueDay,
cc.defaultCredit, cc.defaultCredit,
cc.defaultIsTaxDataChecked, cc.defaultIsTaxDataChecked,
cc.defaultHasCoreVnl, cc.defaultHasCoreVnl,
cc.defaultMandateTypeFk, cc.defaultMandateTypeFk
c.hasDailyInvoice
INTO vPayMethodFk, INTO vPayMethodFk,
vDueDay, vDueDay,
vDefaultCredit, vDefaultCredit,
vIsTaxDataChecked, vIsTaxDataChecked,
vHasCoreVnl, vHasCoreVnl,
vMandateTypeFk, vMandateTypeFk
vHasDailyInvoice
FROM clientConfig cc FROM clientConfig cc
LEFT JOIN province p ON p.id = vProvinceFk LEFT JOIN province p ON p.id = vProvinceFk
LEFT JOIN country c ON c.id = p.countryFk; LEFT JOIN country c ON c.id = p.countryFk;
@ -70,8 +67,7 @@ BEGIN
credit = vDefaultCredit, credit = vDefaultCredit,
isTaxDataChecked = vIsTaxDataChecked, isTaxDataChecked = vIsTaxDataChecked,
hasCoreVnl = vHasCoreVnl, hasCoreVnl = vHasCoreVnl,
isEqualizated = FALSE, isEqualizated = FALSE
hasDailyInvoice = vHasDailyInvoice
ON duplicate KEY UPDATE ON duplicate KEY UPDATE
payMethodFk = vPayMethodFk, payMethodFk = vPayMethodFk,
dueDay = vDueDay, dueDay = vDueDay,

View File

@ -43,7 +43,7 @@ BEGIN
c.isTaxDataChecked, c.isTaxDataChecked,
t.companyFk, t.companyFk,
t.shipped, t.shipped,
IFNULL(a.hasDailyInvoice, co.hasDailyInvoice), c.hasDailyInvoice,
w.isManaged, w.isManaged,
c.hasToInvoice c.hasToInvoice
INTO vClientFk, INTO vClientFk,
@ -55,9 +55,6 @@ BEGIN
vHasToInvoice vHasToInvoice
FROM ticket t FROM ticket t
JOIN `client` c ON c.id = t.clientFk JOIN `client` c ON c.id = t.clientFk
JOIN province p ON p.id = c.provinceFk
LEFT JOIN autonomy a ON a.id = p.autonomyFk
JOIN country co ON co.id = p.countryFk
JOIN warehouse w ON w.id = t.warehouseFk JOIN warehouse w ON w.id = t.warehouseFk
WHERE t.id = vCurTicketFk; WHERE t.id = vCurTicketFk;
@ -85,7 +82,7 @@ BEGIN
IF(vHasDailyInvoice) AND vHasToInvoice THEN IF(vHasDailyInvoice) AND vHasToInvoice THEN
SELECT invoiceSerial(vClientFk, vCompanyFk, 'quick') INTO vSerial; SELECT invoiceSerial(vClientFk, vCompanyFk, 'quick') INTO vSerial;
IF vSerial IS NULL THEN IF vSerial IS NULL THEN
CALL util.throw('Cannot booking without a serial'); CALL util.throw('Cannot booking without a serial');
END IF; END IF;

View File

@ -0,0 +1,13 @@
UPDATE `vn`.`client` c
JOIN `vn`.`country` co ON co.id=c.countryFk
SET c.hasDailyInvoice = co.hasDailyInvoice
WHERE co.hasDailyInvoice IS NOT NULL
AND c.hasDailyInvoice = FALSE;
UPDATE `vn`.`client` c
JOIN `vn`.`province` p ON p.id=c.provinceFk
JOIN `vn`.`autonomy` a ON a.id = p.autonomyFk
SET c.hasDailyInvoice = a.hasDailyInvoice
WHERE a.hasDailyInvoice IS NOT NULL
AND c.hasDailyInvoice = FALSE;

View File

@ -43,6 +43,23 @@ module.exports = function(Self) {
}; };
try { try {
const province = await models.Province.findOne({
where: {id: data.provinceFk},
fields: ['autonomyFk']
});
const autonomy = province ? await models.Autonomy.findOne({
where: {id: province.autonomyFk},
fields: ['hasDailyInvoice']
}) : null;
const country = await models.Country.findOne({
where: {id: data.countryFk},
fields: ['hasDailyInvoice']
});
const hasDailyInvoice = (autonomy?.hasDailyInvoice ?? country?.hasDailyInvoice) || false;
const account = await models.VnUser.create(user, myOptions); const account = await models.VnUser.create(user, myOptions);
const client = await Self.create({ const client = await Self.create({
id: account.id, id: account.id,
@ -57,7 +74,8 @@ module.exports = function(Self) {
provinceFk: data.provinceFk, provinceFk: data.provinceFk,
countryFk: data.countryFk, countryFk: data.countryFk,
isEqualizated: data.isEqualizated, isEqualizated: data.isEqualizated,
businessTypeFk: data.businessTypeFk businessTypeFk: data.businessTypeFk,
hasDailyInvoice: hasDailyInvoice
}, myOptions); }, myOptions);
const address = await models.Address.create({ const address = await models.Address.create({

View File

@ -1,67 +1,78 @@
const models = require('vn-loopback/server/server').models; const models = require('vn-loopback/server/server').models;
describe('Client Create', () => { describe('Client Create', () => {
const newAccount = { let options;
userName: 'deadpool', let tx;
email: 'deadpool@marvel.com',
fi: '16195279J',
name: 'Wade',
socialName: 'DEADPOOL MARVEL',
street: 'WALL STREET',
city: 'New York',
businessTypeFk: 'florist',
provinceFk: 1
};
const newAccountWithoutEmail = JSON.parse(JSON.stringify(newAccount));
delete newAccountWithoutEmail.email;
beforeAll.mockLoopBackContext(); beforeAll.mockLoopBackContext();
it(`should not find deadpool as he's not created yet`, async() => { beforeEach(async() => {
const tx = await models.Client.beginTransaction({}); tx = await models.Client.beginTransaction({});
options = {transaction: tx};
});
afterEach(async() => await tx.rollback());
it('should not find deadpool as he is not created yet', async() => {
try { try {
const options = {transaction: tx}; const account = await models.VnUser.findOne({where: {name: 'deadpool'}}, options);
const client = await models.Client.findOne({where: {name: 'Wade'}}, options);
const account = await models.VnUser.findOne({where: {name: newAccount.userName}}, options); expect(account).toBeNull();
const client = await models.Client.findOne({where: {name: newAccount.name}}, options); expect(client).toBeNull();
expect(account).toEqual(null);
expect(client).toEqual(null);
await tx.rollback();
} catch (e) { } catch (e) {
await tx.rollback(); await tx.rollback();
throw e; throw e;
} }
}); });
it('should not create a new account', async() => { it('should throw an error when creating a new account without email', async() => {
const tx = await models.Client.beginTransaction({});
let error; let error;
const newAccountWithoutEmail = {
userName: 'deadpool',
fi: '16195279J',
name: 'Wade',
socialName: 'DEADPOOL MARVEL',
street: 'WALL STREET',
city: 'New York',
businessTypeFk: 'florist',
provinceFk: 1
};
try { try {
const options = {transaction: tx};
await models.Client.createWithUser(newAccountWithoutEmail, options); await models.Client.createWithUser(newAccountWithoutEmail, options);
await tx.rollback();
} catch (e) { } catch (e) {
error = e.message; error = e;
await tx.rollback();
} }
expect(error).toEqual(`An email is necessary`); expect(error.message).toEqual('An email is necessary');
}); });
it('should create a new account', async() => { it('should create a new account with dailyInvoice', async() => {
const tx = await models.Client.beginTransaction({}); const newAccount = {
userName: 'deadpool',
email: 'deadpool@marvel.com',
fi: '16195279J',
name: 'Wade',
socialName: 'DEADPOOL MARVEL',
street: 'WALL STREET',
city: 'New York',
businessTypeFk: 'florist',
provinceFk: 1
};
try { try {
const options = {transaction: tx}; const province = await models.Province.findById(newAccount.provinceFk, {
fields: ['id', 'name', 'autonomyFk'],
include: {
relation: 'autonomy'
}
}, options);
const client = await models.Client.createWithUser(newAccount, options); const client = await models.Client.createWithUser(newAccount, options);
const account = await models.VnUser.findOne({where: {name: newAccount.userName}}, options); const account = await models.VnUser.findOne({where: {name: newAccount.userName}}, options);
expect(province.autonomy().hasDailyInvoice).toBeTruthy();
expect(account.name).toEqual(newAccount.userName); expect(account.name).toEqual(newAccount.userName);
expect(client.id).toEqual(account.id); expect(client.id).toEqual(account.id);
expect(client.name).toEqual(newAccount.name); expect(client.name).toEqual(newAccount.name);
@ -69,8 +80,38 @@ describe('Client Create', () => {
expect(client.fi).toEqual(newAccount.fi); expect(client.fi).toEqual(newAccount.fi);
expect(client.socialName).toEqual(newAccount.socialName); expect(client.socialName).toEqual(newAccount.socialName);
expect(client.businessTypeFk).toEqual(newAccount.businessTypeFk); expect(client.businessTypeFk).toEqual(newAccount.businessTypeFk);
expect(client.hasDailyInvoice).toBeTruthy();
} catch (e) {
await tx.rollback(); await tx.rollback();
throw e;
}
});
it('should create a new account without dailyInvoice', async() => {
const newAccount = {
userName: 'deadpool',
email: 'deadpool@marvel.com',
fi: '16195279J',
name: 'Wade',
socialName: 'DEADPOOL MARVEL',
street: 'WALL STREET',
city: 'New York',
businessTypeFk: 'florist',
provinceFk: 3
};
try {
const province = await models.Province.findById(newAccount.provinceFk, {
fields: ['id', 'name', 'autonomyFk'],
include: {
relation: 'autonomy'
}
}, options);
const client = await models.Client.createWithUser(newAccount, options);
expect(province.autonomy.hasDailyInvoice).toBeFalsy();
expect(client.hasDailyInvoice).toBeFalsy();
} catch (e) { } catch (e) {
await tx.rollback(); await tx.rollback();
throw e; throw e;
@ -78,26 +119,25 @@ describe('Client Create', () => {
}); });
it('should not be able to create a user if exists', async() => { it('should not be able to create a user if exists', async() => {
const tx = await models.Client.beginTransaction({});
let error; let error;
const newAccount = {
userName: 'deadpool',
email: 'deadpool@marvel.com',
fi: '16195279J',
name: 'Wade',
socialName: 'DEADPOOL MARVEL',
street: 'WALL STREET',
city: 'New York',
businessTypeFk: 'florist',
provinceFk: 1
};
try { try {
const options = {transaction: tx};
await models.Client.createWithUser(newAccount, options); await models.Client.createWithUser(newAccount, options);
const client = await models.Client.createWithUser(newAccount, options); await models.Client.createWithUser(newAccount, options);
expect(client).toBeNull();
await tx.rollback();
} catch (e) { } catch (e) {
await tx.rollback();
error = e; error = e;
} }
const errorName = error.details.codes.name[0]; expect(error.message).toContain('already exists');
expect(errorName).toEqual('uniqueness');
}); });
}); });

View File

@ -46,7 +46,7 @@ module.exports = Self => {
c.salesPersonFk, c.salesPersonFk,
c.isToBeMailed, c.isToBeMailed,
c.hasToInvoice, c.hasToInvoice,
co.hasDailyInvoice, c.hasDailyInvoice,
eu.email salesPersonEmail, eu.email salesPersonEmail,
t.addressFk t.addressFk
FROM ticket t FROM ticket t
@ -125,7 +125,7 @@ module.exports = Self => {
WHERE (al.code = 'PACKED' OR (am.code = 'refund' AND al.code <> 'delivered')) WHERE (al.code = 'PACKED' OR (am.code = 'refund' AND al.code <> 'delivered'))
AND t.shipped BETWEEN ? - INTERVAL tc.closureDaysAgo DAY AND util.dayEnd(?) AND t.shipped BETWEEN ? - INTERVAL tc.closureDaysAgo DAY AND util.dayEnd(?)
AND t.refFk IS NULL AND t.refFk IS NULL
AND IFNULL(a.hasDailyInvoice, co.hasDailyInvoice) AND c.hasDailyInvoice
GROUP BY ticketFk GROUP BY ticketFk
HAVING hasErrorToInvoice HAVING hasErrorToInvoice
OR hasErrorTaxDataChecked OR hasErrorTaxDataChecked

View File

@ -50,7 +50,7 @@ module.exports = Self => {
c.salesPersonFk, c.salesPersonFk,
c.isToBeMailed, c.isToBeMailed,
c.hasToInvoice, c.hasToInvoice,
co.hasDailyInvoice, c.hasDailyInvoice,
eu.email salesPersonEmail, eu.email salesPersonEmail,
t.addressFk t.addressFk
FROM expedition e FROM expedition e
@ -58,8 +58,6 @@ module.exports = Self => {
JOIN ticketState ts ON ts.ticketFk = t.id JOIN ticketState ts ON ts.ticketFk = t.id
JOIN alertLevel al ON al.id = ts.alertLevel JOIN alertLevel al ON al.id = ts.alertLevel
JOIN client c ON c.id = t.clientFk JOIN client c ON c.id = t.clientFk
JOIN province p ON p.id = c.provinceFk
JOIN country co ON co.id = p.countryFk
LEFT JOIN account.emailUser eu ON eu.userFk = c.salesPersonFk LEFT JOIN account.emailUser eu ON eu.userFk = c.salesPersonFk
WHERE al.code = 'PACKED' WHERE al.code = 'PACKED'
AND t.id = ? AND t.id = ?