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": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"CLAVE": {
|
||||
"type": "number"
|
||||
"key": {
|
||||
"type": "number",
|
||||
"mysql": {
|
||||
"columnName": "CLAVE"
|
||||
}
|
||||
}
|
||||
},
|
||||
"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;
|
||||
const models = Self.app.models;
|
||||
const myOptions = {userId: ctx.req.accessToken.userId};
|
||||
|
@ -36,27 +36,27 @@ module.exports = Self => {
|
|||
let isLinked;
|
||||
let accountingEntries;
|
||||
|
||||
let {'ASIEN': bookEntry} = await models.Xdiario.findOne({
|
||||
let bookEntry = await models.Xdiario.findOne({
|
||||
fields: ['ASIEN'],
|
||||
where: {
|
||||
and: [
|
||||
{'CLAVE': id},
|
||||
{key: invoiceInId},
|
||||
{enlazado: 0},
|
||||
{enlazadoSage: 0}
|
||||
]
|
||||
}
|
||||
}, myOptions);
|
||||
|
||||
if (bookEntry) {
|
||||
accountingEntries = await models.Xdiario.count({ASIEN: bookEntry}, myOptions);
|
||||
if (bookEntry?.ASIEN) {
|
||||
accountingEntries = await models.Xdiario.count({ASIEN: bookEntry.ASIEN}, myOptions);
|
||||
|
||||
await models.Xdiario.destroyAll({ASIEN: bookEntry}, myOptions);
|
||||
await Self.updateAll({id}, {isBooked: false}, myOptions);
|
||||
await models.Xdiario.destroyAll({ASIEN: bookEntry.ASIEN}, myOptions);
|
||||
await Self.updateAll({id: invoiceInId}, {isBooked: false}, myOptions);
|
||||
} else {
|
||||
const linkedBookEntry = await models.Xdiario.findOne({
|
||||
fields: ['ASIEN'],
|
||||
where: {
|
||||
CLAVE: id,
|
||||
key: invoiceInId,
|
||||
and: [{or: [{enlazado: true, enlazadoSage: true}]}]
|
||||
}
|
||||
}, myOptions);
|
||||
|
@ -68,7 +68,7 @@ module.exports = Self => {
|
|||
|
||||
return {
|
||||
isLinked,
|
||||
bookEntry,
|
||||
bookEntry: bookEntry?.ASIEN,
|
||||
accountingEntries
|
||||
};
|
||||
} catch (e) {
|
||||
|
|
Loading…
Reference in New Issue