fix: refs #6942 add test & change column name
gitea/salix/pipeline/pr-dev This commit looks good
Details
gitea/salix/pipeline/pr-dev This commit looks good
Details
This commit is contained in:
parent
8b29152c00
commit
58635b5468
|
@ -80,8 +80,11 @@
|
||||||
"enlazado": {
|
"enlazado": {
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
"CLAVE": {
|
"key": {
|
||||||
"type": "number"
|
"type": "number",
|
||||||
|
"mysql": {
|
||||||
|
"columnName": "CLAVE"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"relations": {
|
"relations": {
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
|
describe('invoiceIn toUnbook()', () => {
|
||||||
|
it('should check that invoiceIn is unbooked', async() => {
|
||||||
|
const userId = 1;
|
||||||
|
const ctx = {
|
||||||
|
req: {
|
||||||
|
|
||||||
|
accessToken: {userId: userId},
|
||||||
|
headers: {origin: 'http://localhost:5000'},
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const invoiceInId = 1;
|
||||||
|
const tx = await models.InvoiceIn.beginTransaction({});
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
try {
|
||||||
|
await models.InvoiceIn.toBook(ctx, invoiceInId, options);
|
||||||
|
const bookEntry = await models.InvoiceIn.toUnbook(ctx, invoiceInId, options);
|
||||||
|
const invoiceIn = await models.InvoiceIn.findById(invoiceInId, null, options);
|
||||||
|
|
||||||
|
expect(bookEntry.accountingEntries).toEqual(4);
|
||||||
|
expect(bookEntry.isLinked).toBeFalsy();
|
||||||
|
expect(invoiceIn.isBooked).toEqual(false);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
|
@ -19,7 +19,7 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.toUnbook = async(ctx, id, options) => {
|
Self.toUnbook = async(ctx, invoiceInId, options) => {
|
||||||
let tx;
|
let tx;
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const myOptions = {userId: ctx.req.accessToken.userId};
|
const myOptions = {userId: ctx.req.accessToken.userId};
|
||||||
|
@ -36,27 +36,27 @@ module.exports = Self => {
|
||||||
let isLinked;
|
let isLinked;
|
||||||
let accountingEntries;
|
let accountingEntries;
|
||||||
|
|
||||||
let {'ASIEN': bookEntry} = await models.Xdiario.findOne({
|
let bookEntry = await models.Xdiario.findOne({
|
||||||
fields: ['ASIEN'],
|
fields: ['ASIEN'],
|
||||||
where: {
|
where: {
|
||||||
and: [
|
and: [
|
||||||
{'CLAVE': id},
|
{key: invoiceInId},
|
||||||
{enlazado: 0},
|
{enlazado: 0},
|
||||||
{enlazadoSage: 0}
|
{enlazadoSage: 0}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
if (bookEntry) {
|
if (bookEntry?.ASIEN) {
|
||||||
accountingEntries = await models.Xdiario.count({ASIEN: bookEntry}, myOptions);
|
accountingEntries = await models.Xdiario.count({ASIEN: bookEntry.ASIEN}, myOptions);
|
||||||
|
|
||||||
await models.Xdiario.destroyAll({ASIEN: bookEntry}, myOptions);
|
await models.Xdiario.destroyAll({ASIEN: bookEntry.ASIEN}, myOptions);
|
||||||
await Self.updateAll({id}, {isBooked: false}, myOptions);
|
await Self.updateAll({id: invoiceInId}, {isBooked: false}, myOptions);
|
||||||
} else {
|
} else {
|
||||||
const linkedBookEntry = await models.Xdiario.findOne({
|
const linkedBookEntry = await models.Xdiario.findOne({
|
||||||
fields: ['ASIEN'],
|
fields: ['ASIEN'],
|
||||||
where: {
|
where: {
|
||||||
CLAVE: id,
|
key: invoiceInId,
|
||||||
and: [{or: [{enlazado: true, enlazadoSage: true}]}]
|
and: [{or: [{enlazado: true, enlazadoSage: true}]}]
|
||||||
}
|
}
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
@ -68,7 +68,7 @@ module.exports = Self => {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
isLinked,
|
isLinked,
|
||||||
bookEntry,
|
bookEntry: bookEntry?.ASIEN,
|
||||||
accountingEntries
|
accountingEntries
|
||||||
};
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
Loading…
Reference in New Issue