#6942 toUnbook #2135
|
@ -76,7 +76,13 @@
|
||||||
},
|
},
|
||||||
"enlazadoSage": {
|
"enlazadoSage": {
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
}
|
},
|
||||||
|
"enlazado": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
"CLAVE": {
|
||||||
|
"type": "number"
|
||||||
|
}
|
||||||
jorgep marked this conversation as resolved
Outdated
|
|||||||
},
|
},
|
||||||
"relations": {
|
"relations": {
|
||||||
"company": {
|
"company": {
|
||||||
|
|
|
@ -0,0 +1,78 @@
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('toUnbook', {
|
||||||
|
description: 'To unbook the invoiceIn',
|
||||||
|
accessType: 'WRITE',
|
||||||
|
accepts: {
|
||||||
|
arg: 'id',
|
||||||
|
type: 'number',
|
||||||
|
required: true,
|
||||||
|
description: 'The invoiceIn id',
|
||||||
|
http: {source: 'path'}
|
||||||
|
},
|
||||||
|
returns: {
|
||||||
|
type: 'object',
|
||||||
|
root: true
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: '/:id/toUnbook',
|
||||||
|
verb: 'POST'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.toUnbook = async(ctx, id, options) => {
|
||||||
|
let tx;
|
||||||
|
const models = Self.app.models;
|
||||||
|
const myOptions = {userId: ctx.req.accessToken.userId};
|
||||||
|
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
if (!myOptions.transaction) {
|
||||||
|
tx = await Self.beginTransaction({});
|
||||||
|
myOptions.transaction = tx;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
let isLinked;
|
||||||
|
let accountingEntries;
|
||||||
|
|
||||||
|
let {'ASIEN': bookEntry} = await models.Xdiario.findOne({
|
||||||
|
fields: ['ASIEN'],
|
||||||
|
where: {
|
||||||
|
and: [
|
||||||
|
{'CLAVE': id},
|
||||||
|
{enlazado: 0},
|
||||||
|
{enlazadoSage: 0}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}, myOptions);
|
||||||
|
|
||||||
jorgep marked this conversation as resolved
jsegarra
commented
El numero de ocurrencias de bookEntry.ASIEN es medio-alto. El numero de ocurrencias de bookEntry.ASIEN es medio-alto.
Propongo crear una variable representativa de este valor y reemplazar donde toque.
Otro enfoque puede ser que en el if, reemplazar bookEntry.ASIEN porque ya es true
jorgep
commented
Me parece bien. Me parece bien.
|
|||||||
|
if (bookEntry) {
|
||||||
jgallego marked this conversation as resolved
Outdated
alexm
commented
@jgallego veus be la logica? @jgallego veus be la logica?
jgallego
commented
esta ok esta ok
|
|||||||
|
accountingEntries = await models.Xdiario.count({ASIEN: bookEntry}, myOptions);
|
||||||
|
|
||||||
|
await models.Xdiario.destroyAll({where: {ASIEN: bookEntry}}, myOptions);
|
||||||
|
} else {
|
||||||
|
const linkedBookEntry = await models.Xdiario.findOne({
|
||||||
|
fields: ['ASIEN'],
|
||||||
|
where: {
|
||||||
|
CLAVE: id,
|
||||||
|
and: [{or: [{enlazado: true, enlazadoSage: true}]}]
|
||||||
|
}
|
||||||
|
}, myOptions);
|
||||||
|
|
||||||
|
bookEntry = linkedBookEntry?.ASIEN;
|
||||||
|
isLinked = true;
|
||||||
|
}
|
||||||
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
|
return {
|
||||||
|
isLinked,
|
||||||
|
bookEntry,
|
||||||
|
accountingEntries
|
||||||
|
};
|
||||||
|
} catch (e) {
|
||||||
|
if (tx) await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
|
@ -10,6 +10,7 @@ module.exports = Self => {
|
||||||
require('../methods/invoice-in/invoiceInEmail')(Self);
|
require('../methods/invoice-in/invoiceInEmail')(Self);
|
||||||
require('../methods/invoice-in/getSerial')(Self);
|
require('../methods/invoice-in/getSerial')(Self);
|
||||||
require('../methods/invoice-in/corrective')(Self);
|
require('../methods/invoice-in/corrective')(Self);
|
||||||
|
require('../methods/invoice-in/toUnbook')(Self);
|
||||||
|
|
||||||
Self.rewriteDbError(function(err) {
|
Self.rewriteDbError(function(err) {
|
||||||
if (err.code === 'ER_ROW_IS_REFERENCED_2' && err.sqlMessage.includes('vehicleInvoiceIn'))
|
if (err.code === 'ER_ROW_IS_REFERENCED_2' && err.sqlMessage.includes('vehicleInvoiceIn'))
|
||||||
|
|
Loading…
Reference in New Issue
El campo CLAVE está en mayúsculas en la base de datos
Li pots fer un rename per a que nosaltres ho gastem normal.
En ticket.json hi ha un exemple: