8179-testToMaster #3176
|
@ -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": {
|
||||||
|
|
|
@ -28,6 +28,10 @@
|
||||||
},
|
},
|
||||||
"continentFk": {
|
"continentFk": {
|
||||||
"type": "number"
|
"type": "number"
|
||||||
|
},
|
||||||
|
"hasDailyInvoice": {
|
||||||
|
"type": "boolean",
|
||||||
|
"description": "Indicates if the autonomy has daily invoice enabled"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"relations": {
|
"relations": {
|
||||||
|
|
|
@ -16,6 +16,9 @@
|
||||||
"name": {
|
"name": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"required": true
|
"required": true
|
||||||
|
},
|
||||||
|
"autonomyFk": {
|
||||||
|
"type": "number"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"relations": {
|
"relations": {
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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;
|
||||||
|
|
||||||
|
|
|
@ -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;
|
|
@ -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({
|
||||||
|
|
|
@ -1,5 +1,54 @@
|
||||||
const models = require('vn-loopback/server/server').models;
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
describe('Client Create', () => {
|
describe('Client Create', () => {
|
||||||
|
let options;
|
||||||
|
let tx;
|
||||||
|
|
||||||
|
beforeAll.mockLoopBackContext();
|
||||||
|
|
||||||
|
beforeEach(async() => {
|
||||||
|
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 {
|
||||||
|
const account = await models.VnUser.findOne({where: {name: 'deadpool'}}, options);
|
||||||
|
const client = await models.Client.findOne({where: {name: 'Wade'}}, options);
|
||||||
|
|
||||||
|
expect(account).toBeNull();
|
||||||
|
expect(client).toBeNull();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw an error when creating a new account without email', async() => {
|
||||||
|
let error;
|
||||||
|
const newAccountWithoutEmail = {
|
||||||
|
userName: 'deadpool',
|
||||||
|
fi: '16195279J',
|
||||||
|
name: 'Wade',
|
||||||
|
socialName: 'DEADPOOL MARVEL',
|
||||||
|
street: 'WALL STREET',
|
||||||
|
city: 'New York',
|
||||||
|
businessTypeFk: 'florist',
|
||||||
|
provinceFk: 1
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
await models.Client.createWithUser(newAccountWithoutEmail, options);
|
||||||
|
} catch (e) {
|
||||||
|
error = e;
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(error.message).toEqual('An email is necessary');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create a new account with dailyInvoice', async() => {
|
||||||
const newAccount = {
|
const newAccount = {
|
||||||
userName: 'deadpool',
|
userName: 'deadpool',
|
||||||
email: 'deadpool@marvel.com',
|
email: 'deadpool@marvel.com',
|
||||||
|
@ -11,57 +60,19 @@ describe('Client Create', () => {
|
||||||
businessTypeFk: 'florist',
|
businessTypeFk: 'florist',
|
||||||
provinceFk: 1
|
provinceFk: 1
|
||||||
};
|
};
|
||||||
const newAccountWithoutEmail = JSON.parse(JSON.stringify(newAccount));
|
|
||||||
delete newAccountWithoutEmail.email;
|
|
||||||
|
|
||||||
beforeAll.mockLoopBackContext();
|
|
||||||
|
|
||||||
it(`should not find deadpool as he's not created yet`, async() => {
|
|
||||||
const tx = await models.Client.beginTransaction({});
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const options = {transaction: tx};
|
const province = await models.Province.findById(newAccount.provinceFk, {
|
||||||
|
fields: ['id', 'name', 'autonomyFk'],
|
||||||
const account = await models.VnUser.findOne({where: {name: newAccount.userName}}, options);
|
include: {
|
||||||
const client = await models.Client.findOne({where: {name: newAccount.name}}, options);
|
relation: 'autonomy'
|
||||||
|
|
||||||
expect(account).toEqual(null);
|
|
||||||
expect(client).toEqual(null);
|
|
||||||
|
|
||||||
await tx.rollback();
|
|
||||||
} catch (e) {
|
|
||||||
await tx.rollback();
|
|
||||||
throw e;
|
|
||||||
}
|
}
|
||||||
});
|
}, options);
|
||||||
|
|
||||||
it('should not create a new account', async() => {
|
|
||||||
const tx = await models.Client.beginTransaction({});
|
|
||||||
|
|
||||||
let error;
|
|
||||||
try {
|
|
||||||
const options = {transaction: tx};
|
|
||||||
await models.Client.createWithUser(newAccountWithoutEmail, options);
|
|
||||||
|
|
||||||
await tx.rollback();
|
|
||||||
} catch (e) {
|
|
||||||
error = e.message;
|
|
||||||
|
|
||||||
await tx.rollback();
|
|
||||||
}
|
|
||||||
|
|
||||||
expect(error).toEqual(`An email is necessary`);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should create a new account', async() => {
|
|
||||||
const tx = await models.Client.beginTransaction({});
|
|
||||||
|
|
||||||
try {
|
|
||||||
const options = {transaction: tx};
|
|
||||||
|
|
||||||
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');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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 = ?
|
||||||
|
|
Loading…
Reference in New Issue