Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into dev
This commit is contained in:
commit
c13253dcc2
|
@ -58,6 +58,35 @@ describe('Client Edit fiscalData path', () => {
|
||||||
.accessToSection('client.card.fiscalData');
|
.accessToSection('client.card.fiscalData');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should receive an error if VIES and EQtax are being ticked together', async() => {
|
||||||
|
const result = await nightmare
|
||||||
|
.wait(selectors.clientFiscalData.socialNameInput)
|
||||||
|
.clearInput(selectors.clientFiscalData.socialNameInput)
|
||||||
|
.write(selectors.clientFiscalData.socialNameInput, 'SMASH!')
|
||||||
|
.clearInput(selectors.clientFiscalData.fiscalIdInput)
|
||||||
|
.write(selectors.clientFiscalData.fiscalIdInput, '94980061C')
|
||||||
|
.clearInput(selectors.clientFiscalData.addressInput)
|
||||||
|
.write(selectors.clientFiscalData.addressInput, 'Somewhere edited')
|
||||||
|
.clearInput(selectors.clientFiscalData.postcodeInput)
|
||||||
|
.write(selectors.clientFiscalData.postcodeInput, '12345')
|
||||||
|
.clearInput(selectors.clientFiscalData.cityInput)
|
||||||
|
.write(selectors.clientFiscalData.cityInput, 'N/A')
|
||||||
|
.autocompleteSearch(selectors.clientFiscalData.countryAutocomplete, 'Francia')
|
||||||
|
.autocompleteSearch(selectors.clientFiscalData.provinceAutocomplete, 'Province two')
|
||||||
|
.waitToClick(selectors.clientFiscalData.activeCheckbox)
|
||||||
|
.waitToClick(selectors.clientFiscalData.frozenCheckbox)
|
||||||
|
.waitToClick(selectors.clientFiscalData.hasToInvoiceCheckbox)
|
||||||
|
.waitToClick(selectors.clientFiscalData.viesCheckbox)
|
||||||
|
.waitToClick(selectors.clientFiscalData.invoiceByMailCheckbox)
|
||||||
|
.waitToClick(selectors.clientFiscalData.invoiceByAddressCheckbox)
|
||||||
|
.waitToClick(selectors.clientFiscalData.equalizationTaxCheckbox)
|
||||||
|
.waitToClick(selectors.clientFiscalData.verifiedDataCheckbox)
|
||||||
|
.waitToClick(selectors.clientFiscalData.saveButton)
|
||||||
|
.waitForLastSnackbar();
|
||||||
|
|
||||||
|
expect(result).toEqual('Data saved!');
|
||||||
|
}, 15000);
|
||||||
|
|
||||||
it('should receive an error if the fiscal id contains A or B at the beginning', async() => {
|
it('should receive an error if the fiscal id contains A or B at the beginning', async() => {
|
||||||
const result = await nightmare
|
const result = await nightmare
|
||||||
.waitToClick(selectors.clientFiscalData.viesCheckbox)
|
.waitToClick(selectors.clientFiscalData.viesCheckbox)
|
||||||
|
|
|
@ -12,6 +12,10 @@ module.exports = function(Self) {
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.observe('before save', async function(ctx) {
|
Self.observe('before save', async function(ctx) {
|
||||||
|
let options = {};
|
||||||
|
if (ctx.options && ctx.options.transaction)
|
||||||
|
options.transaction = ctx.options.transaction;
|
||||||
|
|
||||||
let oldInstance;
|
let oldInstance;
|
||||||
let oldInstanceFk;
|
let oldInstanceFk;
|
||||||
let newInstance;
|
let newInstance;
|
||||||
|
@ -22,7 +26,7 @@ module.exports = function(Self) {
|
||||||
oldInstance = await fkToValue(oldInstanceFk, ctx);
|
oldInstance = await fkToValue(oldInstanceFk, ctx);
|
||||||
if (ctx.where && !ctx.currentInstance) {
|
if (ctx.where && !ctx.currentInstance) {
|
||||||
let fields = Object.keys(ctx.data);
|
let fields = Object.keys(ctx.data);
|
||||||
ctx.oldInstances = await ctx.Model.app.models[ctx.Model.definition.name].find({where: ctx.where, fields: fields});
|
ctx.oldInstances = await ctx.Model.app.models[ctx.Model.definition.name].find({where: ctx.where, fields: fields}, options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ctx.isNewInstance)
|
if (ctx.isNewInstance)
|
||||||
|
@ -33,10 +37,14 @@ module.exports = function(Self) {
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.observe('before delete', async function(ctx) {
|
Self.observe('before delete', async function(ctx) {
|
||||||
|
let options = {};
|
||||||
|
if (ctx.options && ctx.options.transaction)
|
||||||
|
options.transaction = ctx.options.transaction;
|
||||||
|
|
||||||
if (ctx.where) {
|
if (ctx.where) {
|
||||||
let affectedModel = ctx.Model.definition.name;
|
let affectedModel = ctx.Model.definition.name;
|
||||||
let definition = ctx.Model.definition;
|
let definition = ctx.Model.definition;
|
||||||
let deletedInstances = await ctx.Model.app.models[affectedModel].find({where: ctx.where});
|
let deletedInstances = await ctx.Model.app.models[affectedModel].find({where: ctx.where}, options);
|
||||||
let relation = definition.settings.log.relation;
|
let relation = definition.settings.log.relation;
|
||||||
|
|
||||||
if (relation) {
|
if (relation) {
|
||||||
|
@ -61,6 +69,10 @@ module.exports = function(Self) {
|
||||||
});
|
});
|
||||||
|
|
||||||
async function logDeletedInstances(ctx, loopBackContext) {
|
async function logDeletedInstances(ctx, loopBackContext) {
|
||||||
|
let options = {};
|
||||||
|
if (ctx.options && ctx.options.transaction)
|
||||||
|
options.transaction = ctx.options.transaction;
|
||||||
|
|
||||||
ctx.hookState.oldInstance.forEach(async instance => {
|
ctx.hookState.oldInstance.forEach(async instance => {
|
||||||
let userFk;
|
let userFk;
|
||||||
if (loopBackContext)
|
if (loopBackContext)
|
||||||
|
@ -80,16 +92,16 @@ module.exports = function(Self) {
|
||||||
newInstance: {}
|
newInstance: {}
|
||||||
};
|
};
|
||||||
|
|
||||||
let transaction = {};
|
|
||||||
if (ctx.options && ctx.options.transaction)
|
|
||||||
transaction = ctx.options.transaction;
|
|
||||||
|
|
||||||
let logModel = definition.settings.log.model;
|
let logModel = definition.settings.log.model;
|
||||||
await ctx.Model.app.models[logModel].create(logRecord, transaction);
|
await ctx.Model.app.models[logModel].create(logRecord, options);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fkToValue(instance, ctx) {
|
async function fkToValue(instance, ctx) {
|
||||||
|
let options = {};
|
||||||
|
if (ctx.options && ctx.options.transaction)
|
||||||
|
options.transaction = ctx.options.transaction;
|
||||||
|
|
||||||
let cleanInstance = JSON.parse(JSON.stringify(instance));
|
let cleanInstance = JSON.parse(JSON.stringify(instance));
|
||||||
let result = {};
|
let result = {};
|
||||||
for (let key in cleanInstance) {
|
for (let key in cleanInstance) {
|
||||||
|
@ -98,8 +110,11 @@ module.exports = function(Self) {
|
||||||
for (let key1 in ctx.Model.relations) {
|
for (let key1 in ctx.Model.relations) {
|
||||||
let val1 = ctx.Model.relations[key1];
|
let val1 = ctx.Model.relations[key1];
|
||||||
if (val1.keyFrom == key && key != 'id') {
|
if (val1.keyFrom == key && key != 'id') {
|
||||||
let recordSet = await val1.modelTo.findById(val);
|
let recordSet = await ctx.Model.app.models[val1.modelTo.modelName].findById(val, options);
|
||||||
val = recordSet.name; // FIXME preparar todos los modelos con campo name
|
let definition = val1.modelTo.definition;
|
||||||
|
let changedModelValue = definition.settings.log && definition.settings.log.changedModelValue;
|
||||||
|
|
||||||
|
val = (changedModelValue && recordSet && recordSet[changedModelValue]) || (recordSet && recordSet.id) || val; // FIXME preparar todos los modelos con campo name
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -109,6 +124,10 @@ module.exports = function(Self) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function logInModel(ctx, loopBackContext) {
|
async function logInModel(ctx, loopBackContext) {
|
||||||
|
let options = {};
|
||||||
|
if (ctx.options && ctx.options.transaction)
|
||||||
|
options.transaction = ctx.options.transaction;
|
||||||
|
|
||||||
let definition = ctx.Model.definition;
|
let definition = ctx.Model.definition;
|
||||||
let primaryKey;
|
let primaryKey;
|
||||||
for (let property in definition.properties) {
|
for (let property in definition.properties) {
|
||||||
|
@ -143,10 +162,11 @@ module.exports = function(Self) {
|
||||||
|
|
||||||
// Sets the changedModelValue to save and the instances changed in case its an updateAll
|
// Sets the changedModelValue to save and the instances changed in case its an updateAll
|
||||||
let changedModelValue = definition.settings.log.changedModelValue;
|
let changedModelValue = definition.settings.log.changedModelValue;
|
||||||
|
let where;
|
||||||
if (changedModelValue && (!ctx.instance || !ctx.instance[changedModelValue])) {
|
if (changedModelValue && (!ctx.instance || !ctx.instance[changedModelValue])) {
|
||||||
var where = [];
|
|
||||||
changedModelId = [];
|
changedModelId = [];
|
||||||
let changedInstances = await ctx.Model.app.models[definition.name].find({where: ctx.where, fields: ['id', changedModelValue]});
|
where = [];
|
||||||
|
let changedInstances = await ctx.Model.app.models[definition.name].find({where: ctx.where, fields: ['id', changedModelValue]}, options);
|
||||||
changedInstances.forEach(element => {
|
changedInstances.forEach(element => {
|
||||||
where.push(element[changedModelValue]);
|
where.push(element[changedModelValue]);
|
||||||
changedModelId.push(element.id);
|
changedModelId.push(element.id);
|
||||||
|
@ -185,11 +205,7 @@ module.exports = function(Self) {
|
||||||
|
|
||||||
let logModel = definition.settings.log.model;
|
let logModel = definition.settings.log.model;
|
||||||
|
|
||||||
let transaction = {};
|
await ctx.Model.app.models[logModel].create(logsToSave, options);
|
||||||
if (ctx.options && ctx.options.transaction)
|
|
||||||
transaction = ctx.options.transaction;
|
|
||||||
|
|
||||||
await ctx.Model.app.models[logModel].create(logsToSave, transaction);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// this function retuns all the instances changed in case this is an updateAll
|
// this function retuns all the instances changed in case this is an updateAll
|
||||||
|
|
Loading…
Reference in New Issue